@@ -61,17 +61,14 @@ def setUpClass(cls):
6161 Calls Maven to compile & run Java classes that will generate serialized
6262 data
6363 """
64- # Compute the java directory (from top folder or test folder)
65- java_dir = [os .getcwd ()]
66- if not os .getcwd ().endswith ('tests' ):
67- # Not in the test folder
68- java_dir .append ('tests' )
64+ # Compute the java directory
65+ java_dir = os .path .join (os .path .dirname (__file__ ), 'java' )
6966
70- java_dir . append ( 'java' )
71-
72- os .chdir (os . path . join ( * java_dir ) )
67+ # Run Maven and go back to the working folder
68+ cwd = os . getcwd ()
69+ os .chdir (java_dir )
7370 subprocess .call (['mvn' , 'test' ], shell = True )
74- os .chdir ('..' )
71+ os .chdir (cwd )
7572
7673 def read_file (self , filename ):
7774 """
@@ -80,14 +77,22 @@ def read_file(self, filename):
8077 :param filename: Name of the file to read
8178 :return: File content
8279 """
83- with open (filename , 'rb' ) as filep :
80+ for subfolder in ('java' , '' ):
81+ found_file = os .path .join (
82+ os .path .dirname (__file__ ), subfolder , filename )
83+ if os .path .exists (found_file ):
84+ break
85+ else :
86+ raise IOError ("File not found: {0}" .format (filename ))
87+
88+ with open (found_file , 'rb' ) as filep :
8489 return filep .read ()
8590
8691 def test_char_rw (self ):
8792 """
8893 Reads testChar.ser and checks the serialization process
8994 """
90- jobj = self .read_file ("java/ testChar.ser" )
95+ jobj = self .read_file ("testChar.ser" )
9196 pobj = javaobj .loads (jobj )
9297 _logger .debug ("Read char object: %s" , pobj )
9398 self .assertEqual (pobj , '\x00 C' )
@@ -98,7 +103,7 @@ def test_double_rw(self):
98103 """
99104 Reads testDouble.ser and checks the serialization process
100105 """
101- jobj = self .read_file ("java/ testDouble.ser" )
106+ jobj = self .read_file ("testDouble.ser" )
102107 pobj = javaobj .loads (jobj )
103108 _logger .debug ("Read double object: %s" , pobj )
104109
@@ -111,7 +116,7 @@ def test_bytes_rw(self):
111116 """
112117 Reads testBytes.ser and checks the serialization process
113118 """
114- jobj = self .read_file ("java/ testBytes.ser" )
119+ jobj = self .read_file ("testBytes.ser" )
115120 pobj = javaobj .loads (jobj )
116121 _logger .debug ("Read bytes: %s" , pobj )
117122
@@ -124,7 +129,7 @@ def test_boolean(self):
124129 """
125130 Reads testBoolean.ser and checks the serialization process
126131 """
127- jobj = self .read_file ("java/ testBoolean.ser" )
132+ jobj = self .read_file ("testBoolean.ser" )
128133 pobj = javaobj .loads (jobj )
129134 _logger .debug ("Read boolean object: %s" , pobj )
130135
@@ -139,7 +144,7 @@ def test_byte(self):
139144
140145 The result from javaobj is a single-character string.
141146 """
142- jobj = self .read_file ("java/ testByte.ser" )
147+ jobj = self .read_file ("testByte.ser" )
143148 pobj = javaobj .loads (jobj )
144149 _logger .debug ("Read Byte: %r" , pobj )
145150
@@ -152,7 +157,7 @@ def test_fields(self):
152157 """
153158 Reads a serialized object and checks its fields
154159 """
155- jobj = self .read_file ("java/ test_readFields.ser" )
160+ jobj = self .read_file ("test_readFields.ser" )
156161 pobj = javaobj .loads (jobj )
157162 _logger .debug ("Read object: %s" , pobj )
158163
@@ -178,7 +183,7 @@ def test_class(self):
178183 """
179184 Reads the serialized String class
180185 """
181- jobj = self .read_file ("java/ testClass.ser" )
186+ jobj = self .read_file ("testClass.ser" )
182187 pobj = javaobj .loads (jobj )
183188 _logger .debug ("Read object: %s" , pobj )
184189 self .assertEqual (pobj .name , 'java.lang.String' )
@@ -190,7 +195,7 @@ def test_class(self):
190195 # """
191196 # Reads a serialized Swing component
192197 # """
193- # jobj = self.read_file("java/ testSwingObject.ser")
198+ # jobj = self.read_file("testSwingObject.ser")
194199 # pobj = javaobj.loads(jobj)
195200 # _logger.debug("Read object: %s", pobj)
196201 #
0 commit comments