def test_variable_expression_fill_with_str_without_type(): context = Context() context.currentContext["name"] = "Atmaram" var_e = VariableExpression("name") val = var_e.fill(context) assert type(val) == StringHolder assert val.value == "Atmaram"
def test_function_expression_get_required_variables_when_in_context_int_var(): context = Context() context.currentContext["name"] = 123 fun_e = FunctionExpression(add, [VariableExpression("name").of_type(int)]) val = fun_e.get_required_variables(context) assert type(val) == MapVariable assert len(val.variable_map) == 0
def test_function_expression_get_required_variables_when_in_context_str_var(): context = Context() context.currentContext["name"] = "Atmaram" fun_e = FunctionExpression(join, [VariableExpression("name").of_type(str)]) val = fun_e.get_required_variables(context) assert type(val) == MapVariable assert len(val.variable_map) == 0
def test_variable_expression_fill_with_int_without_type(): context = Context() context.currentContext["name"] = 123 var_e = VariableExpression("name") val = var_e.fill(context) assert type(val) == IntegerHolder assert val.value == 123
def test_pour_to_list_when_source_is_greater_than_target(): l1 = [{"place": "pune"}] l2 = [{"name": "atmaram"}, {"name": "yogesh"}] Context.pour_to(l1, l2) obj1 = {"name": "atmaram", "place": "pune"} obj2 = {"name": "yogesh"} assert obj1 in l1 assert obj2 in l1
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"
def test_function_expression_fill_with_strings(): context = Context() context.currentContext["name"] = "Atmaram" context.currentContext["place"] = "Pune" fun_e = FunctionExpression( join, [VariableExpression("name").of_type(str)]).with_argument( VariableExpression("place").of_type(str)) val = fun_e.fill(context) assert val.value == "AtmaramPune"
def test_function_expression_fill_with_string_and_integer(): context = Context() context.currentContext["name"] = "Atmaram" context.currentContext["place"] = 123 fun_e = FunctionExpression(join, [ VariableExpression("name").of_type(str), VariableExpression("place").of_type(int) ]) val = fun_e.fill(context) assert val.value == "Atmaram123"
def test_function_add_expression_fill_with_integer_and_string(): context = Context() context.currentContext["name"] = 123 context.currentContext["place"] = '123' fun_e = FunctionExpression(add, [ VariableExpression("name").of_type(int), VariableExpression("place").of_type(str) ]) val = fun_e.fill(context) assert val.value == "123123"
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 == ""
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"
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
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'
def test_function_expression_get_required_variables_when_not_in_context_str_var( ): context = Context() fun_e = FunctionExpression(join, [VariableExpression("name").of_type(str)]) val = fun_e.get_required_variables(context) assert type(val) == MapVariable assert 'name' in val.variable_map var = val.variable_map['name'] assert type(var) == ValueHolderVariable assert var.valueHolderClass == StringHolder
def test_variable_expression_get_required_variables_when_not_in_context_int_var( ): context = Context() var_e = VariableExpression("name").of_type(int) val = var_e.get_required_variables(context) assert type(val) == MapVariable assert 'name' in val.variable_map var = val.variable_map['name'] assert type(var) == ValueHolderVariable assert var.valueHolderClass == IntegerHolder
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"
def start(self, input_string, io): journey = self.__match(input_string, io) if journey is not None: journey.execute(Context(), io)
def test_expression_get_required_variables(): context = Context() exp = Expression() assert exp.get_required_variables(context) is None
def test_get_required_variables_method_when_io_none(): context = Context() template = Template() val = template.get_required_variables(context, None) assert type(val) == MapVariable assert len(val.variable_map) == 0
def test_constant_expression_get_required_variables_int_val(): context = Context() var_e = ConstantExpression(123) val = var_e.get_required_variables(context) assert type(val) == MapVariable assert len(val.variable_map) == 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"
def test_constant_expression_fill_with_int(): context = Context() fun_e = ConstantExpression(123) val = fun_e.fill(context) assert type(val) == IntegerHolder assert val.value == 123
def test_constant_expression_fill_with_str(): context = Context() fun_e = ConstantExpression("Atmaram") val = fun_e.fill(context) assert type(val) == StringHolder assert val.value == "Atmaram"
def test_pour_to_list_when_source_is_equal_to_target(): l1 = [{"name": "atmaram"}] l2 = [{"place": "pune"}] Context.pour_to(l1, l2) obj = {"name": "atmaram", "place": "pune"} assert obj in l1
def test_expression_fill(): context = Context() exp = Expression() assert exp.fill(context) is None
def test_pour_to_map(): o1 = {"name": "Anjali","Place": "delhi"} o2 = {"Place": ["pune","mumbai"]} Context.pour_to(o1, o2) obj1 = {"name": "Anjali", "Place": ["pune","mumbai"]} assert obj1 == o1