def test_delete(self): File.copy('testResources\\FileTest.txt', "testResources\\FileTestTemp.txt") self.assertTrue(File.exists("testResources\\FileTestTemp.txt")) File.delete("testResources\\FileTestTemp.txt") self.assertFalse(File.exists("testResources\\FileTestTemp.txt")) pass
def test_writetext(self): File.write_text('testResources\\FileTest.txt', "Nothing") self.assertEqual(File.read_text('testResources\\FileTest.txt'), "Nothing") File.write_text('testResources\\FileTest.txt', 'Contents Of File\nSecond Line Of Content') self.assertEqual(File.read_text('testResources\\FileTest.txt'), 'Contents Of File\nSecond Line Of Content') pass
def test_readtext(self): self.assertEqual(File.read_text('testResources\\FileTest.txt'), 'Contents Of File\nSecond Line Of Content')
def test_exists(self): self.assertTrue(File.exists(r'testResources\FileTest.txt')) self.assertFalse(File.exists(r'testResources\FILEDOESNOTEXIST.txt'))
def test_readlines(self): self.assertEqual(File.read_lines('testResources\\FileTest.txt'), ['Contents Of File\n', 'Second Line Of Content'])
def replace_file(path, pattern, replacement): text = File.read_text(path) text = Regex.replace_string(text, pattern, replacement) File.write_text(path, text)
def match_file(path, pattern): text = File.read_text(path) return Regex.match_string(text, pattern)
def get_resource_path(resource): # TODO: write unit test if File.exists(Path.combine(Path.get_file_path(__file__), resource)): return Path.combine(Path.get_file_path(__file__), resource) else: raise Exception('The given resource could not be found')