@@ -70,12 +70,13 @@ def setUpClass(cls):
7070 subprocess .call (['mvn' , 'test' ], shell = True )
7171 os .chdir (cwd )
7272
73- def read_file (self , filename ):
73+ def read_file (self , filename , stream = False ):
7474 """
7575 Reads the content of the given file in binary mode
7676
7777 :param filename: Name of the file to read
78- :return: File content
78+ :param stream: If True, return the file stream
79+ :return: File content or stream
7980 """
8081 for subfolder in ('java' , '' ):
8182 found_file = os .path .join (
@@ -85,8 +86,11 @@ def read_file(self, filename):
8586 else :
8687 raise IOError ("File not found: {0}" .format (filename ))
8788
88- with open (found_file , 'rb' ) as filep :
89- return filep .read ()
89+ if stream :
90+ return open (found_file , "rb" )
91+ else :
92+ with open (found_file , 'rb' ) as filep :
93+ return filep .read ()
9094
9195 def test_char_rw (self ):
9296 """
@@ -271,18 +275,18 @@ def test_enums(self):
271275 # # TODO: add some tests
272276 # self.assertEqual(classdesc.name, "MyExceptionWhenDumping")
273277
274- # def test_sun_example(self):
275- # marshaller = javaobj.JavaObjectUnmarshaller(
276- # open ("sunExample.ser", "rb" ))
277- # pobj = marshaller.readObject()
278- #
279- # self.assertEqual(pobj.value, 17)
280- # self.assertTrue(pobj.next)
281- #
282- # pobj = marshaller.readObject()
283- #
284- # self.assertEqual(pobj.value, 19)
285- # self.assertFalse(pobj.next)
278+ def test_sun_example (self ):
279+ marshaller = javaobj .JavaObjectUnmarshaller (
280+ self . read_file ("sunExample.ser" , stream = True ))
281+ pobj = marshaller .readObject ()
282+
283+ self .assertEqual (pobj .value , 17 )
284+ self .assertTrue (pobj .next )
285+
286+ pobj = marshaller .readObject ()
287+
288+ self .assertEqual (pobj .value , 19 )
289+ self .assertFalse (pobj .next )
286290
287291 def test_collections (self ):
288292 jobj = self .read_file ("objCollections.ser" )
0 commit comments