testing deltatar filtering regular expressions
authorEduardo Robles Elvira <edulix@wadobo.com>
Fri, 2 Aug 2013 08:18:19 +0000 (10:18 +0200)
committerEduardo Robles Elvira <edulix@wadobo.com>
Fri, 2 Aug 2013 08:18:19 +0000 (10:18 +0200)
testing/test_deltatar.py

index b75694f..835405a 100644 (file)
@@ -17,6 +17,7 @@
 # Author: Eduardo Robles Elvira <edulix@wadobo.com>
 
 import os
+import re
 import shutil
 import logging
 import binascii
@@ -553,6 +554,45 @@ class DeltaTarTest(BaseTest):
                 '/test/test2'
             ])
 
+    def test_deltatar_filter_path_regexp(self):
+        '''
+        Test specifically the deltatar.filter_path function with regular
+        expressions
+        '''
+        included_files = [
+            re.compile('^/test/(hola|caracola/caracolero)(|/.*)$'),
+            re.compile('^/yes$'),
+            '/testing'
+        ]
+        excluded_files = [
+            re.compile('^/testing/in_the'),
+        ]
+        deltatar = DeltaTar(mode=self.MODE, included_files=included_files,
+                            excluded_files=excluded_files)
+
+        # assert valid and invalid paths
+        assert deltatar.filter_path('/test/hola')
+        assert deltatar.filter_path('/test/hola/any/thing')
+        assert deltatar.filter_path('/test/caracola/caracolero')
+        assert deltatar.filter_path('/test/caracola/caracolero/yeah')
+        assert deltatar.filter_path('/test/caracola/caracolero/whatever/aa')
+        assert deltatar.filter_path('/yes')
+        assert deltatar.filter_path('/testing')
+        assert deltatar.filter_path('/testing/yes')
+        assert deltatar.filter_path('/testing/in_th')
+
+        assert not deltatar.filter_path('/something')
+        assert not deltatar.filter_path('/other/thing')
+        assert not deltatar.filter_path('/test_ing')
+        assert not deltatar.filter_path('/test/hola_lala')
+        assert not deltatar.filter_path('/test/agur')
+        assert not deltatar.filter_path('/testing_something')
+        assert not deltatar.filter_path('/yeso')
+        assert not deltatar.filter_path('/yes/o')
+        assert not deltatar.filter_path('/yes_o')
+        assert not deltatar.filter_path('/testing/in_the')
+        assert not deltatar.filter_path('/testing/in_the_field')
+        assert not deltatar.filter_path('/testing/in_the/field')
 
 
 class DeltaTar2Test(DeltaTarTest):