Skip to content

Commit 8048b6d

Browse files
committed
Remaining issues in Texture + tests
1 parent 0858d4e commit 8048b6d

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

pywavefront/texture.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,17 +67,19 @@ def find(self, path=None):
6767
6868
Args:
6969
path: Override the search path
70+
Raises:
71+
FileNotFoundError if not found
7072
"""
7173
if self.exists():
7274
return self.path
7375

7476
search_path = path or self._search_path
75-
locations = search_path.glob('**/{}'.format(self.file_name))
77+
locations = Path(search_path).glob('**/{}'.format(self.file_name))
7678
# Attempt to look up the first entry of the generator
7779
try:
7880
first = next(locations)
7981
except StopIteration:
80-
raise ValueError("Cannot locate texture `{}` in search path: {}".format(
82+
raise FileNotFoundError("Cannot locate texture `{}` in search path: {}".format(
8183
self._name, search_path))
8284

8385
return str(first)
@@ -101,7 +103,7 @@ def path(self):
101103

102104
@path.setter
103105
def path(self, value):
104-
self._path = value
106+
self._path = Path(value)
105107

106108
@property
107109
def image_name(self):
@@ -116,5 +118,5 @@ def image_name(self, value):
116118
self._name = value
117119

118120
def exists(self):
119-
"""bool: Does the texture exist?"""
121+
"""bool: Does the texture exist"""
120122
return self._path.exists()

tests/test_texture.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,20 @@ class TestTexture(unittest.TestCase):
1111

1212
def testPathedImageName(self):
1313
"""For Texture objects, the image name should be the last component of the path."""
14-
my_texture = pywavefront.texture.Texture('4x4.png', search_path=utils.FIXTURE_PATH)
15-
self.assertEqual(my_texture.path, str(utils.fixture('4x4.png')))
16-
self.assertEqual(my_texture.name, '4x4.png')
14+
texture = pywavefront.texture.Texture('4x4.png', search_path=utils.FIXTURE_PATH)
15+
self.assertEqual(texture.path, str(utils.fixture('4x4.png')))
16+
self.assertEqual(texture.name, '4x4.png')
17+
self.assertTrue(texture)
18+
self.assertEqual(texture.image_name, '4x4.png')
19+
self.assertEqual(texture.file_name, '4x4.png')
20+
self.assertTrue(os.path.exists(texture.find()))
1721

1822
def testMissingFile(self):
1923
"""Referencing a missing texture file should raise an exception."""
2024
texture = pywavefront.texture.Texture('missing.file.do.not.create', search_path='')
2125
self.assertFalse(texture.exists())
26+
with self.assertRaises(FileNotFoundError):
27+
texture.find()
2228

2329
def testPathVsName(self):
2430
texture = pywavefront.texture.Texture('somefile', search_path=Path('path/to'))

0 commit comments

Comments
 (0)