sahib / rmlint

Extremely fast tool to remove duplicates and other lint from your filesystem
http://rmlint.rtfd.org
GNU General Public License v3.0
1.85k stars 128 forks source link

test_sorting.test_regex_multiple_matches and test_sorting.test_sort_by_regex fail with certain values for RM_TS_DIR #630

Closed sbraz closed 10 months ago

sbraz commented 10 months ago

Hi again, With the latest 2.10.2 release, two tests fail for some values of RM_TS_DIR, apparently it only happens when certain digits are present in the path. To reproduce:

$ RM_TS_DIR=/tmp/01/ nosetests -v tests/test_options/test_sorting.py
test_sorting.test_sorting ... ok
test_sorting.keep_testdir ... ok
test_sorting.create_testdir ... ok
test_sorting.test_sort_by_outlyer ... ok
test_sorting.test_sort_by_outlyer_hardcore ... ok
test_sorting.test_sort_by_regex ... FAIL
test_sorting.test_sort_by_regex_bad_input ... ok
test_sorting.test_regex_multiple_matches ... FAIL

======================================================================
FAIL: test_sorting.test_sort_by_regex
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python3.11/site-packages/nose/case.py", line 197, in runTest
    self.test(*self.arg)
  File "/tmp/build/rmlint/tests/test_options/test_sorting.py", line 169, in test_sort_by_regex
    assert paths[1].endswith('d')
AssertionError

======================================================================
FAIL: test_sorting.test_regex_multiple_matches
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python3.11/site-packages/nose/case.py", line 197, in runTest
    self.test(*self.arg)
  File "/tmp/build/rmlint/tests/test_options/test_sorting.py", line 221, in test_regex_multiple_matches
    assert [e['path'] for e in data] == [os.path.join(TESTDIR_NAME, p) for p in paths]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError

----------------------------------------------------------------------
Ran 8 tests in 36.428s

FAILED (failures=2)

Additional info can be obtained by running the desired tests with pytest:

_______________________________________________________________________________________________ test_sort_by_regex ________________________________________________________________________________________________                                                            

    @with_setup(usual_setup_func, usual_teardown_func)                                                                                                                                                                                                                         
    def test_sort_by_regex():                                                                                                                                                                                                                                                  
        create_file('xxx', 'aaaa')                                                                                                                                                                                                                                             
        create_file('xxx', 'aaab')                                                                                                                                                                                                                                             
        create_file('xxx', 'b')                                                                                                                                                                                                                                                
        create_file('xxx', 'c')                                                                                                                                                                                                                                                
        create_file('xxx', '1/c')                                                                                                                                                                                                                                              
        create_file('xxx', 'd')                                                                                                                                                                                                                                                

        head, *data, footer = run_rmlint("-S 'r<1/c>x<d$>a'")                                                                                                                                                                                                                  

        paths = [p['path'] for p in data]                                                                                                                                                                                                                                      

        assert paths[0].endswith('1/c')                                                                                                                                                                                                                                        
>       assert paths[1].endswith('d')                                                                                                                                                                                                                                          
E       AssertionError: assert False                                                                                                                                                                                                                                           
E        +  where False = <built-in method endswith of str object at 0x7ff94e770df0>('d')                                                                                                                                                                                      
E        +    where <built-in method endswith of str object at 0x7ff94e770df0> = '/tmp/01/1/c'.endswith                                                                                                                                                                        

tests/test_options/test_sorting.py:169: AssertionError                                                                                                                                                                                                                         
___________________________________________________________________________________________ test_regex_multiple_matches ___________________________________________________________________________________________                                                            

    @with_setup(usual_setup_func, usual_teardown_func)                                                                                                                                                                                                                         
    def test_regex_multiple_matches():                                                                                                                                                                                                                                         
        paths = [                                                                                                                                                                                                                                                              
            '1/a', '1/a2', '1/b',                                                                                                                                                                                                                                              
            '2/a', '2/a2', '2/b',                                                                                                                                                                                                                                              
        ]                                                                                                                                                                                                                                                                      
        for path in reversed(paths):                                                                     
            create_file('xxx', path)                                                                                                                                                                               

        # when multiple paths matched a regex, rmlint would not try the next criterion                                                                                                                             
        # check multiple times because sort order was inconsistent before the fix                                                      
        for _ in range(3):     
            head, *data, foot = run_rmlint("-S 'r<1>x<a>l'")                                             
            assert len(data) == len(paths)                                                                                                                                                                         
>           assert [e['path'] for e in data] == [os.path.join(TESTDIR_NAME, p) for p in paths]                                         
E           AssertionError: assert ['/tmp/01/1/a', '/tmp/01/2/a', '/tmp/01/1/a2', '/tmp/01/2/a2', '/tmp/01/1/b', '/tmp/01/2/b'] == ['/tmp/01/1/a', '/tmp/01/1/a2', '/tmp/01/1/b', '/tmp/01/2/a', '/tmp/01/2/a2', '/tmp/01/2/b']
E             At index 1 diff: '/tmp/01/2/a' != '/tmp/01/1/a2'                                                                         
E             Full diff:                                                                                 
E               [                                                                                                                                                                                                  
E                '/tmp/01/1/a',                                                                                                                                                                                    
E             +  '/tmp/01/2/a',                                                                          
E                '/tmp/01/1/a2',                 
E             +  '/tmp/01/2/a2',                                                                         
E                '/tmp/01/1/b',                                                                          
E             -  '/tmp/01/2/a',                                                                                                                                                                                    
E             -  '/tmp/01/2/a2',                                                                                                                                                                                   
E                '/tmp/01/2/b',                                                                                                                                                                                    
E               ]                                                                                        

tests/test_options/test_sorting.py:221: AssertionError                                                   
cebtenzzre commented 10 months ago

Does this work better?

--- a/tests/test_options/test_sorting.py
+++ b/tests/test_options/test_sorting.py
@@ -158,15 +158,15 @@ def test_sort_by_regex():
     create_file('xxx', 'aaab')
     create_file('xxx', 'b')
     create_file('xxx', 'c')
-    create_file('xxx', '1/c')
-    create_file('xxx', 'd')
+    create_file('xxx', 'd/e')
+    create_file('xxx', 'f')

-    head, *data, footer = run_rmlint("-S 'r<1/c>x<d$>a'")
+    head, *data, footer = run_rmlint("-S 'r<d/e>x<f$>a'")

     paths = [p['path'] for p in data]

-    assert paths[0].endswith('1/c')
-    assert paths[1].endswith('d')
+    assert paths[0].endswith('d/e')
+    assert paths[1].endswith('f')
     assert paths[2].endswith('aaaa')
     assert paths[3].endswith('aaab')
     assert paths[4].endswith('b')
sbraz commented 10 months ago

Yes, it fixes test_sort_by_regex. The other test probably needs a different fix.

cebtenzzre commented 10 months ago

Try this:

diff --git a/tests/test_options/test_sorting.py b/tests/test_options/test_sorting.py
index e5ac2c66..45774a19 100644
--- a/tests/test_options/test_sorting.py
+++ b/tests/test_options/test_sorting.py
@@ -206,16 +206,16 @@ def test_sort_by_regex_bad_input():
 # regression test for GitHub issue #484
 @with_setup(usual_setup_func, usual_teardown_func)
 def test_regex_multiple_matches():
-    paths = [
-        '1/a', '1/a2', '1/b',
-        '2/a', '2/a2', '2/b',
-    ]
+    paths = [os.path.join(dname, bname)
+             for dname in ['unique_1', 'unique_2']
+             for bname in ['a', 'a2', 'b']]
+
     for path in reversed(paths):
         create_file('xxx', path)

     # when multiple paths matched a regex, rmlint would not try the next criterion
     # check multiple times because sort order was inconsistent before the fix
     for _ in range(3):
-        head, *data, foot = run_rmlint("-S 'r<1>x<a>l'")
+        head, *data, foot = run_rmlint("-S 'r<unique_1>x<a>l'")
         assert len(data) == len(paths)
         assert [e['path'] for e in data] == [os.path.join(TESTDIR_NAME, p) for p in paths]
sbraz commented 10 months ago

Yep, with both patches, both formerly failing tests now pass. I'll try to re-run the full test suite now to see if anything else is causing issues.

EDIT: all good

Ran 265 tests in 77.123s

OK (SKIP=11)