Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Low probability failure in test/test_extras/test_infixowl/test_restriction.py::test_restriction_str_and_hash #2030

Closed
aucampia opened this issue Jul 17, 2022 · 2 comments · Fixed by #2033
Labels
bug Something isn't working

Comments

@aucampia
Copy link
Member

aucampia commented Jul 17, 2022

Failures can be seen in these GitHub actions runs:

  ________________________ test_restriction_str_and_hash _________________________
  
  graph = <Graph identifier=http://example.org/vocab/context0 (<class 'rdflib.graph.Graph'>)>
  
      def test_restriction_str_and_hash(graph):
  
          r1 = (
              (Property(EXNS.someProp, baseType=OWL.DatatypeProperty))
              @ some
              @ (Class(EXNS.Foo))
          )
  
          assert str(r1) == "( ex:someProp SOME ex:Foo )"
  
          sg = Graph()
          sg.bind("ex", EXNS)
  
          r1.serialize(sg)
  
          assert r1.isPrimitive() is False
  >       assert len(str(r1.__hash__())) > 17
  E       AssertionError: assert 16 > 17
  E        +  where 16 = len('6777726393218724')
  E        +    where '6777726393218724' = str(6777726393218724)
  E        +      where 6777726393218724 = <bound method Restriction.__hash__ of ( ex:someProp SOME ex:Foo )>()
  E        +        where <bound method Restriction.__hash__ of ( ex:someProp SOME ex:Foo )> = ( ex:someProp SOME ex:Foo ).__hash__
  
  test/test_extras/test_infixowl/test_restriction.py:39: AssertionError

This command seems to reproduce this failure at least once, I got 3 failures on my last run:

for (( index=0; index<1000; index++ ));
do
  task test -- test/test_extras/test_infixowl/test_restriction.py::test_restriction_str_and_hash;
done

I'm guessing this is somehow related to python hash value which by default will be different for different instances.

CC: @gjhiggins

@aucampia
Copy link
Member Author

Output from my computer:

============================================================================ test session starts ============================================================================
platform linux -- Python 3.10.5, pytest-7.1.2, pluggy-1.0.0
rootdir: /home/iwana/sw/d/github.com/iafork/rdflib.reviews, configfile: pyproject.toml
plugins: cov-3.0.0, repeat-0.9.1
collected 1 item                                                                                                                                                            

test/test_extras/test_infixowl/test_restriction.py F                                                                                                                  [100%]

================================================================================= FAILURES ==================================================================================
_______________________________________________________________________ test_restriction_str_and_hash _______________________________________________________________________

graph = <Graph identifier=http://example.org/vocab/context0 (<class 'rdflib.graph.Graph'>)>

    def test_restriction_str_and_hash(graph):
    
        r1 = (
            (Property(EXNS.someProp, baseType=OWL.DatatypeProperty))
            @ some
            @ (Class(EXNS.Foo))
        )
    
        assert str(r1) == "( ex:someProp SOME ex:Foo )"
    
        sg = Graph()
        sg.bind("ex", EXNS)
    
        r1.serialize(sg)
    
        assert r1.isPrimitive() is False
>       assert len(str(r1.__hash__())) > 17
E       AssertionError: assert 17 > 17
E        +  where 17 = len('56610119568990127')
E        +    where '56610119568990127' = str(56610119568990127)
E        +      where 56610119568990127 = <bound method Restriction.__hash__ of ( ex:someProp SOME ex:Foo )>()
E        +        where <bound method Restriction.__hash__ of ( ex:someProp SOME ex:Foo )> = ( ex:someProp SOME ex:Foo ).__hash__

test/test_extras/test_infixowl/test_restriction.py:39: AssertionError
========================================================================== short test summary info ==========================================================================
FAILED test/test_extras/test_infixowl/test_restriction.py::test_restriction_str_and_hash - AssertionError: assert 17 > 17
============================================================================= 1 failed in 0.15s =============================================================================
task: Failed to run task "test": exit status 1

@ghost
Copy link

ghost commented Jul 17, 2022

It's my failure, I'm just guessing at how to test the result, hence the relative weakness of the length test - largely because I was merely focused on coverage, I assume __hash__() works.

@ghost ghost mentioned this issue Jul 17, 2022
8 tasks
@aucampia aucampia added the bug Something isn't working label Jul 18, 2022
@aucampia aucampia linked a pull request Jul 18, 2022 that will close this issue
8 tasks
aucampia pushed a commit that referenced this issue Jul 18, 2022
Maintenance-positive changes recommended by
[flake8-bugbear](https://pypi.org/project/flake8-bugbear/), mostly explicitly
indicating unused loop variables with a prefixing underscore (it identified one
case where _none_ of the loop variables were being used) and a couple of
don't-use-mutable-objects-as-args instances.

1. Added leading underscore to unused loop variables, removed mutable objects
   from args, (replacing with None and then performing an explicit “if None”
   assignment in the body of the method).

2. Swapped out an excessively weak, coverage-motivated length test of __hash__()
   (which was causing intermittent test failures) for an equality test of two
   runs, fixes issue #2030
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant