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

test_ordering (libcst.metadata.tests.test_scope_provider.ScopeProviderTest) fails on i586 and Python 3.6 #442

Closed
mcepl opened this issue Jan 3, 2021 · 4 comments · Fixed by #650

Comments

@mcepl
Copy link

mcepl commented Jan 3, 2021

When packaging LibCST for OpenSUSE the testsuite fails repeatedly on i586 with Python 3.6:

[  122s] ======================================================================
[  122s] FAIL: test_ordering (libcst.metadata.tests.test_scope_provider.ScopeProviderTest)
[  122s] ----------------------------------------------------------------------
[  122s] Traceback (most recent call last):
[  122s]   File "/home/abuild/rpmbuild/BUILD/libcst-0.3.14/libcst/metadata/tests/test_scope_provider.py", line 1380, in test_ordering
[  122s]     self.assertEqual(x.value, global_refs[0].node)
[  122s] AssertionError: Name(
[  122s]     value='b',
[  122s]     lpar=[],
[  122s]     rpar=[],
[  122s] ) != Name(
[  122s]     value='b',
[  122s]     lpar=[],
[  122s]     rpar=[],
[  122s] )

Complete build log with all details and versions of packages

@bnavigator
Copy link

Additional info: The above build log was with 0.3.14, but the same error occurs on 0.3.16.

@jimmylai
Copy link
Contributor

It looks like the assertion took two Name objects looked the same but they were different one.
There are multiple Name("b") in the test case.
https://github.com/Instagram/LibCST/blob/master/libcst/metadata/tests/test_scope_provider.py#L1370-L1376

Can you add some statements to print the id of those different Name("b")?
That can help us understand what global_refs[0].node refers to in your test environment.

@bnavigator
Copy link

bnavigator commented Jan 12, 2021

And how would I get the "Id"? .value is "b" for both.

Here is a pickle dump string:

        import pickle
        print("Debug:")
        print("x.value = ")
        print(pickle.dumps(x.value))
        print("global_refs[0].node = ")
        print(pickle.dumps(global_refs[0]))
        self.assertEqual(x.value, global_refs[0].node)
abuild@greinerT450s:~/rpmbuild/BUILD/libcst-0.3.16> python3.6 -m unittest -v libcst.metadata.tests.test_scope_provider.ScopeProviderTest.test_ordering
test_ordering (libcst.metadata.tests.test_scope_provider.ScopeProviderTest) ... Debug:
x.value = 
b'\x80\x03clibcst._nodes.expression\nName\nq\x00)\x81q\x01}q\x02(X\x05\x00\x00\x00valueq\x03X\x01\x00\x00\x00bq\x04X\x04\x00\x00\x00lparq\x05)X\x04\x00\x00\x00rparq\x06)ub.'
global_refs[0].node = 
b'\x80\x03clibcst.metadata.scope_provider\nAccess\nq\x00)\x81q\x01}q\x02(X\x04\x00\x00\x00nodeq\x03clibcst._nodes.expression\nName\nq\x04)\x81q\x05}q\x06(X\x05\x00\x00\x00valueq\x07X\x01\x00\x00\x00bq\x08X\x04\x00\x00\x00lparq\t)X\x04\x00\x00\x00rparq\n)ubX\x05\x00\x00\x00scopeq\x0bclibcst.metadata.scope_provider\nClassScope\nq\x0c)\x81q\r}q\x0e(X\x06\x00\x00\x00parentq\x0fclibcst.metadata.scope_provider\nGlobalScope\nq\x10)\x81q\x11}q\x12(X\x07\x00\x00\x00globalsq\x13h\x11h\x0fh\x11X\x0c\x00\x00\x00_assignmentsq\x14ccollections\ndefaultdict\nq\x15cbuiltins\nset\nq\x16\x85q\x17Rq\x18(h\x08h\x16]q\x19clibcst.metadata.scope_provider\nAssignment\nq\x1a)\x81q\x1b}q\x1c(h\x03clibcst._nodes.statement\nImportFrom\nq\x1d)\x81q\x1e}q\x1f(X\x06\x00\x00\x00moduleq h\x04)\x81q!}q"(h\x07X\x01\x00\x00\x00aq#h\t)h\n)ubX\x05\x00\x00\x00namesq$clibcst._nodes.statement\nImportAlias\nq%)\x81q&}q\'(X\x04\x00\x00\x00nameq(h\x04)\x81q)}q*(h\x07h\x08h\t)h\n)ubX\x06\x00\x00\x00asnameq+NX\x05\x00\x00\x00commaq,clibcst._maybe_sentinel\nMaybeSentinel\nq-K\x01\x85q.Rq/ub\x85q0X\x08\x00\x00\x00relativeq1)h\tNh\nNX\t\x00\x00\x00semicolonq2h/X\x15\x00\x00\x00whitespace_after_fromq3clibcst._nodes.whitespace\nSimpleWhitespace\nq4)\x81q5}q6h\x07X\x01\x00\x00\x00 q7sbX\x18\x00\x00\x00whitespace_before_importq8h4)\x81q9}q:h\x07h7sbX\x17\x00\x00\x00whitespace_after_importq;h4)\x81q<}q=h\x07h7sbubX\x12\x00\x00\x00_Assignment__indexq>K\x00h(h\x08h\x0bh\x11X\x19\x00\x00\x00_BaseAssignment__accessesq?h\x16]q@(h\x01h\x00)\x81qA}qB(h\x03h\x04)\x81qC}qD(h\x07h\x08h\t)h\n)ubh\x0bh\rX\r\x00\x00\x00is_annotationqE\x89X\x0c\x00\x00\x00is_type_hintqF\x89X\x14\x00\x00\x00_Access__assignmentsqGh\x16]qHh\x1ba\x85qIRqJX\x0e\x00\x00\x00_Access__indexqKK\x00ube\x85qLRqMuba\x85qNRqOX\x01\x00\x00\x00XqPh\x16]qQh\x1a)\x81qR}qS(h\x03clibcst._nodes.statement\nClassDef\nqT)\x81qU}qV(h(h\x04)\x81qW}qX(h\x07hPh\t)h\n)ubX\x04\x00\x00\x00bodyqYclibcst._nodes.statement\nIndentedBlock\nqZ)\x81q[}q\\(hYclibcst._nodes.statement\nSimpleStatementLine\nq])\x81q^}q_(hYclibcst._nodes.statement\nAssign\nq`)\x81qa}qb(X\x07\x00\x00\x00targetsqcclibcst._nodes.statement\nAssignTarget\nqd)\x81qe}qf(X\x06\x00\x00\x00targetqgh\x04)\x81qh}qi(h\x07X\x01\x00\x00\x00xqjh\t)h\n)ubX\x17\x00\x00\x00whitespace_before_equalqkh4)\x81ql}qmh\x07h7sbX\x16\x00\x00\x00whitespace_after_equalqnh4)\x81qo}qph\x07h7sbub\x85qqh\x07hCh2h/ub\x85qrX\r\x00\x00\x00leading_linesqs)X\x13\x00\x00\x00trailing_whitespaceqtclibcst._nodes.whitespace\nTrailingWhitespace\nqu)\x81qv}qw(X\n\x00\x00\x00whitespaceqxh4)\x81qy}qzh\x07X\x00\x00\x00\x00q{sbX\x07\x00\x00\x00commentq|NX\x07\x00\x00\x00newlineq}clibcst._nodes.whitespace\nNewline\nq~)\x81q\x7f}q\x80h\x07Nsbububh])\x81q\x81}q\x82(hYh`)\x81q\x83}q\x84(hchd)\x81q\x85}q\x86(hgh\x04)\x81q\x87}q\x88(h\x07h\x08h\t)h\n)ubhkh4)\x81q\x89}q\x8ah\x07h7sbhnh4)\x81q\x8b}q\x8ch\x07h7sbub\x85q\x8dh\x07h\x05h2h/ub\x85q\x8ehs)hthu)\x81q\x8f}q\x90(hxh4)\x81q\x91}q\x92h\x07h{sbh|Nh}h~)\x81q\x93}q\x94h\x07Nsbububh])\x81q\x95}q\x96(hYh`)\x81q\x97}q\x98(hchd)\x81q\x99}q\x9a(hgh\x04)\x81q\x9b}q\x9c(h\x07X\x01\x00\x00\x00yq\x9dh\t)h\n)ubhkh4)\x81q\x9e}q\x9fh\x07h7sbhnh4)\x81q\xa0}q\xa1h\x07h7sbub\x85q\xa2h\x07h\x04)\x81q\xa3}q\xa4(h\x07h\x08h\t)h\n)ubh2h/ub\x85q\xa5hs)hthu)\x81q\xa6}q\xa7(hxh4)\x81q\xa8}q\xa9h\x07h{sbh|Nh}h~)\x81q\xaa}q\xabh\x07Nsbubub\x87q\xacX\x06\x00\x00\x00headerq\xadhu)\x81q\xae}q\xaf(hxh4)\x81q\xb0}q\xb1h\x07h{sbh|Nh}h~)\x81q\xb2}q\xb3h\x07NsbubX\x06\x00\x00\x00indentq\xb4NX\x06\x00\x00\x00footerq\xb5)ubX\x05\x00\x00\x00basesq\xb6)X\x08\x00\x00\x00keywordsq\xb7)X\n\x00\x00\x00decoratorsq\xb8)h\th/h\nh/hs)X\x16\x00\x00\x00lines_after_decoratorsq\xb9)X\x16\x00\x00\x00whitespace_after_classq\xbah4)\x81q\xbb}q\xbch\x07h7sbX\x15\x00\x00\x00whitespace_after_nameq\xbdh4)\x81q\xbe}q\xbfh\x07h{sbX\x17\x00\x00\x00whitespace_before_colonq\xc0h4)\x81q\xc1}q\xc2h\x07h{sbubh>K\x01h(hPh\x0bh\x11h?h\x16]q\xc3\x85q\xc4Rq\xc5uba\x85q\xc6Rq\xc7uX\t\x00\x00\x00_accessesq\xc8h\x15h\x16\x85q\xc9Rq\xcaX\x11\x00\x00\x00_assignment_countq\xcbK\x02ubh\x13h\x11h\x14h\x15h\x16\x85q\xccRq\xcd(hjh\x16]q\xceh\x1a)\x81q\xcf}q\xd0(h\x03hhh>K\x00h(hjh\x0bh\rh?h\x16]q\xd1\x85q\xd2Rq\xd3uba\x85q\xd4Rq\xd5h\x08h\x16]q\xd6h\x1a)\x81q\xd7}q\xd8(h\x03h\x87h>K\x01h(h\x08h\x0bh\rh?h\x16]q\xd9h\x00)\x81q\xda}q\xdb(h\x03h\xa3h\x0bh\rhE\x89hF\x89hGh\x16]q\xdch\xd7a\x85q\xddRq\xdehKK\x02uba\x85q\xdfRq\xe0uba\x85q\xe1Rq\xe2h\x9dh\x16]q\xe3h\x1a)\x81q\xe4}q\xe5(h\x03h\x9bh>K\x02h(h\x9dh\x0bh\rh?h\x16]q\xe6\x85q\xe7Rq\xe8uba\x85q\xe9Rq\xeauh\xc8h\x15h\x16\x85q\xebRq\xech\x08h\x16]q\xed(h\x01h\xdahAe\x85q\xeeRq\xefsh\xcbK\x03h(hPh\x03hUX\x11\x00\x00\x00_scope_overwritesq\xf0}q\xf1ubhE\x89hF\x89hGh\x16]q\xf2h\x1ba\x85q\xf3Rq\xf4hKK\x01ub.'
FAIL

======================================================================
FAIL: test_ordering (libcst.metadata.tests.test_scope_provider.ScopeProviderTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/abuild/rpmbuild/BUILD/libcst-0.3.16/libcst/metadata/tests/test_scope_provider.py", line 1398, in test_ordering
    self.assertEqual(x.value, global_refs[0].node)
AssertionError: Name(
    value='b',
    lpar=[],
    rpar=[],
) != Name(
    value='b',
    lpar=[],
    rpar=[],
)

@stanislavlevin
Copy link
Contributor

This is a sorting issue.

(Pdb) type(first_assignment.references)
<class 'set'>

self.__assignments = set()

A set is an unordered collection with no duplicate elements.

An order may be different on each launch of Python interpreter.

(Pdb) x.value == global_refs[1].node
True
(Pdb) x.value == global_refs[0].node
False

stanislavlevin added a commit to stanislavlevin/LibCST that referenced this issue Feb 18, 2022
The test wrongly assumed that `first_assignment.references`
is ordered collection, while actually it is `set`.

Fixes: Instagram#442
Signed-off-by: Stanislav Levin <[email protected]>
stanislavlevin added a commit to stanislavlevin/LibCST that referenced this issue Feb 18, 2022
The test wrongly assumed that `first_assignment.references`
is ordered collection, while actually it is `set`.

Fixes: Instagram#442
Signed-off-by: Stanislav Levin <[email protected]>
stroxler pushed a commit that referenced this issue Feb 18, 2022
The test wrongly assumed that `first_assignment.references`
is ordered collection, while actually it is `set`.

Fixes: #442
Signed-off-by: Stanislav Levin <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants