How to use the ward.util.truncate function in ward

To help you get started, we’ve selected a few ward examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github darrenburns / ward / tests / test_util.py View on Github external
def _(
    input=s,
    num_chars=each(20, 11, 10, 5),
    expected=each(s, s, "hello w...", "he..."),
):
    result = truncate(input, num_chars)
    expect(result).equals(expected)
github darrenburns / ward / ward / terminal.py View on Github external
def output_why_test_failed(self, test_result: TestResult):
        err = test_result.error
        if isinstance(err, ExpectationFailed):
            print(
                f"   Given {truncate(repr(err.history[0].this), num_chars=self.terminal_size.width - 24)}\n"
            )

            for expect in err.history:
                self.print_expect_chain_item(expect)

            last_check = err.history[-1].op  # the check that failed
            if last_check == "equals":
                self.print_failure_equals(err)
        else:
            self.print_traceback(err)

        print(Style.RESET_ALL)
github darrenburns / ward / ward / terminal.py View on Github external
def print_expect_chain_item(self, expect: Expected):
        checkbox = self.result_checkbox(expect)
        that_width = self.terminal_size.width - 32
        if expect.op == "satisfies" and hasattr(expect.that, "__name__"):
            expect_that = truncate(expect.that.__name__, num_chars=that_width)
        else:
            that = repr(expect.that) if expect.that else ""
            expect_that = truncate(that, num_chars=that_width)
        print(f"    {checkbox} it {expect.op} {expect_that}{Style.RESET_ALL}")
github darrenburns / ward / ward / terminal.py View on Github external
def print_expect_chain_item(self, expect: Expected):
        checkbox = self.result_checkbox(expect)
        that_width = self.terminal_size.width - 32
        if expect.op == "satisfies" and hasattr(expect.that, "__name__"):
            expect_that = truncate(expect.that.__name__, num_chars=that_width)
        else:
            that = repr(expect.that) if expect.that else ""
            expect_that = truncate(that, num_chars=that_width)
        print(f"    {checkbox} it {expect.op} {expect_that}{Style.RESET_ALL}")