Example #1
0
    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))
Example #2
0
    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))
Example #3
0
    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,))
Example #4
0
    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, ))
Example #5
0
    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')
Example #6
0
    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')
Example #7
0
 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)))
Example #8
0
 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))
Example #9
0
    def test_fileproxy_clear(self):
        with prepare_file(['coala'], None) as (_, file):
            fileproxy = FileProxy.from_file(file, None)

            fileproxy.clear()
            self.assertEqual(fileproxy.contents(), '')
Example #10
0
 def test_file_from_file_missing_file(self):
     with prepare_file([], None) as (_, file):
         with self.assertRaises(OSError):
             FileProxy.from_file(file+'coala', '.')
Example #11
0
 def random_proxy(self, contents=['coala\n']):
     with prepare_file(contents, None) as (_, file):
         return FileProxy.from_file(file, None)
Example #12
0
 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)))
Example #13
0
 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))
Example #14
0
    def test_fileproxy_clear(self):
        with prepare_file(['coala'], None) as (_, file):
            fileproxy = FileProxy.from_file(file, None)

            fileproxy.clear()
            self.assertEqual(fileproxy.contents(), '')
Example #15
0
 def test_file_from_file_missing_file(self):
     with prepare_file([], None) as (_, file):
         with self.assertRaises(OSError):
             FileProxy.from_file(file + 'coala', '.')
Example #16
0
 def random_proxy(self, contents=['coala\n']):
     with prepare_file(contents, None) as (_, file):
         return FileProxy.from_file(file, None)