source: exist/branches/proglue_production_rev4605_xquery4884/python/ndgutilstests/models/testutilities.py @ 4886

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/exist/branches/proglue_production_rev4605_xquery4884/python/ndgutilstests/models/testutilities.py@4886
Revision 4886, 3.9 KB checked in by sdonegan, 10 years ago (diff)

Creating operational branch for ndgUtils as used on proglue

Line 
1'''
2A test class for the Utilities module.
3
4C Byrom Jun 2008
5Tessella
6'''
7import unittest
8import ndgUtils.models.utilities as utilities
9
10class testUtilities(unittest.TestCase):
11   
12    def setUp(self):
13        '''
14        set up data used in the tests.
15        '''
16
17    def testGetISO8601Date(self):
18        date = utilities.getISO8601Date('2007-02-16 23:14:49.781801+00')
19        self.assertEqual("2007-02-16T23:14:49Z", date)
20
21    def testGetISO8601DateWithT(self):
22        date = utilities.getISO8601Date('2007-02-16T23:14:49.781801+00')
23        self.assertEqual("2007-02-16T23:14:49Z", date)
24
25    def testGetISO8601DateWithZ(self):
26        date = utilities.getISO8601Date('2007-02-16 23:14:49.781801+00Z')
27        self.assertEqual("2007-02-16T23:14:49Z", date)
28       
29    def testFormatDateYYYYMMDD(self):
30        date = utilities.formatDateYYYYMMDD('2007-02-16 23:14:49.781801+00Z')
31        self.assertEqual("2007-02-16", date)
32       
33    def testInvalidFormatDateYYYYMMDD(self):
34        self.assertRaises(ValueError, utilities.formatDateYYYYMMDD, '2dd007-02-16 23:14:49.781801+00Z')
35
36    def testGetTripleData(self):
37        tripleString = "1|2|3"
38        data = utilities.getTripleData(tripleString)
39        self.assertEqual("1", data[0])
40        self.assertEqual("2", data[1])
41        self.assertEqual("3", data[2])
42
43    def testGetTripleDataOneVal(self):
44        tripleString = "1"
45        data = utilities.getTripleData(tripleString)
46        self.assertEqual("1", data[0])
47        self.assertEqual("", data[1])
48        self.assertEqual("", data[2])
49
50    def testGetTripleDataOneValWithDelimiter(self):
51        tripleString = "1|"
52        data = utilities.getTripleData(tripleString)
53        self.assertEqual("1", data[0])
54        self.assertEqual("", data[1])
55        self.assertEqual("", data[2])
56
57    def testGetTripleDataTwoVals(self):
58        tripleString = "1|2"
59        data = utilities.getTripleData(tripleString)
60        self.assertEqual("1", data[0])
61        self.assertEqual("2", data[1])
62        self.assertEqual("", data[2])
63       
64
65    def testGetTripleDataWithSpaces(self):
66        tripleString = " 1  | 2 |  3  "
67        data = utilities.getTripleData(tripleString)
68        self.assertEqual("1", data[0])
69        self.assertEqual("2", data[1])
70        self.assertEqual("3", data[2])
71
72    def testTidyUpParametersRemoveMonth(self):
73        janString = "JANUARY"
74        params = "TEMP01"
75        tidiedParams = utilities.tidyUpParameters(janString + " " + params)
76        self.assertEqual(params, tidiedParams)
77
78    def testTidyUpParametersWithTriple(self):
79        params = "TEMP01 | http://blah.org | TEMP"
80        tidiedParams = utilities.tidyUpParameters(params)
81        self.assertEqual(params, tidiedParams)
82
83    def testTidyUpParametersWithTripleAndThingsToTidy(self):
84        params = "TEMP   01 & | http://blah.org/&fred=t | temp > 6 <  ice  "
85        tidiedParams = utilities.tidyUpParameters(params)
86        self.assertEqual("TEMP 01 &AMP; | http://blah.org/&amp;fred=t | TEMP &GT; 6 &LT; ICE", tidiedParams)
87
88    def testTidyUpParametersRemoveSpaces(self):
89        params = "TEMP          01"
90        tidiedParams = utilities.tidyUpParameters(" " + params + "    ")
91        self.assertEqual("TEMP 01", tidiedParams)
92
93    def testTidyUpParametersUpperCase(self):
94        params = "temp01"
95        tidiedParams = utilities.tidyUpParameters(" " + params + "    ")
96        self.assertEqual("TEMP01", tidiedParams)
97
98    def testTidyUpParametersRemoveMonthRemoveSpacesUpperCase(self):
99        params = "temp   01   JANUARY"
100        tidiedParams = utilities.tidyUpParameters(" " + params + "    ")
101        self.assertEqual("TEMP 01", tidiedParams)
102
103    def testEscapeSpecialCharacters(self):
104        str = ">blah< &"
105        escapedStr = utilities.escapeSpecialCharacters(str)
106        self.assertEqual("&gt;blah&lt; &amp;", escapedStr)
107
108if __name__ == '__main__':
109
110    unittest.main()
Note: See TracBrowser for help on using the repository browser.