Exemplo n.º 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())
Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 4
0
 def test_unsuported(self):
     with self.assertRaises(Exception):
         with utils.read(None) as fh:
             pass
Exemplo n.º 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)
Exemplo n.º 6
0
 def test_unsuported(self):
     with self.assertRaises(ValueError):
         with utils.read(None) as fh:
             pass