|
3 | 3 |
|
4 | 4 | import pywavefront.parser |
5 | 5 |
|
| 6 | + |
6 | 7 | def prepend_dir(file): |
7 | 8 | return os.path.join(os.path.dirname(__file__), file) |
8 | 9 |
|
| 10 | + |
9 | 11 | class TestParsers(unittest.TestCase): |
10 | 12 | def setUp(self): |
11 | 13 | # Append current path to locate files |
@@ -36,6 +38,7 @@ def testObjMaterials(self): |
36 | 38 | self.assertEqual(material1.name, 'Material.simple') |
37 | 39 | self.assertEqual(material2.name, 'Material2.simple') |
38 | 40 |
|
| 41 | + |
39 | 42 | class TestMtlParser(unittest.TestCase): |
40 | 43 | def setUp(self): |
41 | 44 | # Append current path to locate files |
@@ -73,13 +76,20 @@ def testMtlTextureName(self): |
73 | 76 | self.assertEqual(self.material1.texture.image_name, |
74 | 77 | prepend_dir('4x4.png')) |
75 | 78 |
|
| 79 | + |
76 | 80 | class TestParserFailure(unittest.TestCase): |
77 | 81 |
|
78 | 82 | def testMissingParseFunction(self): |
79 | 83 | "Attempting to parse with a missing parse function should raise an exception." |
80 | | - # since no parse functions have been defined, this will always fail |
81 | | - self.assertRaises(Exception, pywavefront.parser.Parser, prepend_dir('uv_sphere.obj')) |
| 84 | + # since no parse functions have been defined, this will always fail in strict mode |
| 85 | + file_name = 'simple.obj' |
| 86 | + parser = pywavefront.parser.Parser(prepend_dir(file_name)) |
| 87 | + pywavefront.parser.Parser.strict = True |
| 88 | + self.assertRaises(AttributeError, parser.read_file, prepend_dir(file_name)) |
| 89 | + pywavefront.parser.Parser.strict = False |
82 | 90 |
|
83 | 91 | def testMissingParsedFile(self): |
84 | 92 | "Referencing a missing parsed file should raise an exception." |
85 | | - self.assertRaises(Exception, pywavefront.parser.Parser, 'missing.file.do.not.create') |
| 93 | + file_name = 'donotexsit.obj' |
| 94 | + parser = pywavefront.parser.Parser(prepend_dir(file_name)) |
| 95 | + self.assertRaises(FileNotFoundError, parser.read_file, prepend_dir(file_name)) |
0 commit comments