Beispiel #1
0
 def test_open_function(self):
     with ContextFile(filename=self.filename,
                      open_func=self.open_func) as file:
         try:
             first_line = next(file).split()
         except StopIteration:
             pass
     self.assertTrue(first_line[0] == "scans:" and first_line[1] == "11")
Beispiel #2
0
 def test_exit_function(self):
     with ContextFile(filename=self.filename,
                      open_func=self.open_func) as file:
         pass
     with self.assertRaises(ValueError):
         # file already closed
         try:
             next(file)
         except StopIteration:
             pass
Beispiel #3
0
 def test_instantiate_class(self):
     ctx = ContextFile(filename=self.filename, open_func=self.open_func)
     self.assertTrue(ctx.filename == self.filename)
     self.assertTrue(ctx.mode == "r")
     self.assertTrue(ctx.encoding == "utf-8")
     self.assertIsNone(ctx.file)
     self.assertIsNone(ctx.longname)
     self.assertIsNone(ctx.scan_number)
     self.assertIsNone(ctx.shortname)
     self.assertIsNone(ctx.directory)
Beispiel #4
0
 def test_repr_str_none(self):
     ctx = ContextFile(filename=self.filename,
                       open_func=self.open_func,
                       shortname=None)
     print(repr(ctx))
     self.assertIsInstance(eval(repr(ctx)), ContextFile)
Beispiel #5
0
 def test_scan_number_wrong_type_float(self):
     with self.assertRaises(TypeError):
         ContextFile(filename=self.filename,
                     open_func=open,
                     scan_number=1.0)
Beispiel #6
0
 def test_open_function_not_supported(self):
     ctx = ContextFile(filename=self.filename, open_func=int)
     with self.assertRaises(NotImplementedError):
         ctx.__enter__()
Beispiel #7
0
 def test_open_function_wrong_type(self):
     with self.assertRaises(TypeError):
         ContextFile(filename=self.filename, open_func="weird function")