def test_start_with_render_false_renders_nothing(self): element = parser.Start( name="example", language="python", content="x = 1\nprint(x)", render=False, ) state = {} 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 = 1", "print(x)")))
def test_start_with_render_true_renders_content(self): element = parser.Start( name="example", language="python", content="x = 1", render=True, ) state = {} new_state, new_element = _execute(state, element) assert_that(new_element, is_code_block( language="python", content="x = 1", )) assert_that(new_state["example"], has_attrs(pending_lines=is_sequence()))
def test_converting_from_diff_to_replace_generates_replace_block(self): start = parser.Start( name="example", language="python", render=True, content=dedent(""" x = 1 print(x) """), ) diff = parser.Diff( name="example", render=False, content=dedent(""" --- old +++ new @@ -1,2 +1,2 @@ -x = 1 +x = 2 print(x) """), ) output = compiler.convert_block( source=( (1, start), (2, diff), ), line_number=2, block_type="replace", ) assert_that(output, is_sequence( is_start(), is_replace( name="example", render=False, content=dedent(""" x = 2 print(x) """) ), ))
def test_start_initialises_state_for_name(self): # TODO: error if name already taken element = parser.Start( name="example", language="python", content="x = 1", render=False, ) state = {} new_state, new_element = _execute(state, element) assert_that(new_state, is_mapping({ "example": is_code( language="python", content="x = 1", ), }))