Beispiel #1
0
    def test_open_file_error(self):
        """
        open_file should raise IOError if file cannot be opened.
        """
        self._msg("test", "open_file error", first=True)
        from garage.utils import open_file

        mode = "rt"
        module_dir = os.path.dirname(os.path.realpath(__file__))
        path = os.path.join(module_dir, "non-existent-file")
        with self.assertRaises(IOError):
            with open_file(path, mode=mode) as file_obj:
                data = file_obj.read()
Beispiel #2
0
    def test_open_file(self):
        """
        open_file should return a stream object if successful.
        """
        self._msg("test", "open_file", first=True)
        from garage.utils import open_file

        module_dir = os.path.dirname(os.path.realpath(__file__))
        path = os.path.join(module_dir, "testfile.txt")
        mode = "rt"
        with open_file(path, mode=mode) as file_obj:
            data = file_obj.read()
        expected = TestData
        self.assertEqual(data, expected)