Пример #1
0
    def test_fileobj(self):
        data = "foo bar boo"
        obj = StringIO(data)

        with utils.read(obj) as fh:
            self.assertEqual(obj, fh)
            self.assertEqual(data, fh.read())
Пример #2
0
    def test_path(self):
        name = "/path/to/file"
        path = MockPath(name)

        with utils.read(path) as fh:
            pass

        # close() is on the fh returned by open()
        calls = [mock.call(), mock.call().close()]
        self.assertEqual(path.open.mock_calls, calls)
Пример #3
0
    def test_path_close(self):
        name = "/path/to/file"
        path = MockPath(name)

        with self.assertRaises(Exception):
            with utils.read(path) as fh:
                raise Exception()

        # close() is on the fh returned by open()
        calls = [mock.call(), mock.call().close()]
        self.assertEqual(path.open.mock_calls, calls)
Пример #4
0
 def test_unsuported(self):
     with self.assertRaises(Exception):
         with utils.read(None) as fh:
             pass
Пример #5
0
    def test_string(self):
        data = "foo bar boo"

        with utils.read(data) as fh:
            self.assertEqual(data, fh.read())
            self.assertEqual('<string>', fh.name)
Пример #6
0
 def test_unsuported(self):
     with self.assertRaises(ValueError):
         with utils.read(None) as fh:
             pass