Example #1
0
    def check_open_file_gc_behaviour(self, file, **kwargs):
        def mangle(file):
            with open_file(file, **kwargs) as result:
                self.assertIsInstance(result, io.TextIOBase)

        with open_file(file, encoding='binary') as f:
            mangle(f)
            self.assertFalse(f.closed)
Example #2
0
    def check_open_file_gc_behaviour(self, file, **kwargs):
        def mangle(file):
            with open_file(file, **kwargs) as result:
                self.assertIsInstance(result, io.TextIOBase)

        with open_file(file, encoding='binary') as f:
            mangle(f)
            self.assertFalse(f.closed)
Example #3
0
    def check_open_file_state_contents(self, file, contents, is_binary,
                                       **kwargs):
        with open_file(file, **kwargs) as f:
            if is_binary:
                self.assertIsInstance(f, (io.BufferedReader,
                                          io.BufferedRandom))
            else:
                self.assertIsInstance(f, io.TextIOBase)
            self.assertTrue(f.readable())
            self.assertEqual(f.read(), contents)
        self.assertEqual(f.closed, self.expected_close)

        f.close()
        self.assertTrue(f.closed)
        self.check_closed(file, True)
Example #4
0
    def check_open_file_state_contents(self, file, contents, is_binary,
                                       **kwargs):
        with open_file(file, **kwargs) as f:
            if is_binary:
                self.assertIsInstance(f, (io.BufferedReader,
                                          io.BufferedRandom))
            else:
                self.assertIsInstance(f, io.TextIOBase)
            self.assertTrue(f.readable())
            self.assertEqual(f.read(), contents)
        self.assertEqual(f.closed, self.expected_close)

        f.close()
        self.assertTrue(f.closed)
        self.check_closed(file, True)
Example #5
0
 def check_open_file_buffer_close_behaviour(self, file, **kwargs):
     if hasattr(file, 'close'):
         with open_file(file, **kwargs) as wrapped:
             file.close()
             self.assertTrue(wrapped.closed)
Example #6
0
 def mangle(file):
     with open_file(file, **kwargs) as result:
         self.assertIsInstance(result, io.TextIOBase)
Example #7
0
 def check_open_file_buffer_close_behaviour(self, file, **kwargs):
     if hasattr(file, 'close'):
         with open_file(file, **kwargs) as wrapped:
             file.close()
             self.assertTrue(wrapped.closed)
Example #8
0
 def mangle(file):
     with open_file(file, **kwargs) as result:
         self.assertIsInstance(result, io.TextIOBase)