コード例 #1
0
def test_type_converter(reporter):
    results = [
        type_converter("str"),
        type_converter(1),
        type_converter({"key": 1}),
    ]
    verify_all("Type converter", results, reporter=reporter)
コード例 #2
0
def test_equals():
    results = [
        _validate_operator(AssertionOperator["=="], "actual", "actual"),
        _validate_operator(AssertionOperator["=="], "actual", "unexpected"),
        _validate_operator(AssertionOperator["=="], 1, "1"),
    ]
    verify_all("Test equals", results)
コード例 #3
0
def test_custom_error():
    results = [
        _validate_operator(
            AssertionOperator["=="],
            "actual",
            "unexpected",
            "partial error",
            "custom message",
        ),
        _validate_operator(
            AssertionOperator["=="],
            "ääööÅÅ",
            "åß∂ƒ©˙∆˚¬…æ",
            "partial error",
            "{value} {value_type} custom message {expected} {expected_type}",
        ),
        _validate_operator(
            AssertionOperator["=="],
            "ääööÅÅ",
            "åß∂ƒ©˙∆˚¬…æ",
            "partial error",
            "{value} custom message {expected}",
        ),
    ]
    verify_all("Test custom error", results)
コード例 #4
0
def test_less_or_equal():
    results = [
        _validate_operator(AssertionOperator[">="], 2, 2),
        _validate_operator(AssertionOperator[">="], 2, 3),
        _validate_operator(AssertionOperator[">="], 2, 1),
    ]
    verify_all("less or equal", results)
コード例 #5
0
def test_not_equals():
    results = [
        _validate_operator(AssertionOperator["!="], "actual", "expected"),
        _validate_operator(AssertionOperator["!="], "actual", "actual",
                           "partial error message"),
    ]
    verify_all("Not equal", results)
コード例 #6
0
def test_validate(with_suite):
    results = [
        _validate_operator(AssertionOperator("validate"), 1, "0 < value < 2"),
        _validate_operator(AssertionOperator("validate"), 1,
                           "value == 'hello'"),
    ]
    verify_all("validate", results)
コード例 #7
0
def test_less():
    results = [
        _validate_operator(AssertionOperator[">"], 2, 1),
        _validate_operator(AssertionOperator[">"], 2, 1, formatters=[_strip]),
        _validate_operator(AssertionOperator[">"], 2, 3, "custom"),
    ]
    verify_all("Less", results)
コード例 #8
0
def test_invalid_operator():
    results = [
        _validate_operator("foo", "actual", "unexpected", "bar"),
        _validate_operator("foo", "actual", "unexpected"),
        _validate_operator("foo", "actual", "unexpected", formatters=[_strip]),
    ]
    verify_all("Custom error", results)
コード例 #9
0
def test_greater():
    results = [
        _validate_operator(AssertionOperator["<"], 1, 2),
        _validate_operator(AssertionOperator["<"], 1, 2, formatters=[_strip]),
        _validate_operator(AssertionOperator["<"], 1, 0, "custom"),
    ]
    verify_all("Greater", results)
コード例 #10
0
def test_not_contains():
    results = [
        _validate_operator(AssertionOperator["not contains"], "actual", "xxx"),
        _validate_operator(AssertionOperator["not contains"], "actual", "t",
                           "custom"),
    ]
    verify_all("Not contains", results)
コード例 #11
0
def test_greater_or_equal():
    results = [
        _validate_operator(AssertionOperator["<="], 1, 2),
        _validate_operator(AssertionOperator["<="], 1, 0),
        _validate_operator(AssertionOperator["<="], 1, 1),
    ]
    verify_all("greater or equal", results)
コード例 #12
0
def test_type_converter():
    results = [
        type_converter(None),
        type_converter(""),
        type_converter(1),
        type_converter(True),
    ]
    verify_all("Type converter", results)
コード例 #13
0
def test_contains():
    results = [
        _validate_operator(AssertionOperator["contains"], "actual", "ctua"),
        _validate_operator(AssertionOperator["contains"], "actual", "nope"),
        _validate_operator(AssertionOperator["*="], "actual", "tual"),
        _validate_operator(AssertionOperator["*="], "actual", "nope"),
    ]
    verify_all("Contains", results)
コード例 #14
0
def test_with_assertions_polling():
    fb = FakeBrowser()
    results = [
        fb.is_three(3),
        _method_validator(fb.is_three, 2),
        fb.second_run_success(),
    ]
    verify_all("Assertion polling", results)
コード例 #15
0
def test_without_assertions_polling():
    fb = FakeBrowser()
    fb.retry_assertions_for = 0
    results = [
        fb.is_three(3),
        _method_validator(fb.is_three, 2),
        _method_validator(fb.second_run_success)
    ]
    verify_all("No polling", results)
コード例 #16
0
def test_then(with_suite):
    then_op = AssertionOperator["then"]
    results = [
        verify_assertion(8, then_op, "value + 3") == 11,
        verify_assertion(2, then_op, "value + 3") == 5,
        verify_assertion("René", then_op,
                         "'Hello ' + value + '!'") == "Hello René!",
    ]
    verify_all("then", results)
コード例 #17
0
def test_ends_with():
    results = [
        _validate_operator(AssertionOperator["$="], "Hello Robots", "Robots"),
        _validate_operator(AssertionOperator["$="], "Hello Robots", "Hello"),
        _validate_operator(AssertionOperator["$="], "Hel[4,5]?[1-9]+ Robots",
                           "[1-9]+ Robots"),
        _validate_operator(AssertionOperator["$="], "Hel[4,5]?[1-9]+ Robots",
                           ".*"),
    ]
    verify_all("ends with", results)
コード例 #18
0
def test_start_with():
    results = [
        _validate_operator(AssertionOperator["^="], "Hello Robots", "Hello"),
        _validate_operator(AssertionOperator["^="], "Hello Robots", "Robots"),
        _validate_operator(AssertionOperator["should start with"],
                           "Hello Robots", "Hello"),
        _validate_operator(AssertionOperator["should start with"],
                           "Hello Robots", "Robots"),
        _validate_operator(AssertionOperator["^="], "Hel[4,5]?[1-9]+ Robots",
                           "Hel[4,5]?[1-"),
        _validate_operator(AssertionOperator["^="], "Hel[4,5]?[1-9]+ Robots",
                           ".*"),
    ]
    verify_all("start with", results)
コード例 #19
0
def test_match():
    results = [
        _validate_operator(AssertionOperator["matches"], "Actual",
                           "(?i)actual"),
        _validate_operator(AssertionOperator["matches"], "Actual", "/(\\d)+/"),
        _validate_operator(AssertionOperator["matches"], "Actual", "^Act"),
        _validate_operator(AssertionOperator["matches"], "Actual", "/(\\d)+/"),
        _validate_operator(AssertionOperator["matches"], "Actual", "ual$"),
        _validate_operator(AssertionOperator["matches"], "Actual\nmultiline",
                           "(?m)Actual\nmultiline$"),
        _validate_operator(AssertionOperator["matches"], "Actual\nmultiline",
                           "/(\\d)+/"),
    ]
    verify_all("match", results)
コード例 #20
0
def test_get_video_size(state: PlaywrightState):
    results = [
        state._get_video_size({}),
        state._get_video_size({"videosPath": "/path/to"}),
        state._get_video_size({"videoSize": {"width": 12, "height": 11}}),
        state._get_video_size({"viewport": {"width": 123, "height": 111}}),
        state._get_video_size(
            {
                "videoSize": {"width": 12, "height": 11},
                "viewport": {"width": 123, "height": 111},
            }
        ),
    ]
    verify_all("Video size", results)
コード例 #21
0
def test_not_equals():
    results = [
        _validate_operator(AssertionOperator["!="], "actual", "expected"),
        _validate_operator(AssertionOperator["!="], "actual", "actual",
                           "partial error message"),
        _validate_operator(AssertionOperator["!="],
                           " actual ",
                           "expected",
                           formatters=[_strip]),
        _validate_operator(AssertionOperator["!="],
                           " actual ",
                           "  actual  ",
                           formatters=[_strip, _apply_to_expected]),
    ]
    verify_all("Not equal", results)
コード例 #22
0
def test_equals():
    results = [
        _validate_operator(AssertionOperator["=="], "actual", "actual"),
        _validate_operator(AssertionOperator["=="], "actual", "unexpected",
                           "partial error"),
        _validate_operator(AssertionOperator["=="], 1, "1"),
        _validate_operator(AssertionOperator["=="],
                           1,
                           "1",
                           formatters=[_strip]),
        _validate_operator(AssertionOperator["=="],
                           "  1  ",
                           "1",
                           formatters=[_strip]),
    ]
    verify_all("Test equals", results)
コード例 #23
0
def test_localtor_split(finder: ElementFinder,
                        reporter: GenericDiffReporterFactory):
    results = [
        finder._split_locator("//div"),
        finder._split_locator("xpath://div"),
        finder._split_locator("xpath=//div"),
        finder._split_locator('//*[text(), " >> "]'),
        finder._split_locator('//*[text(), " >> "] >> css:foobar'),
        finder._split_locator('//*[text(), " >> "] >> //div'),
        finder._split_locator('//*[text(), " >> "] >> css:foobar >> id:tidii'),
        finder._split_locator(
            "identifier:id >> id=name >> name=id >> xpath://a >> dom=name >> link=id >> partial link=something >> "
            'css=#name >> class:name >> jquery=dom.find("foobar") >> sizzle:query.find("tidii") >> '
            "tag:name >> scLocator:tidii"),
        finder._split_locator(['//*[text(), " >> "]', "css:foobar", "tidii"]),
        finder._split_locator("xpath://*  >>  xpath://div"),
        finder._split_locator("xpAtH://* >> xPAth://div"),
        finder._split_locator("xpath : //a >> xpath : //div"),
        finder._split_locator('//*[text(), " >> css:"]'),
    ]
    verify_all("Split multi locator", results, reporter=reporter)
コード例 #24
0
    def test_snippet_samples_compile(self) -> None:
        set_home_directory()

        def with_both(filename: str) -> bool:
            content = read_file(filename)
            snippet = "begin-snippet"
            namespace = "\nusing namespace ApprovalTests;"
            return snippet in content and namespace in content

        def with_embedded_cpp_file_with_include(filename: str) -> bool:
            content = read_file(filename)
            snippet = ".cpp -->"
            namespace = "\nusing namespace ApprovalTests;"
            return snippet in content and namespace in content

        all_files = self.find_all_files(".cpp", with_both, "../tests")
        all_files += self.find_all_files(".cpp", with_both, "../examples")
        all_files += self.find_all_files(".md", with_embedded_cpp_file_with_include, "../doc")

        verify_all("Files that have both snippets or embedded whole source files and using namespace ApprovalTests",
                   all_files, lambda f: str(f))
コード例 #25
0
 def test_move_command(self):
     verify_all("", [True, False],
                lambda b: get_command_text("a.text", "r.txt", b))
コード例 #26
0
def test_leap_with_list():
    results = [(year, is_leap(year)) for year in [1993, 1992, 1900, 2000]]
    verify_all("(year, is leap year)", results)
コード例 #27
0
def test_less():
    results = [
        _validate_operator(AssertionOperator[">"], 2, 1),
        _validate_operator(AssertionOperator[">"], 2, 3),
    ]
    verify_all("Less", results)
コード例 #28
0
def test_greater():
    results = [
        _validate_operator(AssertionOperator["<"], 1, 2),
        _validate_operator(AssertionOperator["<"], 1, 0),
    ]
    verify_all("Greater", results)