File tree Expand file tree Collapse file tree 5 files changed +22
-11
lines changed
Expand file tree Collapse file tree 5 files changed +22
-11
lines changed Original file line number Diff line number Diff line change 3333# ----------------------------------------------------------------------------
3434import os
3535
36- from pywavefront .exceptions import PywavefrontException
37-
3836
3937class Texture (object ):
4038 def __init__ (self , path ):
41- self .image_name = path
39+ # Treat path as part of a file uri always using forward slashes
40+ self .path = path .replace ('\\ ' , os .path .sep )
4241 self .image = None
4342
44- if not os .path .exists (path ):
45- raise PywavefrontException ("Requested file does not exist" )
43+ @property
44+ def image_name (self ):
45+ """Wrap the old property name to not break compatibility"""
46+ 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 )
Original file line number Diff line number Diff line change @@ -119,7 +119,7 @@ def gl_light(lighting):
119119def bind_texture (texture ):
120120 """Draw a single texture"""
121121 if not getattr (texture , 'image' , None ):
122- texture .image = load_image (texture .image_name )
122+ texture .image = load_image (texture .path )
123123
124124 glEnable (texture .image .target )
125125 glBindTexture (texture .image .target , texture .image .id )
Original file line number Diff line number Diff line change @@ -60,7 +60,8 @@ def testSetEmissive(self):
6060
6161class TestInvalidMaterial (unittest .TestCase ):
6262
63- def testSetInvalidTexture (self ):
63+ def test_missing_texture (self ):
6464 """Running set_texture with a nonexistent file should raise an exception."""
6565 material = pywavefront .material .Material ('material' )
66- self .assertRaises (Exception , material .set_texture , 'missing.file.do.not.create' )
66+ material .set_texture ('missing.file.do.not.create' )
67+ self .assertFalse (material .texture .exists ())
Original file line number Diff line number Diff line change @@ -175,7 +175,7 @@ def testMtlSpecular(self):
175175 def testMtlTextureName (self ):
176176 """Parsing an obj file with known material texture should set its name."""
177177 # also tests d
178- self .assertEqual (self .material1 .texture .image_name ,
178+ self .assertEqual (self .material1 .texture .path ,
179179 prepend_dir ('4x4.png' ))
180180
181181
Original file line number Diff line number Diff line change @@ -13,8 +13,9 @@ class TestTexture(unittest.TestCase):
1313 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' ))
16- self .assertEqual (my_texture .image_name , prepend_dir ('4x4.png' ))
16+ self .assertEqual (my_texture .path , prepend_dir ('4x4.png' ))
1717
1818 def testMissingFile (self ):
1919 """Referencing a missing texture file should raise an exception."""
20- self .assertRaises (Exception , pywavefront .texture .Texture , 'missing.file.do.not.create' )
20+ texture = pywavefront .texture .Texture ('missing.file.do.not.create' )
21+ self .assertFalse (texture .exists ())
You can’t perform that action at this time.
0 commit comments