This repository was archived by the owner on Feb 19, 2023. It is now read-only.
This repository was archived by the owner on Feb 19, 2023. It is now read-only.
Getting started #8
Closed
Description
The testing tasks involve the following:
- choose a linting rule (found in
pandas_dev_flaker/_plugins_tree
orpandas_dev_flaker/_plugins_tokens
). E.g.pandas_dev_flaker/_plugins_tree/builtin_filter.py
. - From the content of MSG, try to understand what it's meant to check for. If it's not clear, please ask :) The above example checks that the builtin function
filter
isn't used - Make a test file in
tests
, e.g. for the above, it would betests/builtin_filter_test.py
For your test, follow this template:
import ast
import tokenize
from io import StringIO
import pytest
from pandas_dev_flaker.__main__ import run
def results(s):
return {
"{}:{}: {}".format(*r)
for r in run(
ast.parse(s),
list(tokenize.generate_tokens(StringIO(s).readline)),
)
}
@pytest.mark.parametrize(
"source",
(
pytest.param(
<CODE WHICH SHOULD NOT ERROR GOES HERE>,
id=<NAME FOR TEST CASE>,
),
),
)
def test_noop(source):
assert not results(source)
@pytest.mark.parametrize(
"source, expected",
(
pytest.param(
<CODE WHICH SHOULD ERROR>,
<EXPECTED ERROR MESSAGE>,
id=<NAME FOR TEST CASE>
),
),
)
def test_violation(source, expected):
(result,) = results(source)
assert result == expected
So, in the above example, I would expect
filter(lambda x: x, [0, 1])
to error (because we're using the built-in filter
function), while
import foo
foo.filter(lambda x: x, [0, 1])
shouldn't error, because it's a function filter
which was imported from somewhere rather than being the builtin filter.
Metadata
Metadata
Assignees
Labels
No labels