def sshaped_area(shape, plane=1): width = shape.text[plane].size.x - 1 for y in range(0, shape.text[plane].size.y, 2): shape.text[plane].marks[0, y] = TM.Mark(direction="right") shape.text[plane].marks[width, y] = TM.Mark(direction="down") shape.text[plane].marks[width, y + 1] = TM.Mark(direction="left") shape.text[plane].marks[0, y + 1] = TM.Mark(direction="down")
def test_styled_text_marks_can_be_built_with_keywords_and_strings(): x = TM.Mark(color="green", effects="Blink", direction="Left") assert x.attributes["foreground"] == TM.Color("green") assert x.attributes["effects"] == TM.Effects.blink assert x.attributes["direction"] == TM.Directions.LEFT x = TM.Mark(background="green", effects="Blink, bold") assert x.attributes["background"] == TM.Color("green") assert x.attributes["effects"] == TM.Effects.blink | TM.Effects.bold x = TM.Mark(effects="Blink | bold") assert x.attributes["effects"] == TM.Effects.blink | TM.Effects.bold x = TM.Mark(effects="Blink bold") assert x.attributes["effects"] == TM.Effects.blink | TM.Effects.bold
def test_styled_text_doesnot_skip_positional_mark_placed_at_continuation_of_double_character( direction): sc, sh, text_plane = styled_text() sh.text[1].marks[5, 0] = TM.Mark(attributes={"foreground": "red"}) if direction == "right": start = (4, 0) check_point = (6, 0) else: start = (6, 0) check_point = (3, 0) sh.text[1][start] = f"[direction: {direction}][effect: encircled]ABC" sc.update() yield None # the next assert is covered by other tests - but it ensures at once # that directions, effects, and double-width printing are working in a consistent way assert sh[check_point].value == "B" # TODO: nowadays, the constant "TM.values.CONTINUATION is retrieved at the adjacent # cell - this should be changed so that the value that is "continued" is retrieved, # and a "raw" way should be provided to find the "CONTINUATION" indication # (The backend rendering needs it) # - so, the assert works now, but is commented out, as this behavior is # subject to change: # assert sh[check_point + V2(1, 0)].value == TM.values.CONTINUATION # This assert is the object of the current test: assert sh[check_point].foreground == TM.Color("red")
def test_markmap_prepare_copies_data_instance(): sh = TM.shape((10, 10)) m = TM.Mark() original = mm = sh.text[1].marks mm = mm.prepare("") assert original is not mm assert original.data is not mm.data
def test_styled_text_marks_inline_end_markup_dont_turn_off_location_based_mark( ): sc, sh, text_plane = styled_text() sc.text[1].marks[3, 0] = TM.Mark(attributes={"color": "green"}) sc.text[1].marks[4, 0] = TM.Mark(pop_attributes={"color": None}) sc.text[1].marks[5, 0] = TM.Mark(attributes={"color": "green"}) sc.text[1].marks[7, 0] = TM.Mark(pop_attributes={"color": None}) sc.text[1][0, 0] = "[color: purple]012345[/color]6789" sc.update() yield None assert sc.data[0, 0].foreground == TM.Color("purple") assert sc.data[3, 0].foreground == TM.Color("green") assert sc.data[4, 0].foreground == TM.Color("purple") assert sc.data[6, 0].foreground == TM.Color("green") assert sc.data[7, 0].foreground == TM.values.DEFAULT_FG
def test_styled_text_on_replaying_skipped_cell_mark_should_place_it_first_than_inline_mark_on_next_char( ): sc, sh, text_plane = styled_text() sh.text[1].marks[5, 0] = TM.Mark(attributes={"foreground": "red"}) sh.text[1][4, 0] = "[effect: encircled]A[color: yellow]B[/color]C" sc.update() yield None assert sh[6, 0].foreground == TM.Color("yellow") assert sh[8, 0].foreground == TM.Color("red")
def test_text_plane_clear(): sh = TM.shape((10, 10)) sh.text[1].marks[1, 0] = TM.Mark(attributes={"color": TM.Color("yellow")}) sh.text[1][0, 0] = "qazwsx" assert isinstance(sh.text[1].marks[10, 0], TM.Mark) assert sh.text[1].plane[1, 0] == "a" sh.text[1].clear() assert isinstance(sh.text[1].marks[10, 0], TM.Mark) assert sh.text[1].plane[1, 0] == " " assert sh.text[1].marks.get((1, 0), None) is None
def test_markmap_mark_retrieved_at_all_possible_positions( input_index, expected_at): sh = TM.shape((10, 10)) m = TM.Mark() mm = sh.text[1].marks mm.relative_data.clear() mm[input_index] = m for index in expected_at: assert mm[index] is m
def test_markmap_mark_deleted_at_all_possible_positions(input_index, marks_at): sh = TM.shape((10, 10)) mm = sh.text[1].marks mm.relative_data.clear() m = TM.Mark() for index in marks_at: mm[index] = m assert mm[input_index] is m del mm[input_index] assert mm.get(input_index) is None with pytest.raises(KeyError): del mm[input_index]
def test_markmap_works_with_negative_index(): sh = TM.shape((10, 10)) m = TM.Mark() mm = sh.text[1].marks mm.relative_data.clear() mm[-1, 0] = m assert mm[-1, 0] is m assert not mm.data assert len(mm.relative_data) == 1 assert isinstance(first(mm.relative_data.keys())[0], RelativeMarkIndex) assert isinstance(first(mm.relative_data.keys())[1], int)
def test_markmap_several_marks_at_same_position_retrieved_as_list(): sh = TM.shape((10, 10)) m = TM.Mark() mm = sh.text[1].marks mm.relative_data.clear() mm[9, 0] = m mm[-1, 0] = m assert mm[9, 0] == [m, m] mm[-1, -10] = m assert mm[9, 0] == [m, m, m]
def test_markmap_mark_retrieved_as_absolute_mark_when_rendering(): sh = TM.shape((10, 10)) m = TM.Mark() mm = sh.text[1].marks mm.relative_data.clear() mm[-1, 0] = m prepared = mm.prepare("") assert prepared.is_rendering_copy assert len(mm.data) == 0 and len(prepared.data) == 1 assert prepared.data[9, 0] is m mm[-1, -10] = m prepared = mm.prepare("") assert prepared.data[9, 0] == [m, m]
def test_styled_sequence_can_handle_pretransformers(): sc, sh, text_plane = styled_text() msg = "0123456789" tt = TM.Transformer( foreground=lambda pos: TM.Color((pos[0] * 25 % 256, 0, 0)), background=lambda pos: TM.Color((0, 0, (255 - pos[0] * 25) % 256)), ) aa = StyledSequence(msg, {0: TM.Mark(attributes={"pretransformer": tt})}, text_plane) aa.render() sc.update() yield None assert sc.data[0, 0].foreground == TM.Color((0, 0, 0)) assert sc.data[0, 0].background == TM.Color((0, 0, 255)) assert sc.data[9, 0].foreground == TM.Color((225, 0, 0)) assert sc.data[9, 0].background == TM.Color((0, 0, 30))
def test_styled_text_transformers_inline_end_markup_dont_turn_off_location_based_mark_when_both_are_defined_as_string( ): sc, sh, text_plane = styled_text() sc.text.transformers_map["red"] = TM.Transformer( foreground=lambda: TM.Color("red")) sc.text.transformers_map["blue"] = TM.Transformer( background=lambda: TM.Color("blue")) sc.text[1].marks[3, 0] = TM.Mark(attributes={"pretransformer": "blue"}) sc.text[1][0, 0] = "[transformer: red]012345[/transformer]6789" sc.update() yield None assert sc.data[0, 0].foreground == TM.Color("red") assert sc.data[3, 0].foreground == TM.Color("red") assert sc.data[3, 0].background == TM.Color("blue") assert sc.data[6, 0].foreground == TM.values.DEFAULT_FG assert sc.data[6, 0].background == TM.Color("blue")
def test_markmap_works(): sh = TM.shape((10, 10)) m = TM.Mark() sh.text[1].marks[5, 5] = m assert sh.text[1].marks[5, 5] is m