Skip to content

Commit af26325

Browse files
author
Kurt Yoder
authored
Merge pull request #28 from SergioRAgostinho/uts-full-path
Specify the full path for the test files. Removed pyglet dep on unit tests
2 parents 1b45a91 + a19b075 commit af26325

File tree

5 files changed

+34
-51
lines changed

5 files changed

+34
-51
lines changed

test/test_material.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
import unittest
2-
3-
import pyglet
2+
import os
43

54
import pywavefront.material
65

6+
def prepend_dir(file):
7+
return os.path.join(os.path.dirname(__file__), file)
8+
79
class TestMaterial(unittest.TestCase):
810
def setUp(self):
9-
pyglet.resource.path.append('@' + __name__)
10-
pyglet.resource.reindex()
11-
self.material = pywavefront.material.Material('material')
12-
self.material.set_texture('4x4.png')
11+
# Append current path to locate files
12+
self.material = pywavefront.material.Material(prepend_dir('material'))
13+
self.material.set_texture(prepend_dir('4x4.png'))
1314

1415
def testSetTexture(self):
1516
"Running set_texture should set a texture."
@@ -55,9 +56,6 @@ def testSetEmissive(self):
5556
self.assertEqual(self.material.emissive, [0., 0., 0., 0.])
5657

5758
class TestInvalidMaterial(unittest.TestCase):
58-
def setUp(self):
59-
pyglet.resource.path.append('@' + __name__)
60-
pyglet.resource.reindex()
6159

6260
def testSetInvalidTexture(self):
6361
"Running set_texture with a nonexistent file should raise an exception."

test/test_mesh.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
import unittest
22

3-
import pyglet
4-
53
import pywavefront.mesh
64

75
class TestMesh(unittest.TestCase):
8-
def setUp(self):
9-
pyglet.resource.path.append('@' + __name__)
10-
pyglet.resource.reindex()
116

127
def testMeshName(self):
138
"Creating a mesh with a name should set the name."

test/test_parser.py

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import unittest
2-
3-
import pyglet
2+
import os
43

54
import pywavefront.parser
65

6+
def prepend_dir(file):
7+
return os.path.join(os.path.dirname(__file__), file)
8+
79
class TestParsers(unittest.TestCase):
810
def setUp(self):
9-
pyglet.resource.path.append('@' + __name__)
10-
pyglet.resource.reindex()
11-
meshes = pywavefront.Wavefront('simple.obj')
11+
# Append current path to locate files
12+
meshes = pywavefront.Wavefront(prepend_dir('simple.obj'))
1213
self.mesh1 = meshes.mesh_list[0]
1314
self.mesh2 = meshes.mesh_list[1]
1415

@@ -37,9 +38,8 @@ def testObjMaterials(self):
3738

3839
class TestMtlParser(unittest.TestCase):
3940
def setUp(self):
40-
pyglet.resource.path.append('@' + __name__)
41-
pyglet.resource.reindex()
42-
meshes = pywavefront.Wavefront('simple.obj')
41+
# Append current path to locate files
42+
meshes = pywavefront.Wavefront(prepend_dir('simple.obj'))
4343
self.material1 = meshes.mesh_list[0].materials[0]
4444
self.material2 = meshes.mesh_list[1].materials[0]
4545

@@ -70,17 +70,15 @@ def testMtlSpecular(self):
7070
def testMtlTextureName(self):
7171
"Parsing an obj file with known material texture should set its name."
7272
# also tests d
73-
self.assertEqual(self.material1.texture.image_name, '4x4.png')
73+
self.assertEqual(self.material1.texture.image_name,
74+
prepend_dir('4x4.png'))
7475

7576
class TestParserFailure(unittest.TestCase):
76-
def setUp(self):
77-
pyglet.resource.path.append('@' + __name__)
78-
pyglet.resource.reindex()
7977

8078
def testMissingParseFunction(self):
8179
"Attempting to parse with a missing parse function should raise an exception."
8280
# since no parse functions have been defined, this will always fail
83-
self.assertRaises(Exception, pywavefront.parser.Parser, 'uv_sphere.obj')
81+
self.assertRaises(Exception, pywavefront.parser.Parser, prepend_dir('uv_sphere.obj'))
8482

8583
def testMissingParsedFile(self):
8684
"Referencing a missing parsed file should raise an exception."

test/test_texture.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
11
import unittest
2-
3-
import pyglet
2+
import os
43

54
import pywavefront.texture
65

6+
def prepend_dir(file):
7+
return os.path.join(os.path.dirname(__file__), file)
8+
79
class TestTexture(unittest.TestCase):
8-
def setUp(self):
9-
pyglet.resource.path.append('@' + __name__)
10-
pyglet.resource.reindex()
1110

1211
def testPathedImageName(self):
1312
"For Texture objects, the image name should be the last component of the path."
14-
my_texture = pywavefront.texture.Texture('4x4.png')
15-
self.assertEqual(my_texture.image_name, '4x4.png')
13+
my_texture = pywavefront.texture.Texture(prepend_dir('4x4.png'))
14+
self.assertEqual(my_texture.image_name, prepend_dir('4x4.png'))
1615

1716
def testNonPowerOfTwoImage(self):
1817
"Texture images that have a non-power-of-two dimension should raise an exception."
19-
self.assertRaises(Exception, pywavefront.texture.Texture, '3x4.png')
18+
self.assertRaises(Exception, pywavefront.texture.Texture, prepend_dir('3x4.png'))
2019

2120
def testMissingFile(self):
2221
"Referencing a missing texture file should raise an exception."

test/test_wavefront.py

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
import unittest
2-
3-
import pyglet
2+
import os
43

54
import pywavefront
65

6+
def prepend_dir(file):
7+
return os.path.join(os.path.dirname(__file__), file)
8+
79
class TestWavefront(unittest.TestCase):
810
def setUp(self):
9-
pyglet.resource.path.append('@' + __name__)
10-
pyglet.resource.reindex()
1111
self.mesh_names = ['Simple', 'SimpleB']
1212
self.material_names = ['Material.simple', 'Material2.simple']
13-
self.meshes = pywavefront.Wavefront('simple.obj')
13+
self.meshes = pywavefront.Wavefront(prepend_dir('simple.obj'))
1414

1515
def testMaterials(self):
1616
"Ensure parsed wavefront materials match known values."
@@ -41,38 +41,31 @@ def testMeshMaterialVertices(self):
4141
self.assertEqual(len(self.meshes.meshes[self.mesh_names[0]].materials[0].vertices), 24)
4242

4343
class TestBrokenWavefront(unittest.TestCase):
44-
def setUp(self):
45-
pyglet.resource.path.append('@' + __name__)
46-
pyglet.resource.reindex()
4744

4845
def testUnknownUsemtl(self):
4946
"Referencing an unknown material with usemtl should raise an exception."
5047
self.assertRaises(pywavefront.PywavefrontException,
51-
pywavefront.Wavefront, 'simple_unknown_usemtl.obj')
48+
pywavefront.Wavefront, prepend_dir('simple_unknown_usemtl.obj'))
5249

5350
def testMissingNormals(self):
5451
"If there are texture coordinates but no normals, should raise an exception."
5552
self.assertRaises(pywavefront.PywavefrontException,
56-
pywavefront.Wavefront, 'simple_missing_normals.obj')
53+
pywavefront.Wavefront, prepend_dir('simple_missing_normals.obj'))
5754

5855
class TestNoMaterial(TestWavefront):
5956
def setUp(self):
60-
pyglet.resource.path.append('@' + __name__)
61-
pyglet.resource.reindex()
6257
# reset the obj file to new file with no mtl line
6358
self.mesh_names = ['Simple', 'SimpleB']
6459
self.material_names = [None]
65-
self.meshes = pywavefront.Wavefront('simple_no_mtl.obj')
60+
self.meshes = pywavefront.Wavefront(prepend_dir('simple_no_mtl.obj'))
6661

6762
def testMeshMaterialVertices(self):
6863
"Mesh vertices should have known values."
6964
self.assertEqual(len(self.meshes.meshes[self.mesh_names[0]].materials[0].vertices), 48)
7065

7166
class TestNoObjectNoMaterial(TestNoMaterial):
7267
def setUp(self):
73-
pyglet.resource.path.append('@' + __name__)
74-
pyglet.resource.reindex()
7568
# reset the obj file to new file with no mtl line
7669
self.mesh_names = [None]
7770
self.material_names = [None]
78-
self.meshes = pywavefront.Wavefront('simple_no_object_no_mtl.obj')
71+
self.meshes = pywavefront.Wavefront(prepend_dir('simple_no_object_no_mtl.obj'))

0 commit comments

Comments
 (0)