def test_page_should_not_contain_all_strings_fails(mocker: MockerFixture,
                                                   under_test: x3270):
    mocker.patch("Mainframe3270.py3270.Emulator.string_get",
                 return_value="abc")

    with pytest.raises(Exception, match='The string "abc" was found'):
        under_test.page_should_not_contain_all_strings(["abc", "def"])
def test_page_should_contain_all_strings_ignore_case(mocker: MockerFixture,
                                                     under_test: x3270):
    mocker.patch("Mainframe3270.py3270.Emulator.string_get",
                 side_effect=["AbC", "DeF"])

    under_test.page_should_contain_all_strings(["abc", "def"],
                                               ignore_case=True)
Esempio n. 3
0
def test_wait_until_string_string_not_found(mocker: MockerFixture,
                                            under_test: x3270):
    mocker.patch("Mainframe3270.py3270.Emulator.string_get",
                 return_value="abc")

    with pytest.raises(Exception, match='String "def" not found in 1 seconds'):
        under_test.wait_until_string("def", 1)
def test_page_should_not_contain_string_fails(mocker: MockerFixture,
                                              under_test: x3270):
    mocker.patch("Mainframe3270.py3270.Emulator.string_get",
                 return_value="abc")

    with pytest.raises(Exception, match='The string "ABC" was found'):
        under_test.page_should_not_contain_string("ABC", ignore_case=True)
Esempio n. 5
0
def test_read_exceeds_x_axis(under_test: x3270, mocker: MockerFixture):
    mocker.patch("Mainframe3270.py3270.Emulator.string_get")
    with pytest.raises(
            Exception,
            match="You have exceeded the x-axis limit of the mainframe screen"
    ):
        under_test.read(1, 80, 2)
def test_execute_command(mocker: MockerFixture, under_test: x3270):
    mocker.patch("Mainframe3270.py3270.Emulator.exec_command")
    mocker.patch("time.sleep")
    under_test.execute_command("cmd")

    Emulator.exec_command.assert_called_with("cmd".encode("utf-8"))
    time.sleep.assert_called_with(under_test.wait)
def test_page_should_contain_string_x_times_custom_message(
        mocker: MockerFixture, under_test: x3270):
    mocker.patch("Mainframe3270.py3270.Emulator.string_get", return_value="a")

    with pytest.raises(Exception, match="my error message"):
        under_test.page_should_contain_string_x_times(
            "b", 1, error_message="my error message")
def test_page_should_not_contain_any_string_custom_message(
        mocker: MockerFixture, under_test: x3270):
    mocker.patch("Mainframe3270.py3270.Emulator.string_get",
                 return_value="abc")

    with pytest.raises(Exception, match="my error message"):
        under_test.page_should_not_contain_any_string(
            ["abc", "def"], error_message="my error message")
def test_delete_field_in_position(mocker: MockerFixture, under_test: x3270):
    mocker.patch("Mainframe3270.py3270.Emulator.move_to")
    mocker.patch("Mainframe3270.py3270.Emulator.exec_command")

    under_test.delete_field(5, 5)

    Emulator.move_to.assert_called_with(5, 5)
    Emulator.exec_command.assert_called_with(b"DeleteField")
Esempio n. 10
0
def test_read_fails_check_y_axis_limit(under_test: x3270,
                                       mocker: MockerFixture):
    mocker.patch("Mainframe3270.py3270.Emulator.string_get")
    with pytest.raises(
            Exception,
            match="You have exceeded the y-axis limit of the mainframe screen"
    ):
        under_test.read(25, 1, 1)
Esempio n. 11
0
def test_wait_until_string_not_found_until_timeout(mocker: MockerFixture,
                                                   under_test: x3270):
    mocker.patch("Mainframe3270.py3270.Emulator.string_get",
                 return_value="abc")
    mocker.patch("time.ctime", return_value="Sat Feb 12 15:29:51 2022")

    with pytest.raises(Exception, match='String "abc" not found in 5 seconds'):
        under_test.wait_until_string("abc")
def test_send_enter(mocker: MockerFixture, under_test: x3270):
    mocker.patch("Mainframe3270.py3270.Emulator.send_enter")
    mocker.patch("time.sleep")

    under_test.send_enter()

    Emulator.send_enter.assert_called_once()
    time.sleep.assert_called_once_with(X3270_DEFAULT_ARGS["wait_time"])
def test_write(mocker: MockerFixture, under_test: x3270):
    mocker.patch("Mainframe3270.py3270.Emulator.exec_command")
    mocker.patch("Mainframe3270.py3270.Emulator.send_enter")

    under_test.write("abc")

    Emulator.exec_command.assert_called_once_with(b'String("abc")')
    Emulator.send_enter.assert_called_once()
def test_delete_char(mocker: MockerFixture, under_test: x3270):
    mocker.patch("Mainframe3270.py3270.Emulator.move_to")
    mocker.patch("Mainframe3270.py3270.Emulator.exec_command")

    under_test.delete_char()

    Emulator.move_to.assert_not_called()
    Emulator.exec_command.assert_called_with(b"Delete")
def test_page_should_contain_string(mocker: MockerFixture, under_test: x3270):
    mocker.patch("Mainframe3270.py3270.Emulator.string_get",
                 return_value="abc")
    mocker.patch("robot.api.logger.info")

    under_test.page_should_contain_string("abc")

    logger.info.assert_called_with('The string "abc" was found')
def test_page_should_not_match_regex_fails(mocker: MockerFixture,
                                           under_test: x3270):
    mocker.patch("Mainframe3270.py3270.Emulator.string_get", return_value="a")

    with pytest.raises(
            Exception,
            match=re.escape('There are matches found for "[a]+" pattern')):
        under_test.page_should_not_match_regex("[a]+")
def test_page_should_contain_any_string_fails(mocker: MockerFixture,
                                              under_test: x3270):
    mocker.patch("Mainframe3270.py3270.Emulator.string_get",
                 return_value="abc")

    with pytest.raises(
            Exception,
            match=re.escape("The strings \"['def', 'ghi']\" were not found")):
        under_test.page_should_contain_any_string(["def", "ghi"])
def test_page_should_not_contain_match_ignore_case(mocker: MockerFixture,
                                                   under_test: x3270):
    mocker.patch("Mainframe3270.py3270.Emulator.string_get",
                 return_value="abc")

    with pytest.raises(
            Exception,
            match=re.escape('There are matches found for "*abc*" pattern')):
        under_test.page_should_not_contain_match("*ABC*", ignore_case=True)
def test_page_should_contain_match_fails(mocker: MockerFixture,
                                         under_test: x3270):
    mocker.patch("Mainframe3270.py3270.Emulator.string_get",
                 return_value="abc")

    with pytest.raises(
            Exception,
            match=re.escape('No matches found for "*e?g*" pattern')):
        under_test.page_should_contain_match("*e?g*")
def test_write_bare_in_position(mocker: MockerFixture, under_test: x3270):
    mocker.patch("Mainframe3270.py3270.Emulator.exec_command")
    mocker.patch("Mainframe3270.py3270.Emulator.move_to")
    mocker.patch("Mainframe3270.py3270.Emulator.send_enter")

    under_test.write_bare_in_position("abc", 5, 5)

    Emulator.move_to.assert_called_once_with(5, 5)
    Emulator.exec_command.assert_called_once_with(b'String("abc")')
    Emulator.send_enter.assert_not_called()
def test_take_screenshot(mocker: MockerFixture, under_test: x3270):
    mocker.patch("Mainframe3270.py3270.Emulator.save_screen")
    mocker.patch("robot.api.logger.write")
    mocker.patch("time.time", return_value=1.0)

    under_test.take_screenshot(500, 500)

    logger.write.assert_called_with(
        '<iframe src="./screenshot_1000.html" height="500" width="500"></iframe>',
        level="INFO",
        html=True,
    )
def test_set_screenshot_folder_nonexistent(mocker: MockerFixture,
                                           under_test: x3270):
    mocker.patch("robot.api.logger.error")
    mocker.patch("robot.api.logger.warn")
    path = os.path.join(os.getcwd(), "nonexistent")

    under_test.set_screenshot_folder(path)

    logger.error.assert_called_with(
        'Given screenshots path "%s" does not exist' % path)
    logger.warn.assert_called_with('Screenshots will be saved in "%s"' %
                                   under_test.imgfolder)
def test_page_should_contain_string_x_times_fails(mocker: MockerFixture,
                                                  under_test: x3270):
    mocker.patch("Mainframe3270.py3270.Emulator.string_get", return_value="a")

    with pytest.raises(
            Exception,
            match=
            'The string "a" was not found "1" times, it appears "24" times'):
        under_test.page_should_contain_string_x_times("a", 1)

    with pytest.raises(
            Exception,
            match='The string "b" was not found "1" times, it appears "0" times'
    ):
        under_test.page_should_contain_string_x_times("b", 1)
Esempio n. 24
0
def test_wait_until_string(mocker: MockerFixture, under_test: x3270):
    mocker.patch("Mainframe3270.py3270.Emulator.string_get",
                 return_value="abc")

    txt = under_test.wait_until_string("abc")

    assert txt == "abc"
Esempio n. 25
0
def test_read(under_test: x3270, mocker: MockerFixture):
    mocker.patch("Mainframe3270.py3270.Emulator.string_get",
                 return_value="abc")

    string = under_test.read(1, 1, 3)

    Emulator.string_get.assert_called_once_with(1, 1, 3)
    assert string == "abc"
def test_send_pf(mocker: MockerFixture, under_test: x3270):
    mocker.patch("Mainframe3270.py3270.Emulator.exec_command")

    under_test.send_PF("5")

    Emulator.exec_command.assert_called_with("PF(5)".encode("utf-8"))
def test_move_previous_field(mocker: MockerFixture, under_test: x3270):
    mocker.patch("Mainframe3270.py3270.Emulator.exec_command")

    under_test.move_previous_field()

    Emulator.exec_command.assert_called_with(b"BackTab")
def test_page_should_contain_match_ignore_case(mocker: MockerFixture,
                                               under_test: x3270):
    mocker.patch("Mainframe3270.py3270.Emulator.string_get",
                 return_value="ABC")

    under_test.page_should_contain_match("*a?c*", ignore_case=True)
def test_page_should_contain_any_string_ignore_case(mocker: MockerFixture,
                                                    under_test: x3270):
    mocker.patch("Mainframe3270.py3270.Emulator.string_get",
                 return_value="abc")

    under_test.page_should_contain_any_string(["ABC", "def"], ignore_case=True)
def test_page_should_not_contain_string(mocker: MockerFixture,
                                        under_test: x3270):
    mocker.patch("Mainframe3270.py3270.Emulator.string_get",
                 return_value="abc")

    under_test.page_should_not_contain_string("ABC")