1616import shutil
1717from scipy .constants import pi
1818
19- sys .path .append ('..' )
19+ dir_path = os .path .dirname (os .path .realpath (__file__ ))
20+ sys .path .append (os .path .join (dir_path , '..' ))
2021from wcon import WCONWorms , MeasurementUnit
2122from wcon .measurement_unit import MeasurementUnitAtom
2223
23-
2424def setUpModule ():
2525 # If the wcon module is installed via pip, wcon_schema.json is included
2626 # in the proper place. In the git repo it is not, however, so to test
27- # we must copy it over temporarily, then remove it once tests are done.
28- shutil .copyfile ('../../../ wcon_schema.json' , '../ wcon/ wcon_schema.json' )
27+ # we must copy it over temporarily, then remove it once tests are done.
28+ shutil .copyfile (os . path . join ( dir_path , '..' , '..' , '..' , ' wcon_schema.json'), os . path . join ( dir_path , '..' , ' wcon' , ' wcon_schema.json') )
2929
3030
3131def tearDownModule ():
32- os .remove ('../ wcon/ wcon_schema.json' )
32+ os .remove (os . path . join ( dir_path , '..' , ' wcon' , ' wcon_schema.json') )
3333
3434
3535def flatten (list_of_lists ):
@@ -192,7 +192,9 @@ def _validate_from_schema(self, wcon_string):
192192 except AttributeError :
193193 # Only load _wcon_schema if this method gets called. Once
194194 # it's loaded, though, persist it in memory and don't lose it
195- with open ("../../../wcon_schema.json" , "r" ) as wcon_schema_file :
195+ wcon_schema_path = os .path .abspath (os .path .join (os .path .dirname (__file__ ),
196+ '..' , '..' , '..' , 'wcon_schema.json' ))
197+ with open (wcon_schema_path , "r" ) as wcon_schema_file :
196198 self ._wcon_schema = json .loads (wcon_schema_file .read ())
197199
198200 # Now that the schema has been loaded, we can try again
@@ -204,7 +206,8 @@ def test_schema(self):
204206 self ._validate_from_schema (basic_wcon )
205207
206208 def test_equality_operator (self ):
207- JSON_path = '../../../tests/minimax.wcon'
209+ JSON_path = os .path .abspath (os .path .join (os .path .dirname (__file__ ),
210+ '..' , '..' , '..' , 'tests' , 'minimax.wcon' ))
208211 w2 = WCONWorms .load_from_file (JSON_path )
209212 w2 .units ['y' ] = MeasurementUnit .create ('m' )
210213 w2data = w2 .data .copy ()
0 commit comments