本文整理汇总了Python中tests.util.asserts.equals函数的典型用法代码示例。如果您正苦于以下问题:Python equals函数的具体用法?Python equals怎么用?Python equals使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了equals函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Can_construct_a_nonempty_value_class_using_positional_args
def Can_construct_a_nonempty_value_class_using_positional_args():
@valueclass("mem1", "mem2")
class MyClass:
pass
b = MyClass(3, 4)
assert_that(b.mem1, equals(3))
assert_that(b.mem2, equals(4))
示例2: Can_construct_a_nonempty_value_class_using_keyword_args
def Can_construct_a_nonempty_value_class_using_keyword_args():
@valueclass("mem1", "mem2")
class MyClass:
pass
b = MyClass(mem1=3, mem2=4)
assert_that(b.mem1, equals(3))
assert_that(b.mem2, equals(4))
示例3: Readline_reads_up_to_a_newline
def Readline_reads_up_to_a_newline():
pipe = Pipe()
pipe.write("ab")
pipe.write("c\nd")
pipe.write("e")
pipe.write("\nghi")
pipe.close()
assert_that(pipe.readline(), equals("abc\n"))
assert_that(pipe.readline(), equals("de\n"))
assert_that(pipe.readline(), equals("ghi"))
示例4: Pipe_can_tell_you_whether_it_has_output_pending
def Pipe_can_tell_you_whether_it_has_output_pending():
with Pipe() as p1:
assert_that(p1.pending(), equals(False))
p1.write("xxx")
assert_that(p1.pending(), equals(True))
p1.read(3)
assert_that(p1.pending(), equals(False))
p1.write("xx")
p1.close()
assert_that(p1.pending(), equals(True))
p1.read()
assert_that(p1.pending(), equals(False))
示例5: Multiple_function_calls_with_various_args_get_parsed
def Multiple_function_calls_with_various_args_get_parsed():
assert_that(
parsed("print( 'a', 3, 4 / 12 )(512)();"),
equals(
[
(
"call",
(
"call",
(
"call",
("symbol", "print"),
[
("string", "a"),
("number", "3"),
(
"operation",
"/",
("number", "4"),
("number", "12")
)
]
),
[
("number", "512")
]
),
[]
)
]
)
)
示例6: Function_definition_with_params_and_commands_gets_parsed
def Function_definition_with_params_and_commands_gets_parsed():
assert_that(
parsed('{:(x,yy)print(3-4); a = "x"; print(a);};'),
equals(
[
(
"function",
[
("symbol", "x"),
("symbol", "yy")
],
[
(
"call",
("symbol", 'print'),
[
(
"operation",
'-',
("number", '3'),
("number", '4')
)
]
),
("assignment", ("symbol", 'a'), ("string", 'x')),
("call", ("symbol", 'print'), [("symbol", 'a')])
]
)
]
)
)
示例7: The_str_of_a_value_is_its_repr
def The_str_of_a_value_is_its_repr():
@valueclass("m1", "m2", "m3")
class MyClass:
pass
x = MyClass(3, '4', 5)
assert_that(str(x), equals(repr(x)))
示例8: A_closure_holds_updateable_values
def A_closure_holds_updateable_values():
def dumb_set(env, sym, val):
env.parent.parent.parent.set(sym[1], val)
def dumb_if_equal(env, val1, val2, then_fn, else_fn):
if val1 == val2:
ret = then_fn
else:
ret = else_fn
return eval_expr(("call", ret, []), env)
env = Env()
env.set("dumb_set", ("native", dumb_set))
env.set("dumb_if_equal", ("native", dumb_if_equal))
assert_that(
evald(
"""
counter = {
x = 0;
{:(meth)
dumb_if_equal(meth, "get",
{x;},
{dumb_set("x", x + 1);}
);
}
}();
counter("inc");
counter("inc");
counter("get");
""",
env
),
equals(("number", 2))
)
示例9: Function_definition_containing_commands_gets_parsed
def Function_definition_containing_commands_gets_parsed():
assert_that(
parsed('{print(3-4); a = "x"; print(a);};'),
equals(
[
(
"function",
[],
[
(
"call",
("symbol", 'print'),
[
(
"operation",
'-',
("number", '3'),
("number", '4')
)
]
),
("assignment", ("symbol", 'a'), ("string", 'x')),
("call", ("symbol", 'print'), [("symbol", 'a')])
]
)
]
)
)
示例10: Multiple_commands_parse_into_multiple_expressions
def Multiple_commands_parse_into_multiple_expressions():
program = """
x = 3;
func = {:(a) print(a);};
func(x);
"""
assert_that(
parsed(program),
equals(
[
("assignment", ("symbol", 'x'), ("number", '3')),
(
"assignment",
("symbol", 'func'),
(
"function",
[("symbol", 'a')],
[
("call", ("symbol", 'print'), [("symbol", 'a')])
]
)
),
("call", ("symbol", 'func'), [("symbol", 'x')])
]
)
)
示例11: Can_hold_a_reference_to_a_function_and_call_it
def Can_hold_a_reference_to_a_function_and_call_it():
assert_that(
evald("""
add = {:(x, y) x + y;};
add(20, 2.2);
"""),
equals(("number", 22.2))
)
示例12: A_native_function_can_edit_the_environment
def A_native_function_can_edit_the_environment():
def mx3(env):
env.set("x", ("number", 3))
env = Env()
env.set("make_x_three", ("native", mx3))
assert_that(
evald("x=1;make_x_three();x;", env),
equals(("number", 3))
)
示例13: A_symbol_within_a_function_has_the_local_value
def A_symbol_within_a_function_has_the_local_value():
assert_that(
evald("""
foo = 3;
bar = {foo = 77;foo;}();
bar;
"""),
equals(("number", 77))
)
示例14: Multiple_function_calls_with_no_args_get_parsed
def Multiple_function_calls_with_no_args_get_parsed():
assert_that(
parsed("print()();"),
equals(
[
("call", ("call", ("symbol", "print"), []), [])
]
)
)
示例15: Variable_assignment_gets_parsed
def Variable_assignment_gets_parsed():
assert_that(
parsed("x = 3;"),
equals(
[
("assignment", ("symbol", "x"), ("number", "3"))
]
)
)