Skip to content

Commit b7b79e4

Browse files
committed
Core review #1
1 parent f3e1c40 commit b7b79e4

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

pywavefront/texture.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,24 @@
3131
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
3232
# POSSIBILITY OF SUCH DAMAGE.
3333
# ----------------------------------------------------------------------------
34+
import os
3435

3536

3637
class Texture(object):
3738
def __init__(self, path):
3839
# Treat path as part of a file uri always using forward slashes
39-
self.path = path.replace('\\', '/')
40+
self.path = path.replace('\\', os.path.sep)
4041
self.image = None
4142

4243
@property
4344
def image_name(self):
4445
"""Wrap the old property name to not break compatibility"""
4546
return self.path
47+
48+
@image_name.setter
49+
def image_name(self, value):
50+
"""Wrap the old property name to not break compatibility"""
51+
self.path = value
52+
53+
def exists(self):
54+
return os.path.exists(self.path)

test/test_material.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,12 @@ def testSetEmissive(self):
5656
"""set_emissive should set known values."""
5757
self.material.set_emissive()
5858
self.assertEqual(self.material.emissive, [0., 0., 0., 0.])
59+
60+
61+
class TestInvalidMaterial(unittest.TestCase):
62+
63+
def test_missing_texture(self):
64+
"""Running set_texture with a nonexistent file should raise an exception."""
65+
material = pywavefront.material.Material('material')
66+
material.set_texture('missing.file.do.not.create')
67+
self.assertFalse(material.texture.exists())

test/test_texture.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,8 @@ def testPathedImageName(self):
1414
"""For Texture objects, the image name should be the last component of the path."""
1515
my_texture = pywavefront.texture.Texture(prepend_dir('4x4.png'))
1616
self.assertEqual(my_texture.path, prepend_dir('4x4.png'))
17+
18+
def testMissingFile(self):
19+
"""Referencing a missing texture file should raise an exception."""
20+
texture = pywavefront.texture.Texture('missing.file.do.not.create')
21+
self.assertFalse(texture.exists())

0 commit comments

Comments
 (0)