def test_when_there_are_pending_lines_then_replace_raises_error(self): element = parser.Replace( name="example", content="x = 2", render=False, ) state = { "example": _create_code( language="python", content="x = 1", pending_lines=("x = 1", ), ), } error = pytest.raises(ValueError, lambda: _execute(state, element, line_number=42)) assert_that(str(error.value), equal_to("cannot replace on line number 42, pending lines:\nx = 1"))
def test_converting_from_replace_to_diff_generates_diff_block(self): start = parser.Start( name="example", language="python", render=True, content=dedent(""" x = 1 print(x) """), ) diff = parser.Replace( name="example", render=False, content=dedent(""" x = 2 print(x) """), ) output = compiler.convert_block( source=( (1, start), (2, diff), ), line_number=2, block_type="diff", ) assert_that(output, is_sequence( is_start(), is_diff( name="example", render=False, content=dedent(""" --- +++ @@ -1,2 +1,2 @@ -x = 1 +x = 2 print(x) """) ), ))
def test_replace_with_render_false_renders_nothing(self): element = parser.Replace( name="example", content="x = 2\nprint(x)\n", render=False, ) state = { "example": _create_code( language="python", content="x = 1\nprint(x)\n", pending_lines=(), ), } new_state, new_element = _execute(state, element) assert_that(new_element, is_empty_element) assert_that(new_state["example"], has_attrs(pending_lines=is_sequence("x = 2")))
def test_replace_with_render_true_renders_content(self): element = parser.Replace( name="example", content="x = 2", render=True, ) state = { "example": _create_code( language="python", content="x = 1", pending_lines=(), ), } new_state, new_element = _execute(state, element) assert_that(new_element, is_code_block( language="python", content="x = 2", )) assert_that(new_state["example"], has_attrs(pending_lines=is_sequence()))
def test_replace_replaces_content_for_code(self): element = parser.Replace( name="example", content="x = 2", render=False, ) state = { "example": _create_code( language="python", content="x = 1", ), } new_state, new_element = _execute(state, element) assert_that(new_state, is_mapping({ "example": is_code( language="python", content="x = 2", ), }))