πŸš€ Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more β†’
Socket
DemoInstallSign in
Socket

deflector

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

deflector

Deflector is a minimalist testing library for Python designed to simplify test writing with a clear and intuitive syntax, allowing developers to create and run tests quickly and efficiently without unnecessary complications.

0.1.1
PyPI
Maintainers
1
deflector Logo

Deflector

πŸ“˜ Documentation - Under Construction

Why does Deflector exist?

πŸ’‘ Deflector is a minimalist testing library for Python designed to simplify test writing with a clear and intuitive syntax, allowing developers to create and run tests quickly and efficiently without unnecessary complications.

check High isolation level per file
check Performant and lightweight
check Fully typed library

Quickstart

check Install

$ pip install deflector

Or with poetry

poetry add deflector -G dev

check Test

tests/test_file1.py
from deflector import affirm


affirm.equal(1, 1, "My first test with deflector")

check Run

deflector # or poetry run deflector

Or defining the directory where the tests are:

deflector --dir tests

Features

check Main

FunctionDescription
affirmπŸ” Test assertion.
itπŸ€ΉπŸ»β€β™€οΈ Isolate tests.
describeπŸ€ΉπŸ»β€β™€οΈ Grouping tests.
before_each β€’ after_eachπŸƒ Functions for test setup and teardown.

Affirm

The affirm is used to create tests that validate whether the behavior of your code is as expected, checking the correspondence between values ​​and triggering errors if there are discrepancies.

from deflector import affirm
FunctionDescription
okChecks if a value is truthy.
equalCompares if two values are equal.
not_equalVerifies if two values are different.
match_reChecks if a string matches a regex.
does_not_match_reVerifies if a string does not match a regex.
Ok
affirm.ok(value, message)
affirm.ok(True, "Ok")
Equals
affirm.equal(value, expected, message)
affirm.equal(1 + 2, 3, "Equal: Sum 1+2=3")
Not Equals
affirm.not_equal(value, expected, message)
affirm.not_equal(1 + 2, 4, "Not Equal: Sum 1+2!=4")
Match Regex
affirm.match_re(value, reg_exp, message)
affirm.match_re("acab", "ab", "Match Regex: ab in acab")
Does Not Match Regex
affirm.does_not_match_re(value, reg_exp, message)
affirm.does_not_match_re("ab", "abc", "Does Not Match Regex: ab not in a")

It

from deflector import affirm, it

@it("It Test 1")
def test_1() -> None:
    affirm.ok(True, "Ok")
    affirm.equal(1 + 1, 2, "Equal")
    affirm.not_equal(1 + 2, 1, "Not Equal")
    affirm.match_re("acab", "ab", "Match Re")
    affirm.does_not_match_re("a", "ab", "Does Not Match Re")

Describe

from deflector import affirm, describe, it

@describe("Main 1")
def describe_main() -> None:
    @it("It Test 1")
    def test1() -> None:
        affirm.equal(1 + 1, 2, "Equal 1+1=2")

    @it("It Test 2")
    def test2() -> None:
        affirm.match_re("acab", "ab", "Match Re")

Before Each β€’ After Each

from deflector import affirm, describe, it

@describe("Main 1")
def describe_main() -> None:
    x = 1

    @before_each()
    async def start() -> bool:
        nonlocal x
        await asyncio.sleep(1)
        x += 1
        return True

    @after_each()
    async def end_() -> bool:
        nonlocal x
        await asyncio.sleep(1)
        x = 1
        return True

    @it("It Test 1")
    def test1() -> None:
        affirm.equal(x, 2, "Equal Before Each")
        affirm.equal(1 + 1, 2, "Equal 1")
        affirm.equal(1 + 1, 2, "Equal 2")

    @it("It Test 2")
    def test2() -> None:
        affirm.equal(x, 2, "Equal After Each")
        affirm.equal(1 + 1, 2, "Equal")
        affirm.not_equal(1 + 1, 1, "Not Equal")
        affirm.ok(True, "Ok")
        affirm.match_re("acab", "ab", "Match Re")
        affirm.does_not_match_re("a", "ab", "Does Not Match Re")

Keywords

test

FAQs

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts