Beispiel #1
0
 def testPatternMatch(self):
     '''Test snake match's pattern match facility'''
     res = extract_pattern('{a}-{b}.txt', ['file-1.txt', 'file-ab.txt'])
     self.assertEqual(res['a'], ['file', 'file'])
     self.assertEqual(res['b'], ['1', 'ab'])
     res = extract_pattern('{a}-{b}.txt', ['file--ab--cd.txt'])
     self.assertEqual(res['a'], ['file--ab-'])
     self.assertEqual(res['b'], ['cd'])
     res = extract_pattern('{path}/{to}/{file}.txt', ['/tmp//1.txt'])
     self.assertEqual(res['path'], [None])
     self.assertEqual(res['to'], [None])
     self.assertEqual(res['file'], [None])
     res = extract_pattern('{path}/{to}/{file}.txt',
                           ['/tmp/test/1.txt.txt'])
     self.assertEqual(res['path'], ['/tmp'])
     self.assertEqual(res['to'], ['test'])
     self.assertEqual(res['file'], ['1.txt'])
     # expand_pattern
     env.sos_dict = WorkflowDict({
         'os': os,
         'a': 100,
         'b': 'file name',
         'c': ['file1', 'file2', 'file 3'],
         'd': {'a': 'file1', 'b': 'file2'},
     })
     self.assertEqual(expand_pattern('{b}.txt'), ['file name.txt'])
     self.assertEqual(expand_pattern('{c}.txt'), [
                      'file1.txt', 'file2.txt', 'file 3.txt'])
     self.assertEqual(expand_pattern('{a}_{c}.txt'), [
                      '100_file1.txt', '100_file2.txt', '100_file 3.txt'])
Beispiel #2
0
 def testPatternMatch(self):
     """Test snake match's pattern match facility"""
     res = extract_pattern("{a}-{b}.txt", ["file-1.txt", "file-ab.txt"])
     self.assertEqual(res["a"], ["file", "file"])
     self.assertEqual(res["b"], ["1", "ab"])
     res = extract_pattern("{a}-{b}.txt", ["file--ab--cd.txt"])
     self.assertEqual(res["a"], ["file--ab-"])
     self.assertEqual(res["b"], ["cd"])
     res = extract_pattern("{path}/{to}/{file}.txt", ["/tmp//1.txt"])
     self.assertEqual(res["path"], [None])
     self.assertEqual(res["to"], [None])
     self.assertEqual(res["file"], [None])
     res = extract_pattern("{path}/{to}/{file}.txt", ["/tmp/test/1.txt.txt"])
     self.assertEqual(res["path"], ["/tmp"])
     self.assertEqual(res["to"], ["test"])
     self.assertEqual(res["file"], ["1.txt"])
     # expand_pattern
     env.sos_dict = WorkflowDict(
         {"os": os, "a": 100, "b": "file name", "c": ["file1", "file2", "file 3"], "d": {"a": "file1", "b": "file2"}}
     )
     self.assertEqual(expand_pattern("{b}.txt"), ["file name.txt"])
     self.assertEqual(expand_pattern("{c}.txt"), ["file1.txt", "file2.txt", "file 3.txt"])
     self.assertEqual(expand_pattern("{a}_{c}.txt"), ["100_file1.txt", "100_file2.txt", "100_file 3.txt"])