def main(self): # TODO: write unit test location = self.args[1] pattern = self.args[2] if self.check_attribute(location, AttributeType.PATH) == AttributeType.FOLDER: if len(self.args) >= 4: print( self._print_results( Regex.match_files(location, pattern, self.args[3]))) else: print(self._print_results(Regex.match_files(location, pattern))) else: print(Regex.match_file(location, pattern))
def test_replace_files(self): Regex.replace_files('TestResources', "[is]{2}\s*\w+", "is geen") self.assertTrue( Regex.match_file('TestResources\\RegexMatchTest.txt', "is geen")) Regex.replace_files("TestResources", "[is]{2}\s*\w+", "is een") self.assertTrue( Regex.match_file('TestResources\\RegexMatchTest.txt', "is een"))
def test_match_string(self): self.assertTrue(Regex.match_string("dit is een tekst", "[is]{2}\s*\w+")) self.assertFalse( Regex.match_string("dit is een tekst", "^[is]{2}\s*\w+$"))
def test_replace_files_with_filter(self): Regex.replace_files('TestResources', "[is]{2}\s*\w+", "is geen", "cant_match_anything") self.assertFalse( Regex.match_file('TestResources\\RegexMatchTest.txt', "is geen"))
def test_replace_string(self): self.assertEqual( Regex.replace_string("dit is een tekst", "[is]{2}\s*\w+", "is geen"), "dit is geen tekst")
def test_match_files(self): self.assertEqual(Regex.match_files("TestResources", "[is]{2}\s*\w+"), ['TestResources\\RegexMatchTest.txt'])
def test_match_file(self): self.assertTrue(Regex.match_file("TestRegex.py", "[is]{2}\s*\w+")) self.assertFalse(Regex.match_file("TestRegex.py", "^[is]{2}\s*\w+$"))