/+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: 2008-08-23 07:31:12 UTC
  • Revision ID: git-v1:d25980565dd2640f4d700e85f0fab48a685c8ed7
Fixed bug where the module would download twice (#7) (Evan Lezar)

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
14
15
 
15
16
 
16
17
class TestBase(unittest.TestCase):
20
21
        # All tests require warnings to be raised
21
22
        self.raise_warnings(True)
22
23
 
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
 
 
29
24
    def raise_warnings(self, rw):
30
25
        gc._reset_warnings()
31
26
 
111
106
        self.assertChartURL(chart.get_url(), \
112
107
            '?cht=lc&chs=300x100&chd=e:AAMzZm__zM')
113
108
 
114
 
 
115
109
class TestQRChart(TestBase):
116
110
 
117
111
    def assertQRImage(self, chart, text):
121
115
            print 'PyQrCodec not installed. Can not test QR code image'
122
116
            return
123
117
 
124
 
        chart.download(self.temp_image)
125
 
        status, string = PyQrcodec.decode(self.temp_image)
 
118
        fn = 'temp.png'
 
119
        chart.download(fn)
 
120
        status, string = PyQrcodec.decode(fn)
126
121
        self.assertTrue(status)
127
122
        self.assertEquals(text, string)
128
123
 
141
136
 
142
137
    def test_no_data(self):
143
138
        chart = gc.QRChart(100, 100)
144
 
        self.assertRaises(gc.NoDataGivenException, chart.get_url)
 
139
        self.assertRaises(NoDataGivenException, chart.get_url)
145
140
 
146
141
    def test_validate_image(self):
147
142
        text = 'Hello World'
151
146
        self.assertQRImage(chart, text)
152
147
 
153
148
    def test_validate_utf8(self):
154
 
        text = 'こんにちは世界'  # Hello world in Japanese UTF-8
 
149
        text = 'こんにちは世界'  # Hello world in Japanese UTF8
155
150
        chart = gc.QRChart(100, 100)
156
151
        chart.add_data(text)
157
152
        chart.set_ec('H', 0)
158
153
        self.assertQRImage(chart, text)
159
154
 
 
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
 
160
168
class TestGrammar(TestBase):
161
169
 
162
170
    types = ('Venn', 'GroupedHorizontalBar', 'GoogleOMeter', 'Scatter',