Exemple #1
0
def test_allow_unused_public_function():
    gamla.pipe(
        "def hi():\n    return 1",
        ast.parse,
        dead_code.detect,
        gamla.check(gamla.complement(gamla.count), AssertionError),
    )
Exemple #2
0
def test_private_class():
    gamla.pipe(
        "class _Something: pass; A = _Something()",
        ast.parse,
        dead_code.detect,
        gamla.check(gamla.complement(gamla.count), AssertionError),
    )
Exemple #3
0
def test_allow_unused_public():
    gamla.pipe(
        'I_AM_A_CONSTANT = "asd"',
        ast.parse,
        dead_code.detect,
        gamla.check(gamla.complement(gamla.count), AssertionError),
    )
Exemple #4
0
def test_disallow_unused_async_private_function():
    gamla.pipe(
        "async def _hi():\n    return 1",
        ast.parse,
        dead_code.detect,
        gamla.check(gamla.count, AssertionError),
    )
Exemple #5
0
def test_disallow_unused_private():
    gamla.pipe(
        '_I_AM_A_CONSTANT = "asd"',
        ast.parse,
        dead_code.detect,
        gamla.check(gamla.count, AssertionError),
    )
Exemple #6
0
def test_allow_double_underscore():
    gamla.pipe(
        'd.__getitem__("bla")',
        ast.parse,
        dead_code.detect,
        gamla.check(gamla.complement(gamla.count), AssertionError),
    )
Exemple #7
0
def test_class_methods_disallowed():
    gamla.pipe(
        """@dataclasses.dataclass(frozen=True)
class SomeClass:
    # Some comment.
    text: Text
    _private_thing: Text = "bla"
""",
        ast.parse,
        dead_code.detect,
        gamla.check(gamla.count, AssertionError),
    )
Exemple #8
0
def test_bad():
    for bad_comment in [
        "# todo(uri): I am a bad comment.",
        "#todo: do something",
        "# TODO ROM: uncomment when vaccine faq fixed",
        "# TODO (rachel): Remove if not relevant after rescraping novant's vaccine faq.",
        "#no leading space",
    ]:
        gamla.pipe(
            bad_comment,
            comment.detect,
            gamla.check(gamla.count, AssertionError),
        )
Exemple #9
0
def test_class_methods_allowed():
    gamla.pipe(
        """@dataclasses.dataclass(frozen=True)
class SomeClass:
    # Some comment.
    text: Text
    _private_thing: Text = "bla"

    def is_something(self) -> bool:
        return self._private_thing in []
    """,
        ast.parse,
        dead_code.detect,
        gamla.check(gamla.complement(gamla.count), AssertionError),
    )
Exemple #10
0
def test_good():
    for good_comment in [
        "# TODO(uri): I am a good comment.",
        "# I am good too.",
        "a = 3  # I am good.",
        "from nlu.config import logging_config  # noqa: F401",
        "    for element in filter(  # type: ignore",
        '            url=render.add_utm_param("https://example.example.org/#screening"),',
        "        # https://example.com/example/index.html#/example/",
        "#: Bla bla.",
    ]:
        gamla.pipe(
            good_comment,
            comment.detect,
            gamla.check(gamla.complement(gamla.count), AssertionError),
        )
Exemple #11
0
def test_detect_redundant_lambda():
    gamla.pipe(
        """something = functools.lru_cache(maxsize=1024)(
    gamla.compose_left(
        gamla.pipe(
            _CONFIDENCE_ELEMENTS, gamla.map(_collect_type), gamla.star(gamla.juxtcat)
        ),
        gamla.filter(lambda element: element.confidence is not None),
        gamla.map(lambda element: element.confidence),
        tuple,
        gamla.check(lambda x: gamla.identity(x), ValueError),
        gamla.average,
    )
)""",
        ast.parse,
        redundant_lambda.detect,
        tuple,
        gamla.check(gamla.identity, AssertionError),
    )