コード例 #1
0
ファイル: test_files.py プロジェクト: wenshiqi0/gecko-dev
class TestComposedFinder(MatchTestTemplate, TestWithTmpDir):
    def add(self, path, content=None):
        # Put foo/qux files under $tmp/b.
        if path.startswith('foo/qux/'):
            real_path = mozpath.join('b', path[8:])
        else:
            real_path = mozpath.join('a', path)
        ensureParentDir(self.tmppath(real_path))
        if not content:
            content = path
        open(self.tmppath(real_path), 'wb').write(content)

    def do_check(self, pattern, result):
        if '*' in pattern:
            return
        do_check(self, self.finder, pattern, result)

    def test_composed_finder(self):
        self.prepare_match_test()
        # Also add files in $tmp/a/foo/qux because ComposedFinder is
        # expected to mask foo/qux entirely with content from $tmp/b.
        ensureParentDir(self.tmppath('a/foo/qux/hoge'))
        open(self.tmppath('a/foo/qux/hoge'), 'wb').write('hoge')
        open(self.tmppath('a/foo/qux/bar'), 'wb').write('not the right content')
        self.finder = ComposedFinder({
            '': FileFinder(self.tmppath('a')),
            'foo/qux': FileFinder(self.tmppath('b')),
        })
        self.do_match_test()

        self.assertIsNone(self.finder.get('does-not-exist'))
        self.assertIsInstance(self.finder.get('bar'), File)
コード例 #2
0
ファイル: test_files.py プロジェクト: jt9897253/mozjs
class TestComposedFinder(MatchTestTemplate, TestWithTmpDir):
    def add(self, path, content=None):
        # Put foo/qux files under $tmp/b.
        if path.startswith("foo/qux/"):
            real_path = mozpath.join("b", path[8:])
        else:
            real_path = mozpath.join("a", path)
        ensureParentDir(self.tmppath(real_path))
        if not content:
            content = six.ensure_binary(path)
        open(self.tmppath(real_path), "wb").write(content)

    def do_check(self, pattern, result):
        if "*" in pattern:
            return
        do_check(self, self.finder, pattern, result)

    def test_composed_finder(self):
        self.prepare_match_test()
        # Also add files in $tmp/a/foo/qux because ComposedFinder is
        # expected to mask foo/qux entirely with content from $tmp/b.
        ensureParentDir(self.tmppath("a/foo/qux/hoge"))
        open(self.tmppath("a/foo/qux/hoge"), "wb").write(b"hoge")
        open(self.tmppath("a/foo/qux/bar"),
             "wb").write(b"not the right content")
        self.finder = ComposedFinder({
            "": FileFinder(self.tmppath("a")),
            "foo/qux": FileFinder(self.tmppath("b")),
        })
        self.do_match_test()

        self.assertIsNone(self.finder.get("does-not-exist"))
        self.assertIsInstance(self.finder.get("bar"), File)
コード例 #3
0
ファイル: test_files.py プロジェクト: MekliCZ/positron
class TestComposedFinder(MatchTestTemplate, TestWithTmpDir):
    def add(self, path, content=None):
        # Put foo/qux files under $tmp/b.
        if path.startswith('foo/qux/'):
            real_path = mozpath.join('b', path[8:])
        else:
            real_path = mozpath.join('a', path)
        ensureParentDir(self.tmppath(real_path))
        if not content:
            content = path
        open(self.tmppath(real_path), 'wb').write(content)

    def do_check(self, pattern, result):
        if '*' in pattern:
            return
        do_check(self, self.finder, pattern, result)

    def test_composed_finder(self):
        self.prepare_match_test()
        # Also add files in $tmp/a/foo/qux because ComposedFinder is
        # expected to mask foo/qux entirely with content from $tmp/b.
        ensureParentDir(self.tmppath('a/foo/qux/hoge'))
        open(self.tmppath('a/foo/qux/hoge'), 'wb').write('hoge')
        open(self.tmppath('a/foo/qux/bar'), 'wb').write('not the right content')
        self.finder = ComposedFinder({
            '': FileFinder(self.tmppath('a')),
            'foo/qux': FileFinder(self.tmppath('b')),
        })
        self.do_match_test()

        self.assertIsNone(self.finder.get('does-not-exist'))
        self.assertIsInstance(self.finder.get('bar'), File)