Ejemplo n.º 1
0
 def test_fileproxy_init(self):
     with prepare_file([], None) as (_, file):
         url = os.path.normcase(os.getcwd())
         fileproxy = FileProxy(file, url, 'coala')
         self.assertEqual(fileproxy.version, -1)
         self.assertEqual(fileproxy.contents(), 'coala')
         self.assertEqual(fileproxy.workspace, url)
Ejemplo n.º 2
0
 def test_fileproxy_init(self):
     with prepare_file([], None) as (_, file):
         url = os.path.normcase(os.getcwd())
         fileproxy = FileProxy(file, url, 'coala')
         self.assertEqual(fileproxy.version, -1)
         self.assertEqual(fileproxy.contents(), 'coala')
         self.assertEqual(fileproxy.workspace, url)
Ejemplo n.º 3
0
    def test_file_cache_proxy_integration(self, debug=False):
        with bear_test_module(), \
                prepare_file(['disk-copy\n'], None) as (_, filename):

            memory_data = 'in-memory\n'
            proxy = FileProxy(filename, None, memory_data)
            proxymap = FileProxyMap([proxy])
            self.cache.set_proxymap(proxymap)

            results, exitcode, file_dicts = run_coala(
                console_printer=ConsolePrinter(),
                log_printer=LogPrinter(),
                arg_list=(
                    '-c',
                    os.devnull,
                    '-f',
                    filename,
                    '-b',
                    'TestBear',
                ),
                autoapply=False,
                debug=debug,
                cache=self.cache)

            self.assertEqual(exitcode, 0)
            self.assertEqual(len(results), 1)

            # run_coala() output's name is always lower case
            self.assertEqual(file_dicts['cli'][filename.lower()],
                             (memory_data, ))
Ejemplo n.º 4
0
    def test_fileproxy_str(self):
        with prepare_file([], None) as (_, file):
            empty_fileproxy = FileProxy(file)

            gen_str = (f'<FileProxy {empty_fileproxy.filename}, '
                       f'{empty_fileproxy.version}>')

            self.assertEqual(gen_str, str(empty_fileproxy))
Ejemplo n.º 5
0
    def test_get_file_dict_with_proxy_map(self):
        with prepare_file([], None) as (_, file):
            proxy = FileProxy(file, None, 'coala\n')
            proxymap = FileProxyMap([proxy])
            self.cache.set_proxymap(proxymap)

            file_dict = self.cache.get_file_dict([file])
            self.assertEqual(file_dict, {file: ('coala\n', )})
Ejemplo n.º 6
0
    def test_fileproxy_str(self):
        with prepare_file([], None) as (_, file):
            empty_fileproxy = FileProxy(file)

            gen_str = '<FileProxy {}, {}>'.format(empty_fileproxy.filename,
                                                  empty_fileproxy.version)

            self.assertEqual(gen_str, str(empty_fileproxy))
Ejemplo n.º 7
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))
Ejemplo n.º 8
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))
Ejemplo n.º 9
0
    def test_fileproxy_relative_name(self):
        with prepare_file(['coala'], None) as (_, file):
            relative_url = os.path.relpath(file, __file__)

            with self.assertRaises(ValueError) as context:
                FileProxy(relative_url)

            self.assertEqual('expecting absolute filename',
                             str(context.exception))
Ejemplo n.º 10
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, ))
Ejemplo n.º 11
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,))
Ejemplo n.º 12
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')
Ejemplo n.º 13
0
    def test_proxymap_add(self):
        proxymap = self.empty_proxymap()

        with self.assertRaises(TypeError):
            proxymap.add(123) is False

        with self.assertRaises(TypeError):
            proxymap.add('coala') is False

        proxy_one = self.random_proxy()
        self.assertTrue(proxymap.add(proxy_one))

        proxy_two = FileProxy(proxy_one.filename, '.', 'coala-rocks')
        self.assertFalse(proxymap.add(proxy_two, replace=False))
        self.assertTrue(proxymap.add(proxy_two, replace=True))
Ejemplo n.º 14
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')
Ejemplo n.º 15
0
 def random_proxy(self, contents=['coala\n']):
     with prepare_file(contents, None) as (_, file):
         return FileProxy.from_file(file, None)
Ejemplo n.º 16
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)))
Ejemplo n.º 17
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))
Ejemplo n.º 18
0
    def test_fileproxy_get_disk_contents(self):
        with prepare_file(['coala\n'], None) as (_, file):
            proxy = FileProxy(file)

            contents = proxy.get_disk_contents()
            self.assertEqual(contents, 'coala\n')
Ejemplo n.º 19
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(), '')
Ejemplo n.º 20
0
 def test_file_from_file_missing_file(self):
     with prepare_file([], None) as (_, file):
         with self.assertRaises(OSError):
             FileProxy.from_file(file+'coala', '.')
Ejemplo n.º 21
0
 def test_file_from_file_missing_file(self):
     with prepare_file([], None) as (_, file):
         with self.assertRaises(OSError):
             FileProxy.from_file(file + 'coala', '.')
Ejemplo n.º 22
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(), '')
Ejemplo n.º 23
0
 def random_proxy(self, contents=['coala\n']):
     with prepare_file(contents, None) as (_, file):
         return FileProxy.from_file(file, None)
Ejemplo n.º 24
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))
Ejemplo n.º 25
0
    def test_fileproxy_get_disk_contents(self):
        with prepare_file(['coala\n'], None) as (_, file):
            proxy = FileProxy(file)

            contents = proxy.get_disk_contents()
            self.assertEqual(contents, 'coala\n')
Ejemplo n.º 26
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)))
Ejemplo n.º 27
0
 def test_fileproxy_normcase(self):
     with prepare_file([], None) as (_, file):
         fileproxy = FileProxy(file, None, 'coala')
         self.assertEqual(fileproxy.filename, os.path.normcase(file))