File: test_tiny12_typechecker.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 (60 lines) | stat: -rw-r--r-- 2,584 bytes parent folder | download | duplicates (3)
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
#!/usr/bin/env python
#coding:utf-8
# Author:  mozman --<mozman@gmx.at>
# Purpose: test tiny12 typechecker
# Created: 08.10.2010
# Copyright (C) 2010, Manfred Moitzi
# License: MIT License

import sys
import unittest

from svgwrite.data.typechecker import Tiny12TypeChecker

class TestTiny12TypeChecker(unittest.TestCase):
    def setUp(self):
        self.checker = Tiny12TypeChecker()

    def test_is_bool(self):
        self.assertTrue(self.checker.is_boolean(True))
        self.assertTrue(self.checker.is_boolean(False))
        self.assertTrue(self.checker.is_boolean(' true '))
        self.assertTrue(self.checker.is_boolean(' false '))
        self.assertTrue(self.checker.is_boolean('True'))
        self.assertTrue(self.checker.is_boolean('False'))
    def test_is_not_bool(self):
        self.assertFalse(self.checker.is_boolean(1))
        self.assertFalse(self.checker.is_boolean(0))
        self.assertFalse(self.checker.is_boolean((1, 1)))
        self.assertFalse(self.checker.is_boolean(dict(a=1, b=1)))

    def test_is_number(self):
        """ Integer and Float, also as String '100' or '3.1415'. """
        # big numbers only valid for full profile
        self.assertTrue(self.checker.is_number(10000))
        self.assertTrue(self.checker.is_number(-10000))
        self.assertTrue(self.checker.is_number(3.141592))
        self.assertTrue(self.checker.is_number('10000'))
        self.assertTrue(self.checker.is_number('-10000'))
        self.assertTrue(self.checker.is_number('3.141592'))
    def test_is_not_number(self):
        self.assertFalse(self.checker.is_number( (1,2) ))
        self.assertFalse(self.checker.is_number('manfred'))
        self.assertFalse(self.checker.is_number( dict(a=1, b=2) ))
        self.assertFalse(self.checker.is_number(100000))
        self.assertFalse(self.checker.is_number(-100000))
        self.assertFalse(self.checker.is_number('100000'))
        self.assertFalse(self.checker.is_number('-100000'))

    def test_is_focus(self):
        for focus in  [' nav-next ', ' nav-prev ', ' nav-up ', ' nav-down ',
                       ' nav-left ', ' nav-right ', ' nav-up-left ', ' nav-up-right ',
                       'nav-down-left', 'nav-down-right']:
            self.assertTrue(self.checker.is_focus(focus))
    def test_is_not_focus(self):
        self.assertFalse(self.checker.is_focus('mozman'))
        self.assertFalse(self.checker.is_focus(1))
        self.assertFalse(self.checker.is_focus((1,1)))

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