def testWriteGoodFile(self): file = get_relative_path("testdata/new_file.txt") mode = "xt" try: self.assertIsNotNone(utils.openOrDie(file, mode)) finally: os.remove(file)
def testPermissionErrorWrite(self): file = get_relative_path("testdata/existing_file.txt") mode = "wt" with mock.patch("builtins.open", mock.mock_open()) as mock_file: mock_file.side_effect = PermissionError() with self.assertRaises(SystemExit): utils.openOrDie(file, mode)
def testIsADirectoryError(self): file = get_relative_path("testdata") mode = "rt" with self.assertRaises(SystemExit): utils.openOrDie(file, mode)
def testFileNotFoundError(self): file = get_relative_path("testdata/nonexistentfile.txt") mode = "rt" with self.assertRaises(SystemExit): utils.openOrDie(file, mode)
def testFileExistsError(self): file = get_relative_path("testdata/existing_file.txt") mode = "xt" with self.assertRaises(SystemExit): utils.openOrDie(file, mode)
def testReadGoodFile(self): file = get_relative_path("testdata/existing_file.txt") mode = "rt" self.assertIsNotNone(utils.openOrDie(file, mode))
def filePath(file_name): return os.path.abspath(testutils.get_relative_path(file_name))