Esempio n. 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)
Esempio n. 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)
Esempio n. 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)
Esempio n. 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)
Esempio n. 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)
Esempio n. 6
0
 def mangle(file):
     with open_file(file, **kwargs) as result:
         self.assertIsInstance(result, io.TextIOBase)
Esempio n. 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)
Esempio n. 8
0
 def mangle(file):
     with open_file(file, **kwargs) as result:
         self.assertIsInstance(result, io.TextIOBase)