Skip to content
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
Closed
@MarcoGorelli

Description

@MarcoGorelli

The testing tasks involve the following:

  1. choose a linting rule (found in pandas_dev_flaker/_plugins_tree or pandas_dev_flaker/_plugins_tokens). E.g. pandas_dev_flaker/_plugins_tree/builtin_filter.py.
  2. 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
  3. Make a test file in tests, e.g. for the above, it would be tests/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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions