/+junk/pygooglechart-py3k

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/%2Bjunk/pygooglechart-py3k

« back to all changes in this revision

Viewing changes to test/test.py

  • Committer: gak
  • Date: 2009-03-15 04:46:13 UTC
  • Revision ID: git-v1:f2cc79f0db08252c20746a0fd6c659cb981aac2d
Fixed a deprecation warning

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
sys.path.insert(0, ROOT)
12
12
 
13
13
import pygooglechart as gc
14
 
from pygooglechart import NoDataGivenException
15
14
 
16
15
 
17
16
class TestBase(unittest.TestCase):
21
20
        # All tests require warnings to be raised
22
21
        self.raise_warnings(True)
23
22
 
 
23
        self.temp_image = 'temp.png'
 
24
 
 
25
    def tearDown(self):
 
26
        if os.path.exists(self.temp_image):
 
27
            os.unlink(self.temp_image)
 
28
 
24
29
    def raise_warnings(self, rw):
25
30
        gc._reset_warnings()
26
31
 
106
111
        self.assertChartURL(chart.get_url(), \
107
112
            '?cht=lc&chs=300x100&chd=e:AAMzZm__zM')
108
113
 
 
114
 
109
115
class TestQRChart(TestBase):
110
116
 
111
117
    def assertQRImage(self, chart, text):
115
121
            print 'PyQrCodec not installed. Can not test QR code image'
116
122
            return
117
123
 
118
 
        fn = 'temp.png'
119
 
        chart.download(fn)
120
 
        status, string = PyQrcodec.decode(fn)
 
124
        chart.download(self.temp_image)
 
125
        status, string = PyQrcodec.decode(self.temp_image)
121
126
        self.assertTrue(status)
122
127
        self.assertEquals(text, string)
123
128
 
136
141
 
137
142
    def test_no_data(self):
138
143
        chart = gc.QRChart(100, 100)
139
 
        self.assertRaises(NoDataGivenException, chart.get_url)
 
144
        self.assertRaises(gc.NoDataGivenException, chart.get_url)
140
145
 
141
146
    def test_validate_image(self):
142
147
        text = 'Hello World'
146
151
        self.assertQRImage(chart, text)
147
152
 
148
153
    def test_validate_utf8(self):
149
 
        text = 'こんにちは世界'  # Hello world in Japanese UTF8
 
154
        text = 'こんにちは世界'  # Hello world in Japanese UTF-8
150
155
        chart = gc.QRChart(100, 100)
151
156
        chart.add_data(text)
152
157
        chart.set_ec('H', 0)
153
158
        self.assertQRImage(chart, text)
154
159
 
155
 
    def test_validate_shift_jis(self):
156
 
        # XXX: It looks like PyQrcodec doesn't do shift_jis?
157
 
        text = unicode('こんにちは世界', 'utf-8').encode('shift_jis')
158
 
        chart = gc.QRChart(100, 100)
159
 
        chart.add_data(text)
160
 
        chart.set_ec('H', 0)
161
 
        chart.set_encoding('Shift_JIS')
162
 
        self.assertChartURL(chart.get_url(), \
163
 
            '?cht=qr&chs=100x100&chl=%82%B1%82%F1%82%C9' \
164
 
            '%82%BF%82%CD%90%A2%8AE&choe=Shift_JIS&chld=H|0')
165
 
        chart.download('temp.png')
166
 
 
167
 
 
168
160
class TestGrammar(TestBase):
169
161
 
170
162
    types = ('Venn', 'GroupedHorizontalBar', 'GoogleOMeter', 'Scatter',