예제 #1
0
def test_some_setters(A, B):
    """Check thickness and label_mask setters."""
    s = LineSegment(A, B)
    with pytest.raises(ValueError) as excinfo:
        s.thickness = 'undefined'
    assert str(excinfo.value) == 'Incorrect thickness value: \'undefined\'. ' \
        'Available values belong to: {}.'.format(THICKNESS_VALUES)
    with pytest.raises(ValueError) as excinfo:
        s.label_winding = 'undefined'
    assert str(excinfo.value) == "label_winding must be 'clockwise' or " \
        "'anticlockwise'; found 'undefined' instead."
    with pytest.raises(ValueError) as excinfo:
        s.label_mask = 'undefined'
    assert str(excinfo.value).startswith('label_mask must be in '
                                         '[None, \' \', \'?\']; '
                                         'got \'undefined\' instead.')
    s.label_mask = '?'
    assert s.label_mask == '?'
    with pytest.raises(TypeError) as excinfo:
        s.mark_scale = 'undefined'
    assert str(excinfo.value).startswith('The LineSegment\'s mark\'s scale '
                                         'must be a number.')
    with pytest.raises(TypeError) as excinfo:
        s = LineSegment(A, B, locked_label=1)
    assert str(excinfo.value) == 'Expected bool type for \'locked_label\' '\
        'keyword argument. Found <class \'int\'>.'
    s = LineSegment(A, B, locked_label=True)
    with pytest.raises(TypeError) as excinfo:
        s.label = '4.5 cm'
    assert str(excinfo.value) == 'This LineSegments\' label is locked. '\
        'If you\'re using this LineSegment embedded in another '\
        'object (e.g. a Polygon), please use the setup_labels() method of '\
        'this object. Otherwise, first explicitely unlock the LineSegment.'
예제 #2
0
def test_drawing_marked_linesegment(A, F):
    """Check drawing is correct."""
    ls = LineSegment(A, F, mark='//')
    assert ls.drawn == r"""
\begin{tikzpicture}
% Declare Points
\coordinate (A) at (0,0);
\coordinate (F) at (4,0);

% Draw Points
\draw (A) node[scale=0.67] {$\times$};
\draw (F) node[scale=0.67] {$\times$};

% Draw Line Segment
\draw[thick] (A) -- (F) node[midway, sloped, scale=0.5] {//};

% Label Points
\draw (A) node[left] {A};
\draw (F) node[right] {F};
\end{tikzpicture}
"""
    ls.label = '4 cm'
    assert ls.drawn == (r"""
\begin{tikzpicture}
% Declare Points
\coordinate (A) at (0,0);
\coordinate (F) at (4,0);

% Draw Points
\draw (A) node[scale=0.67] {$\times$};
\draw (F) node[scale=0.67] {$\times$};

% Draw Line Segment
\draw[thick] (A) -- (F) node[midway, below, sloped] {4 cm} """
                        r"""node[midway, sloped, scale=0.5] {//};

% Label Points
\draw (A) node[left] {A};
\draw (F) node[right] {F};
\end{tikzpicture}
""")
예제 #3
0
def test_drawing_with_linesegment_labels(A, B, E):
    """Check drawing is correct."""
    ls = LineSegment(A, E, label='4 cm')
    assert ls.drawn == r"""
\begin{tikzpicture}
% Declare Points
\coordinate (A) at (0,0);
\coordinate (E) at (1,0);

% Draw Points
\draw (A) node[scale=0.67] {$\times$};
\draw (E) node[scale=0.67] {$\times$};

% Draw Line Segment
\draw[thick] (A) -- (E) node[midway, below, sloped] {4 cm};

% Label Points
\draw (A) node[left] {A};
\draw (E) node[right] {E};
\end{tikzpicture}
"""
    ls.label = Number(6, unit='cm')
    assert ls.label == r'\SI{6}{cm}'
    assert ls.label_value == Number(6, unit='cm')
    assert ls.drawn == r"""
\begin{tikzpicture}
% Declare Points
\coordinate (A) at (0,0);
\coordinate (E) at (1,0);

% Draw Points
\draw (A) node[scale=0.67] {$\times$};
\draw (E) node[scale=0.67] {$\times$};

% Draw Line Segment
\draw[thick] (A) -- (E) node[midway, below, sloped] {\SI{6}{cm}};

% Label Points
\draw (A) node[left] {A};
\draw (E) node[right] {E};
\end{tikzpicture}
"""
    ls = LineSegment(A, E, label='4 cm', label_position='above')
    assert ls.drawn == r"""
\begin{tikzpicture}
% Declare Points
\coordinate (A) at (0,0);
\coordinate (E) at (1,0);

% Draw Points
\draw (A) node[scale=0.67] {$\times$};
\draw (E) node[scale=0.67] {$\times$};

% Draw Line Segment
\draw[thick] (A) -- (E) node[midway, above, sloped] {4 cm};

% Label Points
\draw (A) node[left] {A};
\draw (E) node[right] {E};
\end{tikzpicture}
"""
    ls = LineSegment(E, A, label='4 cm')
    assert ls.drawn == r"""
\begin{tikzpicture}
% Declare Points
\coordinate (E) at (1,0);
\coordinate (A) at (0,0);

% Draw Points
\draw (E) node[scale=0.67] {$\times$};
\draw (A) node[scale=0.67] {$\times$};

% Draw Line Segment
\draw[thick] (E) -- (A) node[midway, above, sloped] {4 cm};

% Label Points
\draw (E) node[right] {E};
\draw (A) node[left] {A};
\end{tikzpicture}
"""
    ls = LineSegment(E, B, label='4 cm')
    assert ls.drawn == r"""
\begin{tikzpicture}
% Declare Points
\coordinate (E) at (1,0);
\coordinate (B) at (1,1);

% Draw Points
\draw (E) node[scale=0.67] {$\times$};
\draw (B) node[scale=0.67] {$\times$};

% Draw Line Segment
\draw[thick] (E) -- (B) node[midway, below, sloped] {4 cm};

% Label Points
\draw (E) node[below] {E};
\draw (B) node[above] {B};
\end{tikzpicture}
"""
    ls = LineSegment(A, E, label='4 cm', label_winding='clockwise')
    assert ls.drawn == r"""
\begin{tikzpicture}
% Declare Points
\coordinate (A) at (0,0);
\coordinate (E) at (1,0);

% Draw Points
\draw (A) node[scale=0.67] {$\times$};
\draw (E) node[scale=0.67] {$\times$};

% Draw Line Segment
\draw[thick] (A) -- (E) node[midway, above, sloped] {4 cm};

% Label Points
\draw (A) node[left] {A};
\draw (E) node[right] {E};
\end{tikzpicture}
"""
    ls = LineSegment(E, A, label='4 cm', label_winding='clockwise')
    assert ls.drawn == r"""
\begin{tikzpicture}
% Declare Points
\coordinate (E) at (1,0);
\coordinate (A) at (0,0);

% Draw Points
\draw (E) node[scale=0.67] {$\times$};
\draw (A) node[scale=0.67] {$\times$};

% Draw Line Segment
\draw[thick] (E) -- (A) node[midway, below, sloped] {4 cm};

% Label Points
\draw (E) node[right] {E};
\draw (A) node[left] {A};
\end{tikzpicture}
"""
    ls = LineSegment(E,
                     A,
                     label='4 cm',
                     thickness=None,
                     label_winding='clockwise')
    assert ls.drawn == r"""
\begin{tikzpicture}
% Declare Points
\coordinate (E) at (1,0);
\coordinate (A) at (0,0);

% Draw Points
\draw (E) node[scale=0.67] {$\times$};
\draw (A) node[scale=0.67] {$\times$};

% Draw Line Segment
\draw (E) -- (A) node[midway, below, sloped] {4 cm};

% Label Points
\draw (E) node[right] {E};
\draw (A) node[left] {A};
\end{tikzpicture}
"""
    ls = LineSegment(E,
                     A,
                     label='4 cm',
                     label_winding='clockwise',
                     label_mask='?')
    assert ls.drawn == r"""
\begin{tikzpicture}
% Declare Points
\coordinate (E) at (1,0);
\coordinate (A) at (0,0);

% Draw Points
\draw (E) node[scale=0.67] {$\times$};
\draw (A) node[scale=0.67] {$\times$};

% Draw Line Segment
\draw[thick] (E) -- (A) node[midway, below, sloped] {?};

% Label Points
\draw (E) node[right] {E};
\draw (A) node[left] {A};
\end{tikzpicture}
"""
    ls = LineSegment(E,
                     A,
                     label='4 cm',
                     label_winding='clockwise',
                     label_scale='0.67')
    assert ls.drawn == r"""