예제 #1
0
def test_private_class():
    gamla.pipe(
        "class _Something: pass; A = _Something()",
        ast.parse,
        dead_code.detect,
        gamla.check(gamla.complement(gamla.count), AssertionError),
    )
예제 #2
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),
    )
예제 #3
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),
    )
예제 #4
0
def test_allow_double_underscore():
    gamla.pipe(
        'd.__getitem__("bla")',
        ast.parse,
        dead_code.detect,
        gamla.check(gamla.complement(gamla.count), AssertionError),
    )
예제 #5
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),
    )
예제 #6
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),
        )
예제 #7
0
파일: utils.py 프로젝트: hyroai/cloud-utils
def _should_update(
    identifier: Text,
    update: bool,
    force_update: bool,
    ttl_hours: int,
) -> Callable[[Dict], bool]:
    return gamla.anyjuxt(
        gamla.just(force_update),
        gamla.complement(gamla.inside(identifier)),
        gamla.alljuxt(
            gamla.just(update),
            gamla.compose_left(
                _time_since_last_updated(identifier),
                gamla.anyjuxt(
                    gamla.equals(None),
                    gamla.greater_than(datetime.timedelta(hours=ttl_hours)),
                ),
            ),
        ),
    )