File: TestUtils.py

package info (click to toggle)
straw 0.27-0.1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 1,972 kB
  • ctags: 2,318
  • sloc: python: 13,450; ansic: 107; makefile: 21
file content (38 lines) | stat: -rwxr-xr-x 1,198 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
import sys
import unittest
sys.path.insert(0, '../src/lib')
import utils

class UtilsTestCase(unittest.TestCase):

    def testFormatDateBadEncoding(self):
        # Bugzilla 145513
        encoding = "en_US.ISO8859-1"
        format = "%A"
        time = (2004, 8, 5, 20, 29, 59, 3, 218, 0)
        try:
            utils.format_date(time, format, encoding)
        except Exception, ex:
            self.fail("format_date: %s" % str(ex))

    def testURLlocation(self):
        url = "http://www.amazon.com/gp/aws/sdk/103-9053546-3314261"
        self.assertEqual("http://www.amazon.com", utils.get_url_location(url))

    def testReadText(self):
        text = "Blah &gt;foo&lt; <p>bar</p>"
        t = utils.read_text(text, 60)
        self.assertEqual(t, "Blah >foo< bar")

    def testCompleteUrl(self):
        tlist = [("images/foo.jpg","http://blah.com","http://blah.com/images/foo.jpg"),
                 ("/images/foo.jpg","http://b.com","http://b.com/images/foo.jpg")]
        for u,b,r in tlist:
            self.assertEqual(r,utils.complete_url(u,b))

def suite():
    suite = unittest.makeSuite(UtilsTestCase, 'test')
    return suite

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