source: TI02-CSML/trunk/services/3rdParty/GeoTypes-0.6.0/tests/Point_Test.py @ 2194

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI02-CSML/trunk/services/3rdParty/GeoTypes-0.6.0/tests/Point_Test.py@2194
Revision 2194, 2.9 KB checked in by lawrence, 13 years ago (diff)

Adding various specs and 3rd party code of interest for the CSML
services development.

Line 
1
2################################################################################
3# Copyright (c) QinetiQ Plc 2003
4#
5# Licensed under the LGPL. For full license details see the LICENSE file.
6################################################################################
7
8import unittest
9
10import TestConfig
11
12import os
13if not os.environ.get('USECOVERAGE') == '1':
14    import _Point
15    from _Point import *
16
17
18class PointTest(unittest.TestCase):   
19
20    def testEqualities(self):
21        p = Point()
22        q = Point()
23        assert p != None
24        assert None != p
25        assert p != 0
26        assert p != {}
27        assert p != []
28        assert p == q
29       
30    def testPoint(self):
31        """
32        Check that the basic Point class works
33        """
34
35        p = Point()
36        assert p.getX() == 0.0
37        assert p.getY() == 0.0
38        assert p.__str__() == "'(0.000000,0.000000)'"
39
40        p = Point("(1.0,2.0)")
41        assert p.getX() == 1.0
42        assert p.getY() == 2.0
43        assert p.__str__() == "'(1.000000,2.000000)'"
44
45        p.fromString("(3.0,4.0)")
46        assert p.getX() == 3.0
47        assert p.getY() == 4.0
48        assert p.__str__() == "'(3.000000,4.000000)'"
49
50        p.setX(5.0)
51        assert p.__str__() == "'(5.000000,4.000000)'"
52       
53        p.setY(6.0)
54        assert p.__str__() == "'(5.000000,6.000000)'"       
55
56        assert p.__repr__() == "(5.000000,6.000000)"
57
58        p1 = Point("(1.0,2.0)")
59        p2 = Point("(1.0,2.0)")
60
61        assert p1 == p2
62
63        p1 = Point("(1.0,2.0)")
64        p2 = Point("(1.0,3.0)")
65       
66        assert p1 != p2
67
68
69    def testFactories(self):
70
71        p = pointFromValues(1.0,2.0)
72        assert p.getX() == 1.0
73        assert p.getY() == 2.0
74        assert p.__str__() == "'(1.000000,2.000000)'"
75
76        p = pointFromSequence((1.0,2.0))
77        assert p.getX() == 1.0
78        assert p.getY() == 2.0
79        assert p.__str__() == "'(1.000000,2.000000)'"
80       
81    def testzzz_CoverageAssertion(self):
82            try:
83                coverage.stop()
84            except:
85                return 1
86
87            x = coverage.analysis(_Point)
88            assert x[2]==[], "Coverage is less than 100%"
89
90
91def testSuite():
92    return unittest.makeSuite(PointTest,'test')
93
94if __name__ == "__main__":
95    if os.environ.get('USECOVERAGE') == '1':
96        try:
97            import coverage
98            coverage.erase()
99            coverage.start()
100            COVERAGE = 1
101            import _Point
102            from _Point import *
103
104        except:
105            print "Error setting up coverage checking"
106            COVERAGE = 0
107    else:
108        COVERAGE = 0
109
110    if os.environ.get('USEPYCHECK') == '1':
111        try:
112            import pychecker.checker
113        except:
114            print "Pychecker not installed on this machine"
115
116    unittest.TextTestRunner().run(testSuite())
117
118    if COVERAGE:
119        coverage.stop()
120        x = coverage.analysis(_Point)
121        print "\n"
122        coverage.report(_Point)
Note: See TracBrowser for help on using the repository browser.