def test_bash_cases(self, case): """Test bash cases.""" test_case = self.eval_str_esc(case[0]) entry = case[1] print('TEST: ', test_case) self.assert_equal(test_case, entry[0]) expansions = bracex.expand(test_case) if not (len(expansions) == 1 and not expansions[0]): index = 1 for a in expansions: b = RE_REMOVE.sub('', entry[index]) print(' ', a, '<==>', b) self.assert_equal(a, b) index += 1 # Bytes test_case = test_case.encode('utf-8') self.assert_equal(test_case, entry[0].encode('utf-8')) expansions = bracex.expand(test_case) if not (len(expansions) == 1 and not expansions[0]): index = 1 for a in expansions: b = BRE_REMOVE.sub(b'', entry[index].encode('utf-8')) print(' ', a, '<==>', b) self.assert_equal(a, b) index += 1
def test_expansion_limit_expand(self): """Test expansion limit.""" self.assertEqual( len( bracex.expand('text{1,2}text{{3,4,{5,6}text{7,8}},{9}}', limit=14)), 14) with self.assertRaises(bracex.ExpansionLimitException): bracex.expand('text{1,2}text{{3,4,{5,6}text{7,8}},{9}}', limit=13)
def __call__(self, build_id: str) -> bool: build_patterns = itertools.chain.from_iterable( bracex.expand(p) for p in self.build_patterns) skip_patterns = itertools.chain.from_iterable( bracex.expand(p) for p in self.skip_patterns) build: bool = any( fnmatch.fnmatch(build_id, pat) for pat in build_patterns) skip: bool = any( fnmatch.fnmatch(build_id, pat) for pat in skip_patterns) return build and not skip
def test_expansion_no_limit_expand(self): """Test expansion no limit.""" self.assertEqual( len( bracex.expand('text{1,2}text{{3,4,{5,6}text{7,8}},{9}}', limit=0)), 14)
def __call__(self, build_id: str) -> bool: # Filter build selectors by python_requires if set if self.requires_python is not None: py_ver_str = build_id.split('-')[0] major = int(py_ver_str[2]) minor = int(py_ver_str[3:]) version = Version(f"{major}.{minor}.99") if not self.requires_python.contains(version): return False build_patterns = itertools.chain.from_iterable(bracex.expand(p) for p in self.build_patterns) skip_patterns = itertools.chain.from_iterable(bracex.expand(p) for p in self.skip_patterns) build: bool = any(fnmatch.fnmatch(build_id, pat) for pat in build_patterns) skip: bool = any(fnmatch.fnmatch(build_id, pat) for pat in skip_patterns) return build and not skip
def selector_matches(patterns: str, string: str) -> bool: """ Returns True if `string` is matched by any of the wildcard patterns in `patterns`. Matching is according to fnmatch, but with shell-like curly brace expansion. For example, 'cp{36,37}-*' would match either of 'cp36-*' or 'cp37-*'. """ patterns_list = patterns.split() expanded_patterns = itertools.chain.from_iterable( bracex.expand(p) for p in patterns_list) return any(fnmatch.fnmatch(string, pat) for pat in expanded_patterns)
def test_expansion_num_negative_reversed_limt_expand_neg_step(self): """Test expansion numeric negative reversed limit with `expand` negative step.""" self.assertEqual(len(bracex.expand('{-11..-11..-7}', limit=1)), 1) with self.assertRaises(bracex.ExpansionLimitException): bracex.expand('{-11..-1..-7}', limit=1)
def test_expansion_num_reverse_limt_expand_neg_step(self): """Test expansion numeric reversed limit with `expand` negative step.""" self.assertEqual(len(bracex.expand('{11..1..-3}', limit=4)), 4) with self.assertRaises(bracex.ExpansionLimitException): bracex.expand('{11..1..-3}', limit=3)
def test_expansion_num_limt_expand_neg_step(self): """Test expansion numeric limit with `expand` negative step.""" self.assertEqual(len(bracex.expand('{1..11..-5}', limit=3)), 3) with self.assertRaises(bracex.ExpansionLimitException): bracex.expand('{1..11..-5}', limit=2)
def test_expansion_num_negative_limt_expand_step(self): """Test expansion numeric negative limit with `expand`.""" self.assertEqual(len(bracex.expand('{-1..-11..2}', limit=6)), 6) with self.assertRaises(bracex.ExpansionLimitException): bracex.expand('{-1..-11..2}', limit=5)
def test_expansion_num_reverse_limt_expand(self): """Test expansion numeric reversed limit with `expand`.""" self.assertEqual(len(bracex.expand('{11..1}', limit=11)), 11) with self.assertRaises(bracex.ExpansionLimitException): bracex.expand('{11..1}', limit=10)
def test_expansion_char_reverse_limt_expand_step5_neg(self): """Test expansion character reversed limit with `expand` step -5.""" self.assertEqual(len(bracex.expand('{k..a..-5}', limit=3)), 3) with self.assertRaises(bracex.ExpansionLimitException): bracex.expand('{k..a..-5}', limit=2)
def test_expansion_char_limt_expand_step3_neg(self): """Test expansion character limit with `expand` step -3.""" self.assertEqual(len(bracex.expand('{a..k..-3}', limit=4)), 4) with self.assertRaises(bracex.ExpansionLimitException): bracex.expand('{a..k..-3}', limit=3)
def test_expansion_char_reverse_limt_expand_step2(self): """Test expansion character reversed limit with `expand` step 2.""" self.assertEqual(len(bracex.expand('{k..a..2}', limit=6)), 6) with self.assertRaises(bracex.ExpansionLimitException): bracex.expand('{k..a..2}', limit=5)
def test_expansion_char_limt_expand_step5(self): """Test expansion character limit with `expand` step 5.""" self.assertEqual(len(bracex.expand('{a..k..5}', limit=3)), 3) with self.assertRaises(bracex.ExpansionLimitException): bracex.expand('{a..k..5}', limit=2)
def test_expansion_char_reverse_limt_expand(self): """Test expansion character reversed limit with `expand`.""" self.assertEqual(len(bracex.expand('{k..a}', limit=11)), 11) with self.assertRaises(bracex.ExpansionLimitException): bracex.expand('{k..a}', limit=10)