コード例 #1
0
class TestRectangularCoords(object):
    def test_misc(self):
        x, y = TikzRectCoord(3, -4)
        assert x == 3 and y == -4
        a = TikzRectCoord.from_str('++(3,4)')
        assert a.relative is True
        assert a != TikzRectCoord(3, 4)

    ###############
    equality_cases = [(rec_11 + rec_11, TikzRectCoord(2, 2)),
                      (rec_11 + (1, 1), TikzRectCoord(2, 2)),
                      (rec_11 - (-1, 5), TikzRectCoord(2, -4)),
                      ((-1, 5) - rec_11, TikzRectCoord(-2, 4)),
                      (rec_11, (1, 1)),
                      (TikzRectCoord.from_str("(1,1)"), rec_11)]

    @pytest.mark.parametrize('actual,expected', equality_cases)
    def test_equality_checks(self, actual, expected):
        assert actual == expected

    ###############
    fail_cases = [
        (lambda: TikzRectCoord(0, 0) + 2, raises(TypeError)),
        (lambda: TikzRectCoord.from_str("(0,0"), raises(ValueError)),
        (lambda: TikzRectCoord.from_str("(x=0,y=0)"), raises(ValueError)),
        (lambda: rec_11 == 47.5, raises(TypeError)),
        (lambda: TikzRectCoord(0, 0, relative=True) + rec_11,
         raises(ValueError)),
    ]

    @pytest.mark.parametrize("case,expectation", fail_cases)
    def test_fail_cases(self, case, expectation):
        with expectation:
            case()
コード例 #2
0
ファイル: test_paths.py プロジェクト: m-richards/pythonTikz
    def test_misc(self):
        orig_handle = (0, 0)
        rad = 1
        draw_options = TikzOptions("very thick", "->")

        a = TikzDraw([
            orig_handle + TikzRectCoord(-rad, 0), '--',
            orig_handle + TikzRectCoord(rad, 0),
            TikzNode(text=NoEscape(r"{$\Re$}"), options=['above'])
        ],
                     options=draw_options)
        b = (r'\draw[very thick,->] (-1.0,0.0) -- (1.0,0.0)'
             r' node[above] {{$\Re$}};')
        assert a.dumps() == b
コード例 #3
0
def test_node():
    """Small test since Node also gets tested in paths. Also tests inherited
    methods from TikzObject
    """
    with raises(TypeError):
        TikzNode(at='(1,1)')
    with raises(TypeError):
        TikzNode(at=(1, 2))

    a = TikzNode('s',
                 at=TikzRectCoord(1, 1),
                 options=['anchor=east'],
                 text='$x_1$')
    assert a.dumps() == r'\node[anchor=east] (s) at (1.0,1.0) {$x_1$};'
    b = TikzNode('s', at=TikzRectCoord(1, 1), options=['anchor=east'])
    assert b.dumps() == r'\node[anchor=east] (s) at (1.0,1.0) {};'
コード例 #4
0
class TestPolarCoords(object):
    equality_cases = [(pol1 + pol1, TikzRectCoord(-2, 0)),
                      (pol1 - pol1, TikzPolCoord(0, 0)),
                      (pol2 - (-1, 2), TikzRectCoord(1, -1)),
                      (TikzPolCoord.from_str('(180:1)'), pol1)]

    @pytest.mark.parametrize('actual,expected', equality_cases)
    def test_equality_checks(self, actual, expected):
        assert actual == expected

    ###############
    fail_cases = [
        (lambda: TikzPolCoord(0, 0, relative=True) + 2, raises(TypeError)),
        (lambda: TikzPolCoord.from_str("(180,0)"), raises(ValueError)),
        (lambda: TikzPolCoord(0, -5), raises(ValueError)),
    ]

    @pytest.mark.parametrize("case,expectation", fail_cases)
    def test_fail(self, case, expectation):
        with expectation:
            case()
コード例 #5
0
class TestCalcCoords(object):
    equality_cases = [
        (pol1 + pol1, TikzRectCoord(-2, 0)),
        (pol1 - pol1, TikzPolCoord(0, 0)),
        (pol2 - (-1, 2), TikzRectCoord(1, -1)),
        (TikzPolCoord.from_str('(180:1)'), pol1),
    ]

    @pytest.mark.parametrize('actual,expected', equality_cases)
    def test_equality_checks(self, actual, expected):
        assert actual == expected

    ###############
    fail_cases = [
        (lambda: calc1 + calc1, raises(TypeError)),
        (lambda: (3, 4) + calc1, raises(TypeError)),
        (lambda: calc1 - calc1, raises(TypeError)),
        (lambda: calc1 * calc1, raises(TypeError)),
        (lambda: pol1 * calc1, raises(TypeError)),
        (lambda: pol1 + calc1, raises(TypeError)),
        (lambda: pol1 - calc1, raises(TypeError)),
        (lambda: calc1 * 4, raises(TypeError)),
        (lambda: h1 - 41, raises(TypeError)),
        (lambda: h1 - (3, 2), does_not_raise()),
        (lambda: h1 + (3, 2), does_not_raise()),
        (lambda: h1 + 7, raises(TypeError)),
        (lambda: h1 + pol1, does_not_raise()),
        (lambda: h1 - pol1, does_not_raise()),
        (lambda: h1 * 5.3, does_not_raise()),
        (lambda: (3, 4) + h1, does_not_raise()),
        (lambda: (3, 4) - h1, does_not_raise()),
        (lambda: 5.3 * h1, does_not_raise()),
        (lambda: h1 * pol1, raises(TypeError)),
    ]

    @pytest.mark.parametrize("case,expectation", fail_cases)
    def test_fail(self, case, expectation):
        with expectation:
            case()
コード例 #6
0
ファイル: test_paths.py プロジェクト: m-richards/pythonTikz
class TestTikzDraw(object):
    r"""Tests a number of cases of dumps to ensure that the otherwise tested
    components are being assembled correctly. Additionally tests the parent
    TikzPath as there is only a minor difference between teh classes, namely
    the dumps method supplying \draw instead of \path

    Unfortunately, parameterised tests don't work with this class (perhaps
    due to the use of recursive repr?)
    """
    def test_misc(self):
        orig_handle = (0, 0)
        rad = 1
        draw_options = TikzOptions("very thick", "->")

        a = TikzDraw([
            orig_handle + TikzRectCoord(-rad, 0), '--',
            orig_handle + TikzRectCoord(rad, 0),
            TikzNode(text=NoEscape(r"{$\Re$}"), options=['above'])
        ],
                     options=draw_options)
        b = (r'\draw[very thick,->] (-1.0,0.0) -- (1.0,0.0)'
             r' node[above] {{$\Re$}};')
        assert a.dumps() == b


###############

    h = TikzCalcCoord(handle='h', at=TikzRectCoord(0, 3))
    h = h.get_handle()
    dumps_cases = [
        ([rec_11, 'arc', "(300:200:2)", '--', pol1], None,
         r'\draw (1.0,1.0) arc (300.0:200.0:2.0) -- (180.0:1.0);'),
        ([
            rec_11, 'rectangle', h, '-|', pol1,
            TikzNode(text='$x_1$', options='above')
        ], TikzOptions("very thick", "->", 'fill=black'),
         (r'\draw[very thick,->,fill=black] (1.0,1.0) rectangle (h) -|'
          ' (180.0:1.0) node[above] {$x_1$};')),
    ]
    #
    @pytest.mark.parametrize("path,options,expected", dumps_cases)
    def test_dumps(self, path, options, expected):
        actual = TikzDraw(path=path, options=options)
        assert actual.dumps() == expected
コード例 #7
0
 def test_misc(self):
     x, y = TikzRectCoord(3, -4)
     assert x == 3 and y == -4
     a = TikzRectCoord.from_str('++(3,4)')
     assert a.relative is True
     assert a != TikzRectCoord(3, 4)
コード例 #8
0
"""
import pytest
from pytest import raises
from pythontikz.positions import (TikzRectCoord, TikzPolCoord, TikzCalcCoord,
                                  TikzCalcScalar, _TikzCalcImplicitCoord,
                                  TikzNode)

from contextlib import contextmanager


@contextmanager
def does_not_raise():
    yield


rec_11 = TikzRectCoord(1, 1)


class TestRectangularCoords(object):
    def test_misc(self):
        x, y = TikzRectCoord(3, -4)
        assert x == 3 and y == -4
        a = TikzRectCoord.from_str('++(3,4)')
        assert a.relative is True
        assert a != TikzRectCoord(3, 4)

    ###############
    equality_cases = [(rec_11 + rec_11, TikzRectCoord(2, 2)),
                      (rec_11 + (1, 1), TikzRectCoord(2, 2)),
                      (rec_11 - (-1, 5), TikzRectCoord(2, -4)),
                      ((-1, 5) - rec_11, TikzRectCoord(-2, 4)),
コード例 #9
0
ファイル: test_paths.py プロジェクト: m-richards/pythonTikz
 def test_warning_case(self):
     with pytest.warns(UserWarning):
         TikzPathList('(0, 1)', '--', '(2, 0)', TikzRectCoord(0, 0), (3, 0))
コード例 #10
0
ファイル: test_paths.py プロジェクト: m-richards/pythonTikz
from pytest import raises
from pythontikz.common import TikzOptions
from pythontikz.paths import TikzUserPath, TikzPathList, TikzArc, TikzDraw, \
    TikzRadius
from pythontikz.positions import (TikzRectCoord, TikzPolCoord, TikzCalcCoord,
                                  TikzNode)

from contextlib import contextmanager


@contextmanager
def does_not_raise():
    yield


rec_11 = TikzRectCoord(1, 1)


class TestUserPath(object):
    """This is tested poorly, I don't use this class or the underlying tikz
    it represents
    """
    def test_misc(self):
        # necessary here because 'in' is a python keyword
        path_options = {'in': 90, 'out': 0}
        p = TikzUserPath('edge', TikzOptions('-latex', **path_options))
        assert p.dumps() == "edge[-latex,in=90,out=0]"


pol1 = TikzPolCoord(180, 1)
pol2 = TikzPolCoord(90, 1)