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 failures with python 3.8 #183

Closed
mcepl opened this issue Dec 5, 2019 · 0 comments · Fixed by #185
Closed

test failures with python 3.8 #183

mcepl opened this issue Dec 5, 2019 · 0 comments · Fixed by #185

Comments

@mcepl
Copy link

mcepl commented Dec 5, 2019

When trying to update packages of python-radon for openSUSE/Tumbleweed, the test suite fails with these errors (comparing two floating point variables with ==? Really?):

[   10s] =================================== FAILURES ===================================
[   10s] ____ test_visitor[\n     a += 3\n     b += 4\n     c *= 3\n     -expected7] ____
[   10s] 
[   10s] code = '\n     a += 3\n     b += 4\n     c *= 3\n     ', expected = (3, 6, 2, 5)
[   10s] 
[   10s]     @pytest.mark.parametrize('code,expected', SIMPLE_BLOCKS)
[   10s]     def test_visitor(code, expected):
[   10s]         visitor = HalsteadVisitor.from_code(dedent(code))
[   10s] >       assert expected == (visitor.operators, visitor.operands,
[   10s]                             visitor.distinct_operators, visitor.distinct_operands)
[   10s] E       assert (3, 6, 2, 5) == (3, 6, 2, 6)
[   10s] E         At index 3 diff: 5 != 6
[   10s] E         Full diff:
[   10s] E         - (3, 6, 2, 5)
[   10s] E         ?           ^
[   10s] E         + (3, 6, 2, 6)
[   10s] E         ?           ^
[   10s] 
[   10s] radon/tests/test_halstead.py:71: AssertionError
[   10s] _ test_visitor[\n     a = b < 4\n     c = i <= 45 >= d\n     k = 4 < 2\n     -expected9] _
[   10s] 
[   10s] code = '\n     a = b < 4\n     c = i <= 45 >= d\n     k = 4 < 2\n     '
[   10s] expected = (4, 7, 3, 6)
[   10s] 
[   10s]     @pytest.mark.parametrize('code,expected', SIMPLE_BLOCKS)
[   10s]     def test_visitor(code, expected):
[   10s]         visitor = HalsteadVisitor.from_code(dedent(code))
[   10s] >       assert expected == (visitor.operators, visitor.operands,
[   10s]                             visitor.distinct_operators, visitor.distinct_operands)
[   10s] E       assert (4, 7, 3, 6) == (4, 7, 3, 7)
[   10s] E         At index 3 diff: 6 != 7
[   10s] E         Full diff:
[   10s] E         - (4, 7, 3, 6)
[   10s] E         ?           ^
[   10s] E         + (4, 7, 3, 7)
[   10s] E         ?           ^
[   10s] 
[   10s] radon/tests/test_halstead.py:71: AssertionError
[   10s] _ test_mi_visit[\n     class A(object):\n\n         def __init__(self, n):\n             # this is awesome\n             self.n = sum(i for i in range(n) if i&1)\n\n         def m(self, j):\n             """Just compute it.\n             Example.\n             """\n             if j > 421:\n                 return (self.n + 2) ** j\n             return (self.n - 2) ** j\n\n     a = A(4)\n     a.m(42)  # i don't know why, but it works\n-93.84027450359395-True] _
[   10s] 
[   10s] code = "class A(object):\n\n    def __init__(self, n):\n        # this is awesome\n        self.n = sum(i for i in range(n) i...     return (self.n + 2) ** j\n        return (self.n - 2) ** j\n\na = A(4)\na.m(42)  # i don't know why, but it works"
[   10s] expected = 93.84027450359395, count_multi = True
[   10s] 
[   10s]     @pytest.mark.parametrize('code,expected,count_multi', MI_VISIT_CASES)
[   10s]     def test_mi_visit(code, expected, count_multi):
[   10s]         code = dedent(code)
[   10s]         expected = expected
[   10s]         count_multi = count_multi
[   10s] >       assert mi_visit(code, count_multi) == expected
[   10s] E       assert 93.75365939134126 == 93.84027450359395
[   10s] E         -93.75365939134126
[   10s] E         +93.84027450359395
[   10s] 
[   10s] radon/tests/test_other_metrics.py:130: AssertionError
[   10s] _ test_mi_visit[\n     class A(object):\n\n         def __init__(self, n):\n             # this is awesome\n             self.n = sum(i for i in range(n) if i&1)\n\n         def m(self, j):\n             """Just compute it.\n             Example.\n             """\n             if j > 421:\n                 return (self.n + 2) ** j\n             return (self.n - 2) ** j\n\n     a = A(4)\n     a.m(42)  # i don't know why, but it works\n-88.84176333569131-False] _
[   10s] 
[   10s] code = "class A(object):\n\n    def __init__(self, n):\n        # this is awesome\n        self.n = sum(i for i in range(n) i...     return (self.n + 2) ** j\n        return (self.n - 2) ** j\n\na = A(4)\na.m(42)  # i don't know why, but it works"
[   10s] expected = 88.84176333569131, count_multi = False
[   10s] 
[   10s]     @pytest.mark.parametrize('code,expected,count_multi', MI_VISIT_CASES)
[   10s]     def test_mi_visit(code, expected, count_multi):
[   10s]         code = dedent(code)
[   10s]         expected = expected
[   10s]         count_multi = count_multi
[   10s] >       assert mi_visit(code, count_multi) == expected
[   10s] E       assert 88.75514822343865 == 88.84176333569131
[   10s] E         -88.75514822343865
[   10s] E         +88.84176333569131
[   10s] 
[   10s] radon/tests/test_other_metrics.py:130: AssertionError
[   10s] =================== 4 failed, 383 passed, 5 skipped in 1.17s ===================

Complete build logs with all details

bmwiedemann added a commit to bmwiedemann/openSUSE that referenced this issue Dec 11, 2019
brnsnt added a commit to brnsnt/radon that referenced this issue Jan 25, 2020
As of Python 3.8 `ast.Num` is deprecated and not counted as operand
Fixes rubik#183
@brnsnt brnsnt mentioned this issue Jan 25, 2020
rubik pushed a commit that referenced this issue Jan 28, 2020
* fix(visitor): count Constant as halstead operand

As of Python 3.8 `ast.Num` is deprecated and not counted as operand
Fixes #183

* test(tox): add py37,py38

* chore(travis-ci): add Python 3.8

Also remove the workaround for Python 3.7 as is is supported by now

* chore(setup): pin colorama to 0.4.1

Python 3.4 breaks due to tartley/colorama#244

* pin colorama to 0.4.1
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.

1 participant