Exemplo n.º 1
0
 def test_variables_sub(self):
     one = Matcher('{base}/{loc}/*', {'base': 'ONE_BASE'})
     other = Matcher('{base}/somewhere/*', {'base': 'OTHER_BASE'})
     self.assertEqual(one.sub(other, 'ONE_BASE/ab-CD/special'),
                      'OTHER_BASE/somewhere/special')
     one = Matcher('{base}/{loc}/*', {'base': 'ONE_BASE'}, encoding='utf-8')
     other = Matcher('{base}/somewhere/*', {'base': 'OTHER_BASE'},
                     encoding='utf-8')
     self.assertEqual(one.sub(other, b'ONE_BASE/ab-CD/special'),
                      b'OTHER_BASE/somewhere/special')
Exemplo n.º 2
0
 def test_variables_sub(self):
     one = Matcher('{base}/{loc}/*', {'base': 'ONE_BASE'})
     other = Matcher('{base}/somewhere/*', {'base': 'OTHER_BASE'})
     self.assertEqual(
         one.sub(other, 'ONE_BASE/ab-CD/special'),
         'OTHER_BASE/somewhere/special'
     )
Exemplo n.º 3
0
 def test_matcher(self):
     one = Matcher('foo/*')
     self.assertTrue(one.match('foo/baz'))
     self.assertFalse(one.match('foo/baz/qux'))
     other = Matcher('bar/*')
     self.assertTrue(other.match('bar/baz'))
     self.assertFalse(other.match('bar/baz/qux'))
     self.assertEqual(one.sub(other, 'foo/baz'), 'bar/baz')
     self.assertIsNone(one.sub(other, 'bar/baz'))
     one = Matcher('foo/**')
     self.assertTrue(one.match('foo/baz'))
     self.assertTrue(one.match('foo/baz/qux'))
     other = Matcher('bar/**')
     self.assertTrue(other.match('bar/baz'))
     self.assertTrue(other.match('bar/baz/qux'))
     self.assertEqual(one.sub(other, 'foo/baz'), 'bar/baz')
     self.assertEqual(one.sub(other, 'foo/baz/qux'), 'bar/baz/qux')
     one = Matcher('foo/*/one/**')
     self.assertTrue(one.match('foo/baz/one/qux'))
     self.assertFalse(one.match('foo/baz/bez/one/qux'))
     other = Matcher('bar/*/other/**')
     self.assertTrue(other.match('bar/baz/other/qux'))
     self.assertFalse(other.match('bar/baz/bez/other/qux'))
     self.assertEqual(one.sub(other, 'foo/baz/one/qux'),
                      'bar/baz/other/qux')
     self.assertEqual(one.sub(other, 'foo/baz/one/qux/zzz'),
                      'bar/baz/other/qux/zzz')
     self.assertIsNone(one.sub(other, 'foo/baz/bez/one/qux'))
     one = Matcher('foo/**/bar/**')
     self.assertTrue(one.match('foo/bar/baz.qux'))
     self.assertTrue(one.match('foo/tender/bar/baz.qux'))
     self.assertFalse(one.match('foo/nobar/baz.qux'))
     self.assertFalse(one.match('foo/tender/bar'))
Exemplo n.º 4
0
 def test_copy(self):
     one = Matcher('{base}/{loc}/*', {
         'base': 'ONE_BASE',
         'generic': 'keep'
     })
     other = Matcher(one, {'base': 'OTHER_BASE'})
     self.assertEqual(one.sub(other, 'ONE_BASE/ab-CD/special'),
                      'OTHER_BASE/ab-CD/special')
     self.assertDictEqual(one.env, {
         'base': ['ONE_BASE'],
         'generic': ['keep']
     })
     self.assertDictEqual(other.env, {
         'base': ['OTHER_BASE'],
         'generic': ['keep']
     })
Exemplo n.º 5
0
 def test_copy(self):
     one = Matcher('{base}/{loc}/*', {
         'base': 'ONE_BASE',
         'generic': 'keep'
     })
     other = Matcher(one, {'base': 'OTHER_BASE'})
     self.assertEqual(
         one.sub(other, 'ONE_BASE/ab-CD/special'),
         'OTHER_BASE/ab-CD/special'
     )
     self.assertDictEqual(
         one.env,
         {
             'base': ['ONE_BASE'],
             'generic': ['keep']
         }
     )
     self.assertDictEqual(
         other.env,
         {
             'base': ['OTHER_BASE'],
             'generic': ['keep']
         }
     )
Exemplo n.º 6
0
 def test_encoded_matcher(self):
     one = Matcher('foo/*', encoding='utf-8')
     self.assertTrue(one.match(b'foo/bar'))
     other = Matcher('bar/*', encoding='utf-8')
     self.assertEqual(one.sub(other, b'foo/baz'), b'bar/baz')