Exemplo n.º 1
0
def test_get_required_variables_method():
    context = Context()
    template = Template()
    mock_io = mock_console_io('123')
    val = template.get_required_variables(context, mock_io)
    assert type(val) == MapVariable
    assert len(val.variable_map) == 0
Exemplo n.º 2
0
def test_process_method_when_value_not_in_context(capsys):
    context = Context()
    mock_io = mock_console_io("Atmaram")
    template = text(string("Hello"), str_exp(var("name").of_type(str)))
    assert template.process(context, mock_io).value == "HelloAtmaram", "test failed"
    out, err = capsys.readouterr()
    assert out == "Please provide value for name of type String\n", "test failed"
Exemplo n.º 3
0
def test_journey_execute(capsys):
    context = Context()
    io = mock_console_io("2\nHello\nWorld\n")
    journey = Journey().named("Hello World").with_step(step1).with_step(
        step2).responding(text(string("Done Hello")))
    journey.execute(context, io)
    out, err = capsys.readouterr()
    assert out == 'I think you want to Hello World\nHelloWorldDone Hello\n'
Exemplo n.º 4
0
def test_process_method_when_value_in_context(capsys):
    context = Context()
    mock_io = mock_console_io("123")
    template = text(string("Hello"), str_exp(var("name")))
    context.currentContext["name"] = "Atmaram"
    assert template.process(context,mock_io).value == "HelloAtmaram", "test failed"
    out, err = capsys.readouterr()
    assert out == "", "test failed"
Exemplo n.º 5
0
def test_loop_step_call_when_data_not_present(capsys):
    context = Context()
    io = mock_console_io("2\nHello\nWorld\n")

    def step1(context_step, io_step):
        template = text(str_exp(var("name").of_type(str)))
        template.process(context_step, io_step)

    loop_step = LoopStep("names", step1)

    loop_step(context, io)
    out, err = capsys.readouterr()
    assert out == "Enter size of list as IntegerPlease provide value for name of type String\nPlease provide value for name of type String\n"
Exemplo n.º 6
0
def test_loop_step_call_when_data_present(capsys):
    context = Context()
    io = mock_console_io("Hello")
    context.currentContext["names"] = [{"name": "Atmaram"}, {"name": "Yogesh"}]

    def step1(context_step, io_step):
        template = text(str_exp(var("name")))
        template.process(context_step, io_step)

    loop_step = LoopStep("names", step1)

    loop_step(context, None)
    out, err = capsys.readouterr()
    assert out == ""
Exemplo n.º 7
0
def test_journey_manager_start_single_match(capsys):
    io = mock_console_io("")

    journey1 = Journey(step1).named("Hello World").with_step(step2).responding(
        text(string("Done Hello")))
    journey2 = Journey(step1).named("Hello Keep Rotating").with_step(
        step2).responding(text(string("Done Hello")))

    journey_manager = JourneyManager()
    journey_manager.add(journey1)
    journey_manager.add(journey2)
    journey_manager.start("keep", io)
    out, err = capsys.readouterr()
    assert out == 'I think you want to Hello Keep Rotating\nHelloWorldDone Hello\n'
Exemplo n.º 8
0
def test_journey_manager_start_multiple_matches(capsys):
    io = mock_console_io("1\n")

    journey1 = Journey(step1).named("Hello World").with_step(step2).responding(
        text(string("Done Hello")))
    journey2 = Journey(step1).named("Hello Keep Rotating").with_step(
        step2).responding(text(string("Done Hello")))

    journey_manager = JourneyManager()
    journey_manager.add(journey1)
    journey_manager.add(journey2)
    journey_manager.start("Hello", io)
    out, err = capsys.readouterr()
    assert out == 'What do you want to do: \n1) Hello World\n2) Hello Keep Rotating\nEnter Selection as Number: I think you want to Hello World\nHelloWorldDone Hello\n'
Exemplo n.º 9
0
def test_console_reader_read_method_for_string(capsys):
    mock_io = mock_console_io("123")
    obj = mock_io.reader.read(StringHolder)
    out, err = capsys.readouterr()
    assert obj.value == '123', "test failed"
    assert out == '', "test failed"
Exemplo n.º 10
0
def test_console_reader_read_method_for_integer(capsys):
    mock_io = mock_console_io("123")
    obj = mock_io.reader.read(IntegerHolder)
    assert obj.value == 123, "test failed"
    out, err = capsys.readouterr()
    assert out == '', "test failed"
Exemplo n.º 11
0
def test_process_method():
    context = Context()
    template = Template()
    mock_io = mock_console_io('123')
    assert template.process(context, mock_io).value is None, "test failed"