1818log .debug ("module loaded" )
1919
2020
21+ # Some of these are redundant due to the more comprehensive tests
22+ # later on, but it can't hurt to have them here
2123@pytest .mark .parametrize (
2224 "cond" ,
2325 [
@@ -111,6 +113,7 @@ def test_conditions_prefilter(cond, expected):
111113@pytest .mark .parametrize (
112114 ("matcher" , "item" ),
113115 [
116+ # Patterns
114117 ("arch" , Bunch (name = "arch" )),
115118 ("name=arch" , Bunch (name = "arch" )),
116119 ("name=/arch/i" , Bunch (name = "ARCH" )),
@@ -122,6 +125,7 @@ def test_conditions_prefilter(cond, expected):
122125 ("name={{d.alias}}*" , Bunch (name = "ubuntu-server" , alias = "ubuntu" )),
123126 ("name=rtör*" , Bunch (name = "rtörrent" )),
124127 ("name=arch*" , Bunch (name = "arch-linux" )),
128+ ("name=arch* is_complete=yes" , Bunch (name = "arch-linux" , is_complete = True )),
125129 ("name=arch*" , Bunch (name = "arch linux" )),
126130 ('name="arch *"' , Bunch (name = "arch linux" )),
127131 ("arch*" , Bunch (name = "arch linux" )),
@@ -136,11 +140,14 @@ def test_conditions_prefilter(cond, expected):
136140 (r"/s\d+e\d+/i" , Bunch (name = "Test.S03E04.mkv" )),
137141 ('message=""' , Bunch (message = "" )),
138142 ('message!=""' , Bunch (message = "Oh no!" )),
143+ # Booleans
139144 ("is_complete=no" , Bunch (is_complete = False )),
145+ # Numbers
140146 ("ratio>2" , Bunch (ratio = 5.0 )),
141147 ("ratio>2 ratio<6.0" , Bunch (ratio = 5.0 )),
142148 ("size>1G" , Bunch (size = 2 * (1024 ** 3 ))),
143149 ("size>1G" , Bunch (size = 2 * (1024 ** 3 ))),
150+ # Datetimes
144151 ("leechtime>1h" , Bunch (leechtime = 60 * 60 * 2 )),
145152 ("completed>2h" , Bunch (completed = time .time () - (60 * 60 * 2 ))),
146153 ("completed<1h" , Bunch (completed = time .time () - 1 )),
@@ -150,6 +157,7 @@ def test_conditions_prefilter(cond, expected):
150157 ("completed>1990-09-21" , Bunch (completed = time .time ())),
151158 ("completed>1990-09-21T12:00" , Bunch (completed = time .time ())),
152159 ("completed>1990-09-21T12:00:00" , Bunch (completed = time .time ())),
160+ # Tags
153161 ("tagged=notest" , Bunch (tagged = ["test" , "notest" ])),
154162 ("tagged=:" , Bunch (tagged = [])),
155163 ('tagged=""' , Bunch (tagged = [])),
@@ -176,13 +184,15 @@ def test_matcher(matcher, item):
176184 [
177185 ("name=arch" , Bunch (name = "ARCH" )),
178186 ("name=ARCH" , Bunch (name = "arch" )),
187+ ("name=ARCH name=arch" , Bunch (name = "ARCH" )),
179188 ("name=arch" , Bunch (name = "asdfsafad" )),
180189 ("name!=arch*" , Bunch (name = "arch-linux" )),
181190 ("name!=/arch$/" , Bunch (name = "base-arch" )),
182191 ("is_complete=yes" , Bunch (is_complete = False )),
183192 ("ratio<2" , Bunch (ratio = 5.0 )),
184193 ("size<1G" , Bunch (size = 2 * (1024 ** 3 ))),
185194 ("leechtime<1h" , Bunch (leechtime = 60 * 60 * 2 )),
195+ ("leechtime<1h is_complete=yes" , Bunch (leechtime = 60 * 60 * 2 , is_complete = False )),
186196 ("completed>1h" , Bunch (completed = time .time () - 1 )),
187197 ("completed<09/21/1990" , Bunch (completed = time .time ())),
188198 ("tagged=:test" , Bunch (tagged = ["test" , "notest" ])),
@@ -202,30 +212,37 @@ def test_matcher_fail(matcher, item):
202212 (["name=arch" ], 'string.contains_i=$d.name=,"arch"' ),
203213 ('name="arch linux"' , 'string.contains_i=$d.name=,"arch linux"' ),
204214 ("name=/arch/" , 'string.contains_i=$d.name=,"arch"' ),
215+ # Avoid getting trapped in trying to prefilter strings inside
216+ # regex logic
205217 ("name=/(arch|foo)k+/" , 'string.contains_i=$d.name=,"k"' ),
218+ # Too complex of a regex to properly clean
206219 ("name=/((arch|ubuntu)|foo)k+/" , '' ),
207220 ("name=ARCH" , 'string.contains_i=$d.name=,"ARCH"' ),
208- ( "size<1G" , "less=d.size_bytes=,value=1073741824" ),
221+ # Booleans
209222 ("is_complete=no" , "equal=d.complete=,value=0" ),
210223 ("is_private=yes" , "equal=d.is_private=,value=1" ),
224+ # Numbers
225+ ("size<1G" , "less=d.size_bytes=,value=1073741824" ),
211226 ("prio=1" , "equal=value=$d.priority=,value=1" ),
212227 ("ratio>1" , "greater=value=$d.ratio=,value=1000" ),
213228 ("ratio>=1" , "greater=value=$d.ratio=,value=999" ),
214229 ("ratio<1" , "less=value=$d.ratio=,value=1000" ),
215230 ("ratio<=1" , "less=value=$d.ratio=,value=1001" ),
216231 ("prio=1" , "equal=value=$d.priority=,value=1" ),
232+ # Tags
217233 ("tagged=foo" , 'string.contains_i=$d.custom=tags,"foo"' ),
218234 ("tagged=:foo" , 'string.contains_i=$d.custom=tags,"foo"' ),
219235 ("tagged=:" , "equal=d.custom=tags,cat=" ),
220236 ("tagged!=:" , 'not="$equal=d.custom=tags,cat="' ),
221237 ("tagged!=:foo" , 'not="$string.contains_i=$d.custom=tags,\\ "foo\\ ""' ),
222238 ("tagged!=foo" , 'not="$string.contains_i=$d.custom=tags,\\ "foo\\ ""' ),
239+ ("views=test" , 'string.contains_i=$d.views=,"test"' ),
240+ # Dates
223241 (
224242 "completed>1990-09-21" ,
225243 "greater=value=$d.custom=tm_completed,value="
226244 + str (int (time .mktime (time .strptime ("1990-09-20" , "%Y-%m-%d" )))),
227245 ),
228- ("views=test" , 'string.contains_i=$d.views=,"test"' ),
229246 # Example of a seemingly easy query that can't be prefiltered
230247 ("done>0" , "" ),
231248 ],
0 commit comments