File: test_clock_val_parser.py

package info (click to toggle)
svgwrite 1.3.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid
  • size: 2,092 kB
  • sloc: python: 12,603; makefile: 117; sh: 5
file content (70 lines) | stat: -rw-r--r-- 2,320 bytes parent folder | download | duplicates (2)
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
#!/usr/bin/env python
#coding:utf-8
# Author:  mozman --<mozman@gmx.at>
# Purpose: test clock_val_parser
# Created: 03.11.2010
# Copyright (C) 2010, Manfred Moitzi
# License: MIT License

import sys
import unittest
import pyparsing as pp

from svgwrite.data.svgparser import build_clock_val_parser
from svgwrite.data.svgparser import build_wall_clock_val_parser

class TestClockValParser(unittest.TestCase):
    clock_val_parser = build_clock_val_parser()

    def is_valid(self, value):
        try:
            self.clock_val_parser.parseString(value, parseAll=True)
            return True
        except pp.ParseException:
            return False

    def test_full_clock_values(self):
        self.assertTrue(self.is_valid("02:30:03"))
        self.assertTrue(self.is_valid("01:00:00"))
        self.assertTrue(self.is_valid("50:00:10.25"))

    def test_partial_clock_values(self):
        self.assertTrue(self.is_valid("02:33"))
        self.assertTrue(self.is_valid("00:10.5"))

    def test_time_count_values(self):
        self.assertTrue(self.is_valid("3.2h"))
        self.assertTrue(self.is_valid("45min"))
        self.assertTrue(self.is_valid("30s"))
        self.assertTrue(self.is_valid("5ms"))
        self.assertTrue(self.is_valid("12.467"))

class TestWallClockValParser(unittest.TestCase):
    wallclock_parser = build_wall_clock_val_parser()

    def is_valid(self, value):
        try:
            self.wallclock_parser.parseString(value, parseAll=True)
            return True
        except pp.ParseException:
            return False

    def test_date_plus_hhmm(self):
        # Complete date plus hours and minutes:
        # YYYY-MM-DDThh:mmTZD (e.g. 1997-07-16T19:20+01:00)
        self.assertTrue(self.is_valid("1997-07-16T19:20+01:00"))

    def test_date_plus_hhmmss(self):
        # Complete date plus hours, minutes and seconds:
        # YYYY-MM-DDThh:mm:ssTZD (e.g. 1997-07-16T19:20:30+01:00)
        self.assertTrue(self.is_valid("1997-07-16T19:20:30+01:00"))

    def test_date_plus_hhmmss_frac(self):
        # Complete date plus hours, minutes, seconds and a decimal fraction of a second
        # YYYY-MM-DDThh:mm:ss.sTZD (e.g. 1997-07-16T19:20:30.45+01:00)
        self.assertTrue(self.is_valid("1997-07-16T19:20:30.45+01:00"))



if __name__=='__main__':
    unittest.main()