示例#1
0
    def test_combining_with_aliases(self):
        covdata1 = CoverageData()
        covdata1.add_line_data({
            '/home/ned/proj/src/a.py': {1: None, 2: None},
            '/home/ned/proj/src/sub/b.py': {3: None},
            })
        covdata1.write(suffix='1')

        covdata2 = CoverageData()
        covdata2.add_line_data({
            r'c:\ned\test\a.py': {4: None, 5: None},
            r'c:\ned\test\sub\b.py': {6: None},
            })
        covdata2.write(suffix='2')

        covdata3 = CoverageData()
        aliases = PathAliases()
        aliases.add("/home/ned/proj/src/", "./")
        aliases.add(r"c:\ned\test", "./")
        covdata3.combine_parallel_data(aliases=aliases)

        apy = canonical_filename('./a.py')
        sub_bpy = canonical_filename('./sub/b.py')

        self.assert_summary(
            covdata3, { apy: 4, sub_bpy: 2, }, fullpath=True
            )
        self.assert_measured_files(covdata3, [apy,sub_bpy])
示例#2
0
    def test_combining_with_aliases(self):
        covdata1 = CoverageData()
        covdata1.set_lines({
            '/home/ned/proj/src/a.py': {1: None, 2: None},
            '/home/ned/proj/src/sub/b.py': {3: None},
            '/home/ned/proj/src/template.html': {10: None},
        })
        covdata1.set_file_tracers({
            '/home/ned/proj/src/template.html': 'html.plugin',
        })
        self.data_files.write(covdata1, suffix='1')

        covdata2 = CoverageData()
        covdata2.set_lines({
            r'c:\ned\test\a.py': {4: None, 5: None},
            r'c:\ned\test\sub\b.py': {3: None, 6: None},
        })
        self.data_files.write(covdata2, suffix='2')

        covdata3 = CoverageData()
        aliases = PathAliases()
        aliases.add("/home/ned/proj/src/", "./")
        aliases.add(r"c:\ned\test", "./")
        self.data_files.combine_parallel_data(covdata3, aliases=aliases)

        apy = canonical_filename('./a.py')
        sub_bpy = canonical_filename('./sub/b.py')
        template_html = canonical_filename('./template.html')

        self.assert_line_counts(covdata3, {apy: 4, sub_bpy: 2, template_html: 1}, fullpath=True)
        self.assert_measured_files(covdata3, [apy, sub_bpy, template_html])
        self.assertEqual(covdata3.file_tracer(template_html), 'html.plugin')
示例#3
0
    def combine(self, data_paths=None):
        """Combine together a number of similarly-named coverage data files.

        All coverage data files whose name starts with `data_file` (from the
        coverage() constructor) will be read, and combined together into the
        current measurements.

        `data_paths` is a list of files or directories from which data should
        be combined. If no list is passed, then the data files from the
        directory indicated by the current data file (probably the current
        directory) will be combined.

        .. versionadded:: 4.0
            The `data_paths` parameter.

        """
        self._init()
        self.get_data()

        aliases = None
        if self.config.paths:
            aliases = PathAliases()
            for paths in self.config.paths.values():
                result = paths[0]
                for pattern in paths[1:]:
                    aliases.add(pattern, result)

        self.data_files.combine_parallel_data(self.data, aliases=aliases, data_paths=data_paths)
示例#4
0
 def test_multiple_wildcard(self):
     aliases = PathAliases()
     aliases.add('/home/jenkins/*/a/*/b/*/django', './django')
     self.assert_mapped(
         aliases,
         '/home/jenkins/xx/a/yy/b/zz/django/foo/bar.py',
         './django/foo/bar.py'
     )
def apply_path_aliases(cov, alias_map):
    """Adjust filenames in coverage data."""
    data = CoverageData()
    aliases = PathAliases()
    for k, v in alias_map.items():
        aliases.add(k, v)
    data.update(cov.data, aliases)
    cov.data = data
示例#6
0
def create_path_aliases_from_coverage(coverage):
    aliases = PathAliases()
    if coverage and coverage.config.paths:
        for paths in coverage.config.paths.values():
            result = paths[0]
            for pattern in paths[1:]:
                aliases.add(pattern, result)
    return aliases
示例#7
0
    def test_dot(self):
        for d in ('.', '..', '../other', '~'):
            aliases = PathAliases()
            aliases.add(d, '/the/source')
            the_file = os.path.join(d, 'a.py')
            the_file = os.path.expanduser(the_file)
            the_file = os.path.abspath(os.path.realpath(the_file))

            assert '~' not in the_file  # to be sure the test is pure.
            self.assert_mapped(aliases, the_file, '/the/source/a.py')
示例#8
0
    def combine(self):
        aliases = None
        if self.config.paths:
            aliases = PathAliases(self.file_locator)
            for paths in self.config.paths.values():
                result = paths[0]
                for pattern in paths[1:]:
                    aliases.add(pattern, result)

        self.data.combine_parallel_data(aliases=aliases)
示例#9
0
    def test_paths_are_os_corrected(self):
        aliases = PathAliases()
        aliases.add('/home/ned/*/src', './mysrc')
        aliases.add(r'c:\ned\src', './mysrc')
        self.assert_mapped(aliases, r'C:\Ned\src\sub\a.py', './mysrc/sub/a.py')

        aliases = PathAliases()
        aliases.add('/home/ned/*/src', r'.\mysrc')
        aliases.add(r'c:\ned\src', r'.\mysrc')
        self.assert_mapped(aliases, r'/home/ned/foo/src/sub/a.py', r'.\mysrc\sub\a.py')
示例#10
0
 def test_wildcard(self):
     aliases = PathAliases()
     aliases.add('/ned/home/*/src', './mysrc')
     self.assertEqual(aliases.map('/ned/home/foo/src/a.py'), './mysrc/a.py')
     aliases = PathAliases()
     aliases.add('/ned/home/*/src/', './mysrc')
     self.assertEqual(aliases.map('/ned/home/foo/src/a.py'), './mysrc/a.py')
示例#11
0
    def test_linux_on_windows(self):
        # https://bitbucket.org/ned/coveragepy/issues/618/problem-when-combining-windows-generated
        lin = "*/project/module/"
        win = "*\\project\\module\\"

        # Try the paths in both orders.
        for paths in [[lin, win], [win, lin]]:
            aliases = PathAliases()
            for path in paths:
                aliases.add(path, "project\\module")
            self.assert_mapped(
                aliases,
                "C:/a/path/somewhere/coveragepy_test/project/module/tests/file.py",
                "project\\module\\tests\\file.py"
            )
示例#12
0
    def test_dot(self):
        cases = ['.', '..', '../other', '~']
        if not env.WINDOWS:
            # The root test case was added for the manylinux Docker images,
            # and I'm not sure how it should work on Windows, so skip it.
            cases += ['/']
        for d in cases:
            aliases = PathAliases()
            aliases.add(d, '/the/source')
            the_file = os.path.join(d, 'a.py')
            the_file = os.path.expanduser(the_file)
            the_file = os.path.abspath(os.path.realpath(the_file))

            assert '~' not in the_file  # to be sure the test is pure.
            self.assert_mapped(aliases, the_file, '/the/source/a.py')
示例#13
0
文件: control.py 项目: fabio-ts/unftt
    def combine(self):
        """Combine together a number of similarly-named coverage data files.

        All coverage data files whose name starts with `data_file` (from the
        coverage() constructor) will be read, and combined together into the
        current measurements.

        """
        aliases = None
        if self.config.paths:
            aliases = PathAliases(self.file_locator)
            for paths in self.config.paths.values():
                result = paths[0]
                for pattern in paths[1:]:
                    aliases.add(pattern, result)
        self.data.combine_parallel_data(aliases=aliases)
示例#14
0
    def test_combining_with_aliases(self):
        covdata1 = CoverageData()
        covdata1.add_line_data(
            {"/home/ned/proj/src/a.py": {1: None, 2: None}, "/home/ned/proj/src/sub/b.py": {3: None}}
        )
        covdata1.write(suffix="1")

        covdata2 = CoverageData()
        covdata2.add_line_data({r"c:\ned\test\a.py": {4: None, 5: None}, r"c:\ned\test\sub\b.py": {6: None}})
        covdata2.write(suffix="2")

        covdata3 = CoverageData()
        aliases = PathAliases()
        aliases.add("/home/ned/proj/src/", "./")
        aliases.add(r"c:\ned\test", "./")
        covdata3.combine_parallel_data(aliases=aliases)
        self.assert_summary(covdata3, {"./a.py": 4, "./sub/b.py": 2}, fullpath=True)
        self.assert_measured_files(covdata3, ["./a.py", "./sub/b.py"])
示例#15
0
 def test_cant_have_wildcard_at_end(self):
     aliases = PathAliases()
     msg = "Pattern must not end with wildcards."
     with self.assertRaisesRegex(CoverageException, msg):
         aliases.add("/ned/home/*", "fooey")
     with self.assertRaisesRegex(CoverageException, msg):
         aliases.add("/ned/home/*/", "fooey")
     with self.assertRaisesRegex(CoverageException, msg):
         aliases.add("/ned/home/*/*/", "fooey")
示例#16
0
    def combine(self, data_dirs=None):
        """Combine together a number of similarly-named coverage data files.

        All coverage data files whose name starts with `data_file` (from the
        coverage() constructor) will be read, and combined together into the
        current measurements.

        `data_dirs` is a list of directories from which data files should be
        combined. If no list is passed, then the data files from the current
        directory will be combined.

        """
        self._init()
        aliases = None
        if self.config.paths:
            aliases = PathAliases()
            for paths in self.config.paths.values():
                result = paths[0]
                for pattern in paths[1:]:
                    aliases.add(pattern, result)
        self.data.combine_parallel_data(aliases=aliases, data_dirs=data_dirs)
示例#17
0
    def test_wildcard(self):
        aliases = PathAliases()
        aliases.add('/ned/home/*/src', './mysrc')
        self.assert_mapped(aliases, '/ned/home/foo/src/a.py', './mysrc/a.py')

        aliases = PathAliases()
        aliases.add('/ned/home/*/src/', './mysrc')
        self.assert_mapped(aliases, '/ned/home/foo/src/a.py', './mysrc/a.py')
示例#18
0
    def combine(self, data_paths=None, strict=False):
        """Combine together a number of similarly-named coverage data files.

        All coverage data files whose name starts with `data_file` (from the
        coverage() constructor) will be read, and combined together into the
        current measurements.

        `data_paths` is a list of files or directories from which data should
        be combined. If no list is passed, then the data files from the
        directory indicated by the current data file (probably the current
        directory) will be combined.

        If `strict` is true, then it is an error to attempt to combine when
        there are no data files to combine.

        .. versionadded:: 4.0
            The `data_paths` parameter.

        .. versionadded:: 4.3
            The `strict` parameter.

        """
        self._init()
        self._init_data(suffix=None)
        self._post_init()
        self.get_data()

        aliases = None
        if self.config.paths:
            aliases = PathAliases()
            for paths in self.config.paths.values():
                result = paths[0]
                for pattern in paths[1:]:
                    aliases.add(pattern, result)

        combine_parallel_data(self._data, aliases=aliases, data_paths=data_paths, strict=strict)
示例#19
0
    def test_combining_with_aliases(self):
        covdata1 = CoverageData(suffix='1')
        covdata1.add_lines({
            '/home/ned/proj/src/a.py': {
                1: None,
                2: None
            },
            '/home/ned/proj/src/sub/b.py': {
                3: None
            },
            '/home/ned/proj/src/template.html': {
                10: None
            },
        })
        covdata1.add_file_tracers({
            '/home/ned/proj/src/template.html':
            'html.plugin',
        })
        covdata1.write()

        covdata2 = CoverageData(suffix='2')
        covdata2.add_lines({
            r'c:\ned\test\a.py': {
                4: None,
                5: None
            },
            r'c:\ned\test\sub\b.py': {
                3: None,
                6: None
            },
        })
        covdata2.write()

        self.assert_file_count(".coverage.*", 2)

        covdata3 = CoverageData()
        aliases = PathAliases()
        aliases.add("/home/ned/proj/src/", "./")
        aliases.add(r"c:\ned\test", "./")
        combine_parallel_data(covdata3, aliases=aliases)
        self.assert_file_count(".coverage.*", 0)
        # covdata3 hasn't been written yet. Should this file exist or not?
        #self.assert_exists(".coverage")

        apy = canonical_filename('./a.py')
        sub_bpy = canonical_filename('./sub/b.py')
        template_html = canonical_filename('./template.html')

        self.assert_line_counts(covdata3, {
            apy: 4,
            sub_bpy: 2,
            template_html: 1
        },
                                fullpath=True)
        self.assert_measured_files(covdata3, [apy, sub_bpy, template_html])
        self.assertEqual(covdata3.file_tracer(template_html), 'html.plugin')
示例#20
0
    def update(self, other_data, aliases=None):
        if self._has_lines and other_data._has_arcs:
            raise CoverageException("Can't combine arc data with line data")
        if self._has_arcs and other_data._has_lines:
            raise CoverageException("Can't combine line data with arc data")

        aliases = aliases or PathAliases()

        # See what we had already measured, for accurate conflict reporting.
        this_measured = self.measured_files()

        # lines
        if other_data._has_lines:
            for context in other_data.measured_contexts():
                self.set_context(context)
                for filename in other_data.measured_files():
                    lines = set(other_data.lines(filename, context=context))
                    filename = aliases.map(filename)
                    lines.update(self.lines(filename, context=context) or ())
                    self.add_lines({filename: lines})

        # arcs
        if other_data._has_arcs:
            for context in other_data.measured_contexts():
                self.set_context(context)
                for filename in other_data.measured_files():
                    arcs = set(other_data.arcs(filename, context=context))
                    filename = aliases.map(filename)
                    arcs.update(self.arcs(filename, context=context) or ())
                    self.add_arcs({filename: arcs})

        # file_tracers
        for filename in other_data.measured_files():
            other_plugin = other_data.file_tracer(filename)
            filename = aliases.map(filename)
            if filename in this_measured:
                this_plugin = self.file_tracer(filename)
            else:
                this_plugin = None
            if this_plugin is None:
                self.add_file_tracers({filename: other_plugin})
            elif this_plugin != other_plugin:
                raise CoverageException(
                    "Conflicting file tracer name for '%s': %r vs %r" % (
                        filename,
                        this_plugin,
                        other_plugin,
                    ))
示例#21
0
文件: data.py 项目: connoryang/1v1dec
    def combine_parallel_data(self, aliases=None):
        aliases = aliases or PathAliases()
        data_dir, local = os.path.split(self.filename)
        localdot = local + '.'
        for f in os.listdir(data_dir or '.'):
            if f.startswith(localdot):
                full_path = os.path.join(data_dir, f)
                new_lines, new_arcs = self._read_file(full_path)
                for filename, file_data in iitems(new_lines):
                    filename = aliases.map(filename)
                    self.lines.setdefault(filename, {}).update(file_data)

                for filename, file_data in iitems(new_arcs):
                    filename = aliases.map(filename)
                    self.arcs.setdefault(filename, {}).update(file_data)

                if f != local:
                    os.remove(full_path)
示例#22
0
    def test_combining_with_aliases(self):
        covdata1 = CoverageData()
        covdata1.add_line_data({
            '/home/ned/proj/src/a.py': {
                1: None,
                2: None
            },
            '/home/ned/proj/src/sub/b.py': {
                3: None
            },
        })
        covdata1.write(suffix='1')

        covdata2 = CoverageData()
        covdata2.add_line_data({
            r'c:\ned\test\a.py': {
                4: None,
                5: None
            },
            r'c:\ned\test\sub\b.py': {
                6: None
            },
        })
        covdata2.write(suffix='2')

        covdata3 = CoverageData()
        aliases = PathAliases()
        aliases.add("/home/ned/proj/src/", "./")
        aliases.add(r"c:\ned\test", "./")
        covdata3.combine_parallel_data(aliases=aliases)
        self.assert_summary(covdata3, {
            './a.py': 4,
            './sub/b.py': 2
        },
                            fullpath=True)
        self.assert_measured_files(covdata3, ['./a.py', './sub/b.py'])
示例#23
0
 def test_no_accidental_match(self):
     aliases = PathAliases()
     aliases.add('/home/*/src', './mysrc')
     self.assertEqual(aliases.map('/home/foo/srcetc'), '/home/foo/srcetc')
示例#24
0
 def test_nomatch(self):
     aliases = PathAliases()
     aliases.add('/home/*/src', './mysrc')
     self.assert_unchanged(aliases, '/home/foo/a.py')
示例#25
0
 def test_leading_wildcard(self):
     aliases = PathAliases()
     aliases.add('*/d1', './mysrc1')
     aliases.add('*/d2', './mysrc2')
     self.assert_mapped(aliases, '/foo/bar/d1/x.py', './mysrc1/x.py')
     self.assert_mapped(aliases, '/foo/bar/d2/y.py', './mysrc2/y.py')
示例#26
0
 def test_no_accidental_munging(self):
     aliases = PathAliases()
     aliases.add(r'c:\Zoo\boo', 'src/')
     aliases.add('/home/ned$', 'src/')
     self.assert_mapped(aliases, r'c:\Zoo\boo\foo.py', 'src/foo.py')
     self.assert_mapped(aliases, r'/home/ned$/foo.py', 'src/foo.py')
示例#27
0
 def test_multiple_patterns(self):
     aliases = PathAliases()
     aliases.add('/home/*/src', './mysrc')
     aliases.add('/lib/*/libsrc', './mylib')
     self.assert_mapped(aliases, '/home/foo/src/a.py', './mysrc/a.py')
     self.assert_mapped(aliases, '/lib/foo/libsrc/a.py', './mylib/a.py')
示例#28
0
 def test_multiple_patterns(self, rel_yn):
     aliases = PathAliases(relative=rel_yn)
     aliases.add('/home/*/src', './mysrc')
     aliases.add('/lib/*/libsrc', './mylib')
     self.assert_mapped(aliases, '/home/foo/src/a.py', './mysrc/a.py', relative=rel_yn)
     self.assert_mapped(aliases, '/lib/foo/libsrc/a.py', './mylib/a.py', relative=rel_yn)
示例#29
0
    def update(self, other_data, aliases=None):
        """Update this data with data from several other :class:`CoverageData` instances.

        If `aliases` is provided, it's a `PathAliases` object that is used to
        re-map paths to match the local machine's.
        """
        if self._debug.should('dataop'):
            self._debug.write("Updating with data from {!r}".format(
                getattr(other_data, '_filename', '???'), ))
        if self._has_lines and other_data._has_arcs:
            raise CoverageException("Can't combine arc data with line data")
        if self._has_arcs and other_data._has_lines:
            raise CoverageException("Can't combine line data with arc data")

        aliases = aliases or PathAliases()

        # Force the database we're writing to to exist before we start nesting
        # contexts.
        self._start_using()

        # Collector for all arcs, lines and tracers
        other_data.read()
        with other_data._connect() as conn:
            # Get files data.
            cur = conn.execute('select path from file')
            files = {path: aliases.map(path) for (path, ) in cur}
            cur.close()

            # Get contexts data.
            cur = conn.execute('select context from context')
            contexts = [context for (context, ) in cur]
            cur.close()

            # Get arc data.
            cur = conn.execute(
                'select file.path, context.context, arc.fromno, arc.tono '
                'from arc '
                'inner join file on file.id = arc.file_id '
                'inner join context on context.id = arc.context_id')
            arcs = [(files[path], context, fromno, tono)
                    for (path, context, fromno, tono) in cur]
            cur.close()

            # Get line data.
            cur = conn.execute(
                'select file.path, context.context, line_bits.numbits '
                'from line_bits '
                'inner join file on file.id = line_bits.file_id '
                'inner join context on context.id = line_bits.context_id')
            lines = {(files[path], context): numbits
                     for (path, context, numbits) in cur}
            cur.close()

            # Get tracer data.
            cur = conn.execute('select file.path, tracer '
                               'from tracer '
                               'inner join file on file.id = tracer.file_id')
            tracers = {files[path]: tracer for (path, tracer) in cur}
            cur.close()

        with self._connect() as conn:
            conn.con.isolation_level = 'IMMEDIATE'

            # Get all tracers in the DB. Files not in the tracers are assumed
            # to have an empty string tracer. Since Sqlite does not support
            # full outer joins, we have to make two queries to fill the
            # dictionary.
            this_tracers = {
                path: ''
                for path, in conn.execute('select path from file')
            }
            this_tracers.update({
                aliases.map(path): tracer
                for path, tracer in conn.execute(
                    'select file.path, tracer from tracer '
                    'inner join file on file.id = tracer.file_id')
            })

            # Create all file and context rows in the DB.
            conn.executemany('insert or ignore into file (path) values (?)',
                             ((file, ) for file in files.values()))
            file_ids = {
                path: id
                for id, path in conn.execute('select id, path from file')
            }
            conn.executemany(
                'insert or ignore into context (context) values (?)',
                ((context, ) for context in contexts))
            context_ids = {
                context: id
                for id, context in conn.execute(
                    'select id, context from context')
            }

            # Prepare tracers and fail, if a conflict is found.
            # tracer_paths is used to ensure consistency over the tracer data
            # and tracer_map tracks the tracers to be inserted.
            tracer_map = {}
            for path in files.values():
                this_tracer = this_tracers.get(path)
                other_tracer = tracers.get(path, '')
                # If there is no tracer, there is always the None tracer.
                if this_tracer is not None and this_tracer != other_tracer:
                    raise CoverageException(
                        "Conflicting file tracer name for '{}': {!r} vs {!r}".
                        format(path, this_tracer, other_tracer))
                tracer_map[path] = other_tracer

            # Prepare arc and line rows to be inserted by converting the file
            # and context strings with integer ids. Then use the efficient
            # `executemany()` to insert all rows at once.
            arc_rows = ((file_ids[file], context_ids[context], fromno, tono)
                        for file, context, fromno, tono in arcs)

            # Get line data.
            cur = conn.execute(
                'select file.path, context.context, line_bits.numbits '
                'from line_bits '
                'inner join file on file.id = line_bits.file_id '
                'inner join context on context.id = line_bits.context_id')
            for path, context, numbits in cur:
                key = (aliases.map(path), context)
                if key in lines:
                    numbits = numbits_union(lines[key], numbits)
                lines[key] = numbits
            cur.close()

            if arcs:
                self._choose_lines_or_arcs(arcs=True)

                # Write the combined data.
                conn.executemany(
                    'insert or ignore into arc '
                    '(file_id, context_id, fromno, tono) values (?, ?, ?, ?)',
                    arc_rows)

            if lines:
                self._choose_lines_or_arcs(lines=True)
                conn.execute("delete from line_bits")
                conn.executemany(
                    "insert into line_bits "
                    "(file_id, context_id, numbits) values (?, ?, ?)",
                    [(file_ids[file], context_ids[context], numbits)
                     for (file, context), numbits in lines.items()])
            conn.executemany(
                'insert or ignore into tracer (file_id, tracer) values (?, ?)',
                ((file_ids[filename], tracer)
                 for filename, tracer in tracer_map.items()))

        # Update all internal cache data.
        self._reset()
        self.read()
示例#30
0
 def test_nomatch(self):
     aliases = PathAliases()
     aliases.add('/home/*/src', './mysrc')
     self.assertEqual(aliases.map('/home/foo/a.py'), '/home/foo/a.py')
示例#31
0
 def test_noop(self):
     aliases = PathAliases()
     self.assertEqual(aliases.map('/ned/home/a.py'), '/ned/home/a.py')
示例#32
0
 def test_leading_wildcard(self):
     aliases = PathAliases()
     aliases.add('*/d1', './mysrc1')
     aliases.add('*/d2', './mysrc2')
     self.assert_mapped(aliases, '/foo/bar/d1/x.py', './mysrc1/x.py')
     self.assert_mapped(aliases, '/foo/bar/d2/y.py', './mysrc2/y.py')
示例#33
0
 def test_windows_root_paths(self):
     aliases = PathAliases()
     aliases.add('X:\\', '/tmp/src')
     self.assert_mapped(aliases, "X:\\a\\file.py", "/tmp/src/a/file.py")
     self.assert_mapped(aliases, "X:\\file.py", "/tmp/src/file.py")
示例#34
0
 def test_no_accidental_match(self):
     aliases = PathAliases()
     aliases.add('/home/*/src', './mysrc')
     self.assert_unchanged(aliases, '/home/foo/srcetc')
示例#35
0
 def test_multiple_patterns(self):
     aliases = PathAliases()
     aliases.add('/home/*/src', './mysrc')
     aliases.add('/lib/*/libsrc', './mylib')
     self.assertEqual(aliases.map('/home/foo/src/a.py'), './mysrc/a.py')
     self.assertEqual(aliases.map('/lib/foo/libsrc/a.py'), './mylib/a.py')
示例#36
0
 def test_cant_have_wildcard_at_end(self, badpat):
     aliases = PathAliases()
     msg = "Pattern must not end with wildcards."
     with pytest.raises(ConfigError, match=msg):
         aliases.add(badpat, "fooey")
示例#37
0
 def test_noop(self):
     aliases = PathAliases()
     self.assert_not_mapped(aliases, '/ned/home/a.py')
示例#38
0
 def test_nomatch(self):
     aliases = PathAliases()
     aliases.add('/home/*/src', './mysrc')
     self.assert_not_mapped(aliases, '/home/foo/a.py')
示例#39
0
    def test_paths_are_os_corrected(self, rel_yn):
        aliases = PathAliases(relative=rel_yn)
        aliases.add('/home/ned/*/src', './mysrc')
        aliases.add(r'c:\ned\src', './mysrc')
        self.assert_mapped(aliases, r'C:\Ned\src\sub\a.py', './mysrc/sub/a.py', relative=rel_yn)

        aliases = PathAliases(relative=rel_yn)
        aliases.add('/home/ned/*/src', r'.\mysrc')
        aliases.add(r'c:\ned\src', r'.\mysrc')
        self.assert_mapped(
            aliases,
            r'/home/ned/foo/src/sub/a.py',
            r'.\mysrc\sub\a.py',
            relative=rel_yn,
        )
示例#40
0
 def test_no_accidental_match(self):
     aliases = PathAliases()
     aliases.add('/home/*/src', './mysrc')
     self.assert_not_mapped(aliases, '/home/foo/srcetc')
示例#41
0
 def test_no_accidental_munging(self):
     aliases = PathAliases()
     aliases.add(r'c:\Zoo\boo', 'src/')
     aliases.add('/home/ned$', 'src/')
     self.assertEqual(aliases.map(r'c:\Zoo\boo\foo.py'), 'src/foo.py')
     self.assertEqual(aliases.map(r'/home/ned$/foo.py'), 'src/foo.py')
示例#42
0
 def test_noop(self, rel_yn):
     aliases = PathAliases(relative=rel_yn)
     self.assert_unchanged(aliases, '/ned/home/a.py')
示例#43
0
    def test_paths_are_os_corrected(self):
        aliases = PathAliases()
        aliases.add('/home/ned/*/src', './mysrc')
        aliases.add(r'c:\ned\src', './mysrc')
        mapped = aliases.map(r'C:\Ned\src\sub\a.py')
        self.assertEqual(mapped, './mysrc/sub/a.py')

        aliases = PathAliases()
        aliases.add('/home/ned/*/src', r'.\mysrc')
        aliases.add(r'c:\ned\src', r'.\mysrc')
        mapped = aliases.map(r'/home/ned/foo/src/sub/a.py')
        self.assertEqual(mapped, r'.\mysrc\sub\a.py')
示例#44
0
 def test_noop(self):
     aliases = PathAliases()
     self.assertEqual(aliases.map('/ned/home/a.py'), '/ned/home/a.py')
示例#45
0
 def test_nomatch(self):
     aliases = PathAliases()
     aliases.add('/home/*/src', './mysrc')
     self.assertEqual(aliases.map('/home/foo/a.py'), '/home/foo/a.py')
示例#46
0
 def test_multiple_wildcard(self):
     aliases = PathAliases()
     aliases.add('/home/jenkins/*/a/*/b/*/django', './django')
     self.assert_mapped(aliases,
                        '/home/jenkins/xx/a/yy/b/zz/django/foo/bar.py',
                        './django/foo/bar.py')
示例#47
0
 def test_noop(self):
     aliases = PathAliases()
     self.assert_unchanged(aliases, '/ned/home/a.py')