File: test_basics.py

package info (click to toggle)
pygml 0.2.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 420 kB
  • sloc: python: 5,157; makefile: 15; sh: 5
file content (82 lines) | stat: -rw-r--r-- 2,380 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import pytest

from pygml.basics import (
    parse_coordinates, parse_poslist, parse_pos, swap_coordinate_xy,
    swap_coordinates_xy
)


def test_parse_coordinates():
    # basic test
    result = parse_coordinates('12.34 56.7,89.10 11.12')
    assert result == [(12.34, 56.7), (89.10, 11.12)]

    # ignore some whitespace
    result = parse_coordinates('12.34 56.7,  89.10 11.12')
    assert result == [(12.34, 56.7), (89.10, 11.12)]

    # custom cs
    result = parse_coordinates('12.34 56.7;89.10 11.12', cs=';')
    assert result == [(12.34, 56.7), (89.10, 11.12)]

    # custom ts
    result = parse_coordinates('12.34:56.7,89.10:11.12', ts=':')
    assert result == [(12.34, 56.7), (89.10, 11.12)]

    # custom cs/ts
    result = parse_coordinates('12.34:56.7;89.10:11.12', cs=';', ts=':')
    assert result == [(12.34, 56.7), (89.10, 11.12)]

    # custom cs/ts and decimal
    result = parse_coordinates(
        '12,34:56,7;89,10:11,12', cs=';', ts=':', decimal=','
    )
    assert result == [(12.34, 56.7), (89.10, 11.12)]


def test_parse_poslist():
    # basic test
    result = parse_poslist('12.34 56.7 89.10 11.12')
    assert result == [(12.34, 56.7), (89.10, 11.12)]

    # 3D coordinates
    result = parse_poslist('12.34 56.7 89.10 11.12 13.14 15.16', dimensions=3)
    assert result == [(12.34, 56.7, 89.10), (11.12, 13.14, 15.16)]

    # exception on wrong dimensionality
    with pytest.raises(ValueError):
        parse_poslist('12.34 56.7 89.10 11.12', dimensions=3)


def test_parse_pos():
    # basic test
    result = parse_pos('12.34 56.7')
    assert result == (12.34, 56.7)

    # 3D pos
    result = parse_pos('12.34 56.7 89.10')
    assert result == (12.34, 56.7, 89.10)


def test_swap_coordinate_xy():
    # basic test
    swapped = swap_coordinate_xy((12.34, 56.7))
    assert swapped == (56.7, 12.34)

    # 3D coords, only X/Y are to be swapped
    swapped = swap_coordinate_xy((12.34, 56.7, 89.10))
    assert swapped == (56.7, 12.34, 89.10)


def test_swap_coordinates_xy():
    # basic test
    swapped = swap_coordinates_xy(
        [(12.34, 56.7), (89.10, 11.12)]
    )
    assert swapped == [(56.7, 12.34), (11.12, 89.10)]

    # 3D coords, only X/Y are to be swapped
    swapped = swap_coordinates_xy(
        [(12.34, 56.7, 89.10), (11.12, 13.14, 15.16)]
    )
    assert swapped == [(56.7, 12.34, 89.10), (13.14, 11.12, 15.16)]