def test_trivial(): expected = """ user1() user2() if user3(): print("Y") """ c = C(dummy_trivial) x = c(io.StringIO(user_code)).getvalue() assert (x == expected)
def test_complex(): expected = """ if sys: user1() user2() if user3(): print("Y") """ c = C(dummy_complex) x = c(io.StringIO(user_code)).getvalue() assert (x == expected)
def test_simple(): expected = """ print("X") user1() user2() if user3(): print("Y") """ c = C(dummy_simple) x = c(io.StringIO(user_code)).getvalue() assert (x == expected)
def test_pass(): expected = """ if sys: user1() user2() if user3(): print("Y") pass if other: pass """ c = C(dummy_pass) x = c(io.StringIO(user_code)).getvalue() assert (x == expected)
def test_empty(): with pytest.raises(ValueError) as ve: C(dummy_empty) assert ("No insertion line" in str(ve.value))
def test_invalid_format(): with pytest.raises(ValueError) as ve: C(dummy_header) assert ("'# --- END TEMPLATE ---' is not in" in str(ve.value))
def test_multiple(): with pytest.raises(ValueError) as ve: C(dummy_multiple) assert ("Multiple insertion" in str(ve.value))