def test_02_comment(self):
        """
		Tests a comment pattern.
		"""
        regex, include = GitIgnorePattern.pattern_to_regex('# Cork soakers.')
        self.assertIsNone(include)
        self.assertIsNone(regex)
Exemplo n.º 2
0
    def test_04_postfix_wildcard(self):
        """
		Tests a pattern with a postfix wildcard.
		"""
        spec = GitIgnorePattern('~temp-*')
        self.assertTrue(spec.include)
        self.assertEquals(spec.regex.pattern, '^(?:.+/)?\\~temp\\-[^/]*$')
Exemplo n.º 3
0
    def test_03_parent_double_asterisk(self):
        """
		Tests a file name with a double-asterisk parent directory.
		"""
        spec = GitIgnorePattern('**/spam')
        self.assertTrue(spec.include)
        self.assertEquals(spec.regex.pattern, '^(?:.+/)?spam$')
Exemplo n.º 4
0
    def test_03_inner_double_asterisk(self):
        """
		Tests a path with an inner double-asterisk directory.
		"""
        spec = GitIgnorePattern('left/**/right')
        self.assertTrue(spec.include)
        self.assertEquals(spec.regex.pattern, '^(?:.+/)?left(?:/.+)?/right$')
Exemplo n.º 5
0
    def test_04_prefix_wildcard(self):
        """
		Tests a pattern with a prefix wildcard.
		"""
        spec = GitIgnorePattern('*.py')
        self.assertTrue(spec.include)
        self.assertEquals(spec.regex.pattern, '^(?:.+/)?[^/]*\\.py$')
Exemplo n.º 6
0
    def test_05_directory(self):
        """
		Tests a directory pattern.
		"""
        spec = GitIgnorePattern('dir/')
        self.assertTrue(spec.include)
        self.assertEquals(spec.regex.pattern, '^(?:.+/)?dir/.*$')
Exemplo n.º 7
0
    def test_04_infix_wildcard(self):
        """
		Tests a pattern with an infix wildcard.
		"""
        spec = GitIgnorePattern('foo-*-bar')
        self.assertTrue(spec.include)
        self.assertEquals(spec.regex.pattern, '^(?:.+/)?foo\\-[^/]*\\-bar$')
Exemplo n.º 8
0
    def test_01_absolute(self):
        """
		Tests an absolute path pattern.
		"""
        spec = GitIgnorePattern('/an/absolute/file/path')
        self.assertTrue(spec.include)
        self.assertEquals(spec.regex.pattern, '^an/absolute/file/path$')
    def test_00_empty(self):
        """
		Tests an empty pattern.
		"""
        regex, include = GitIgnorePattern.pattern_to_regex('')
        self.assertIsNone(include)
        self.assertIsNone(regex)
Exemplo n.º 10
0
    def test_03_only_double_asterisk(self):
        """
		Tests a double-asterisk pattern which matches everything.
		"""
        spec = GitIgnorePattern('**')
        self.assertTrue(spec.include)
        self.assertEquals(spec.regex.pattern, '^.+$')
Exemplo n.º 11
0
    def test_01_relative(self):
        """
		Tests a relative path pattern.
		"""
        spec = GitIgnorePattern('spam')
        self.assertTrue(spec.include)
        self.assertEquals(spec.regex.pattern, '^(?:.+/)?spam$')
    def test_03_only_double_asterisk(self):
        """
		Tests a double-asterisk pattern which matches everything.
		"""
        regex, include = GitIgnorePattern.pattern_to_regex('**')
        self.assertTrue(include)
        self.assertEqual(regex, '^.+$')
Exemplo n.º 13
0
    def test_02_comment(self):
        """
		Tests a comment pattern.
		"""
        spec = GitIgnorePattern('# Cork soakers.')
        self.assertIsNone(spec.include)
        self.assertIsNone(spec.regex)
Exemplo n.º 14
0
    def test_00_empty(self):
        """
		Tests an empty pattern.
		"""
        spec = GitIgnorePattern('')
        self.assertIsNone(spec.include)
        self.assertIsNone(spec.regex)
Exemplo n.º 15
0
    def test_02_ignore(self):
        """
		Tests an exclude pattern.
		"""
        spec = GitIgnorePattern('!temp')
        self.assertIsNotNone(spec.include)
        self.assertFalse(spec.include)
        self.assertEquals(spec.regex.pattern, '^(?:.+/)?temp$')
Exemplo n.º 16
0
    def test_03_child_double_asterisk(self):
        """
		Tests a directory name with a double-asterisk child
		directory.
		"""
        spec = GitIgnorePattern('spam/**')
        self.assertTrue(spec.include)
        self.assertEquals(spec.regex.pattern, '^(?:.+/)?spam/.*$')
	def test_01_absolute_root(self):
		"""
		Tests a single root absolute path pattern.

		This should NOT match any file (according to git check-ignore (v2.4.1)).
		"""
		spec = GitIgnorePattern('/')
		self.assertIsNone(spec.include)
		self.assertIsNone(spec.regex)
	def test_02_ignore(self):
		"""
		Tests an exclude pattern.

		This should NOT match (according to git check-ignore (v2.4.1)):
		temp/foo
		"""
		spec = GitIgnorePattern('!temp')
		self.assertIsNotNone(spec.include)
		self.assertFalse(spec.include)
		self.assertEqual(spec.regex.pattern, '^(?:.+/)?temp$')
	def test_03_parent_double_asterisk(self):
		"""
		Tests a file name with a double-asterisk parent directory.

		This should match:
		foo/spam
		foo/spam/bar
		"""
		spec = GitIgnorePattern('**/spam')
		self.assertTrue(spec.include)
		self.assertEqual(spec.regex.pattern, '^(?:.+/)?spam(?:/.*)?$')
Exemplo n.º 20
0
    def extract_bower_zipfile(self, zip_file, dest, expected_version=None):
        bower_json = None
        root = None
        deps_installed = []
        for info in zip_file.infolist():
            if PurePath(info.filename).name == "bower.json":
                with zip_file.open(info) as f:
                    bower_json = json.load(f)
                    root = str(PurePath(info.filename).parent)
                break
        version = bower_json["version"]
        if expected_version is not None:
            expected_version = Bower.clean_semver(expected_version)
            if not semver.match(version, expected_version):
                click.secho("error: versions do not match ({} =/= {})".format(
                    version, expected_version))
                raise InvalidPackageError
        if "dependencies" in bower_json:
            for package, version in bower_json["dependencies"].items():
                url = Bower.get_package_url(package)
                deps_installed.extend(
                    self.get_bower_package(url, dest=dest, version=version))
        ignore_patterns = [GitIgnorePattern(ig) for ig in bower_json["ignore"]]
        path_spec = PathSpec(ignore_patterns)
        namelist = [
            path for path in zip_file.namelist()
            if PurePath(path).parts[0] == root
        ]
        ignored = list(path_spec.match_files(namelist))
        for path in namelist:
            dest_path = PurePath(bower_json["name"], *PurePath(path).parts[1:])

            if path in ignored:
                continue

            for path in ignored:
                for parent in PurePath(path):
                    if parent in ignored:
                        continue

            if path.endswith("/"):
                if list(path_spec.match_files([str(dest_path)])):
                    ignored.append(PurePath(path))
                elif not (dest / dest_path).is_dir():
                    (dest / dest_path).mkdir(parents=True)
            else:
                target_path = dest / dest_path.parent / dest_path.name
                source = zip_file.open(path)
                target = target_path.open("wb")
                with source, target:
                    shutil.copyfileobj(source, target)
        deps_installed.append((bower_json["name"], bower_json["version"]))
        return deps_installed
	def test_04_prefix_wildcard(self):
		"""
		Tests a pattern with a prefix wildcard.

		This should match:
		bar.py
		bar.py/
		foo/bar.py
		foo/bar.py/baz
		"""
		spec = GitIgnorePattern('*.py')
		self.assertTrue(spec.include)
		self.assertEqual(spec.regex.pattern, '^(?:.+/)?[^/]*\\.py(?:/.*)?$')
	def test_01_absolute(self):
		"""
		Tests an absolute path pattern.

		This should match:
		an/absolute/file/path
		an/absolute/file/path/foo

		This should NOT match:
		foo/an/absolute/file/path
		"""
		spec = GitIgnorePattern('/an/absolute/file/path')
		self.assertTrue(spec.include)
		self.assertEqual(spec.regex.pattern, '^an/absolute/file/path(?:/.*)?$')
	def test_01_relative(self):
		"""
		Tests a relative path pattern.

		This should match:
		spam
		spam/
		foo/spam
		spam/foo
		foo/spam/bar
		"""
		spec = GitIgnorePattern('spam')
		self.assertTrue(spec.include)
		self.assertEqual(spec.regex.pattern, '^(?:.+/)?spam(?:/.*)?$')
	def test_01_relative_nested(self):
		"""
		Tests a relative nested path pattern.

		This should match:
		foo/spam
		foo/spam/bar

		This should **not** match (according to git check-ignore (v2.4.1)):
		bar/foo/spam
		"""
		spec = GitIgnorePattern('foo/spam')
		self.assertTrue(spec.include)
		self.assertEqual(spec.regex.pattern, '^foo/spam(?:/.*)?$')
	def test_03_child_double_asterisk(self):
		"""
		Tests a directory name with a double-asterisk child
		directory.

		This should match:
		spam/bar

		This should **not** match (according to git check-ignore (v2.4.1)):
		foo/spam/bar
		"""
		spec = GitIgnorePattern('spam/**')
		self.assertTrue(spec.include)
		self.assertEqual(spec.regex.pattern, '^spam/.*$')
	def test_04_postfix_wildcard(self):
		"""
		Tests a pattern with a postfix wildcard.

		This should match:
		~temp-
		~temp-foo
		~temp-foo/bar
		foo/~temp-bar
		foo/~temp-bar/baz
		"""
		spec = GitIgnorePattern('~temp-*')
		self.assertTrue(spec.include)
		self.assertEqual(spec.regex.pattern, '^(?:.+/)?\\~temp\\-[^/]*(?:/.*)?$')
	def test_04_infix_wildcard(self):
		"""
		Tests a pattern with an infix wildcard.

		This should match:
		foo--bar
		foo-hello-bar
		a/foo-hello-bar
		foo-hello-bar/b
		a/foo-hello-bar/b
		"""
		spec = GitIgnorePattern('foo-*-bar')
		self.assertTrue(spec.include)
		self.assertEqual(spec.regex.pattern, '^(?:.+/)?foo\\-[^/]*\\-bar(?:/.*)?$')
	def test_05_directory(self):
		"""
		Tests a directory pattern.

		This should match:
		dir/
		foo/dir/
		foo/dir/bar

		This should **not** match:
		dir
		"""
		spec = GitIgnorePattern('dir/')
		self.assertTrue(spec.include)
		self.assertEqual(spec.regex.pattern, '^(?:.+/)?dir/.*$')
	def test_03_inner_double_asterisk(self):
		"""
		Tests a path with an inner double-asterisk directory.

		This should match:
		left/bar/right
		left/foo/bar/right
		left/bar/right/foo

		This should **not** match (according to git check-ignore (v2.4.1)):
		foo/left/bar/right
		"""
		spec = GitIgnorePattern('left/**/right')
		self.assertTrue(spec.include)
		self.assertEqual(spec.regex.pattern, '^left(?:/.+)?/right(?:/.*)?$')
    def test_01_relative(self):
        """
		Tests a relative path pattern.

		This should match:

			spam
			spam/
			foo/spam
			spam/foo
			foo/spam/bar
		"""
        regex, include = GitIgnorePattern.pattern_to_regex('spam')
        self.assertTrue(include)
        self.assertEqual(regex, '^(?:.+/)?spam(?:/.*)?$')