def test_fileproxy_from_file(self): with prepare_file(['coala\n'], None) as (_, file): fileproxy = FileProxy.from_file(file, None) self.assertEqual(fileproxy.version, -1) self.assertEqual(fileproxy.workspace, None) self.assertEqual(fileproxy.contents(), 'coala\n') self.assertEqual(fileproxy.filename, os.path.normcase(file))
def test_fileproxy_binary_file(self): with make_temp() as filename: data = bytearray([120, 3, 255, 0, 100]) with open(filename, 'wb') as file: file.write(data) proxy = FileProxy.from_file(filename, None, binary=True) self.assertEqual(proxy.filename, os.path.normcase(filename)) self.assertEqual(proxy.contents(), data) self.assertEqual(proxy.lines(), (data,))
def test_fileproxy_binary_file(self): with make_temp() as filename: data = bytearray([120, 3, 255, 0, 100]) with open(filename, 'wb') as file: file.write(data) proxy = FileProxy.from_file(filename, None, binary=True) self.assertEqual(proxy.filename, os.path.normcase(filename)) self.assertEqual(proxy.contents(), data) self.assertEqual(proxy.lines(), (data, ))
def test_fileproxy_replace(self): with prepare_file(['coala\n'], None) as (_, file): fileproxy = FileProxy.from_file(file, '.') self.assertEqual(fileproxy.version, -1) self.assertEqual(fileproxy.contents(), 'coala\n') self.assertTrue(fileproxy.replace('coala-rocks', 1)) self.assertEqual(fileproxy.contents(), 'coala-rocks') self.assertFalse(fileproxy.replace('bears-rocks', 1)) self.assertEqual(fileproxy.contents(), 'coala-rocks') self.assertFalse(fileproxy.replace('coala-mountains', 0)) self.assertEqual(fileproxy.contents(), 'coala-rocks')
def test_fileproxy_hash(self): with prepare_file(['coala\n', 'bears\n'], None) as (_, file): proxy = FileProxy.from_file(file, None) self.assertEqual(hash(proxy), hash(os.path.normcase(file)))
def test_fileproxy_lines(self): with prepare_file(['coala\n', 'bears\n'], None) as (lines, file): proxy = FileProxy.from_file(file, None) self.assertEqual(proxy.lines(), tuple(lines))
def test_fileproxy_clear(self): with prepare_file(['coala'], None) as (_, file): fileproxy = FileProxy.from_file(file, None) fileproxy.clear() self.assertEqual(fileproxy.contents(), '')
def test_file_from_file_missing_file(self): with prepare_file([], None) as (_, file): with self.assertRaises(OSError): FileProxy.from_file(file+'coala', '.')
def random_proxy(self, contents=['coala\n']): with prepare_file(contents, None) as (_, file): return FileProxy.from_file(file, None)
def test_file_from_file_missing_file(self): with prepare_file([], None) as (_, file): with self.assertRaises(OSError): FileProxy.from_file(file + 'coala', '.')