コード例 #1
0
ファイル: tests.py プロジェクト: shuiziliu/django-garage
    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()
コード例 #2
0
ファイル: tests.py プロジェクト: shuiziliu/django-garage
    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)