Merge lp:~cjwatson/storm/py3-tests-prepare-strings into lp:storm

Proposed by Colin Watson
Status: Merged
Merged at revision: 517
Proposed branch: lp:~cjwatson/storm/py3-tests-prepare-strings
Merge into: lp:storm
Diff against target: 337 lines (+45/-43)
6 files modified
tests/databases/base.py (+2/-2)
tests/databases/postgres.py (+6/-4)
tests/expr.py (+16/-16)
tests/properties.py (+5/-5)
tests/store/base.py (+10/-10)
tests/variables.py (+6/-6)
To merge this branch: bzr merge lp:~cjwatson/storm/py3-tests-prepare-strings
Reviewer Review Type Date Requested Status
Kristian Glass (community) Approve
Storm Developers Pending
Review via email: mp+371165@code.launchpad.net

Commit message

Be more explicit about string types in tests.

Description of the change

The distinction between '...' and b'...' matters in Python 3, so be explicit where it matters in tests, in preparation for corresponding changes to Storm itself.

To post a comment you must log in.
Revision history for this message
Kristian Glass (doismellburning) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'tests/databases/base.py'
2--- tests/databases/base.py 2019-06-07 17:14:33 +0000
3+++ tests/databases/base.py 2019-08-11 11:34:17 +0000
4@@ -275,7 +275,7 @@
5
6 def test_binary(self):
7 """Ensure database works with high bits and embedded zeros."""
8- value = "\xff\x00\xff\x00"
9+ value = b"\xff\x00\xff\x00"
10 self.connection.execute("INSERT INTO bin_test (b) VALUES (?)",
11 (value,))
12 result = self.connection.execute("SELECT b FROM bin_test")
13@@ -290,7 +290,7 @@
14 variable = RawStrVariable()
15 # If the following doesn't raise a TypeError we're good.
16 result.set_variable(variable, result.get_one()[0])
17- self.assertEquals(variable.get(), "Value")
18+ self.assertEquals(variable.get(), b"Value")
19
20 def test_order_by_group_by(self):
21 self.connection.execute("INSERT INTO test VALUES (100, 'Title 10')")
22
23=== modified file 'tests/databases/postgres.py'
24--- tests/databases/postgres.py 2019-06-05 11:41:07 +0000
25+++ tests/databases/postgres.py 2019-08-11 11:34:17 +0000
26@@ -147,11 +147,12 @@
27 self.assertEquals(encoding.upper(), "UTF8")
28
29 def test_unicode(self):
30- raw_str = "\xc3\xa1\xc3\xa9\xc3\xad\xc3\xb3\xc3\xba"
31+ raw_str = b"\xc3\xa1\xc3\xa9\xc3\xad\xc3\xb3\xc3\xba"
32 uni_str = raw_str.decode("UTF-8")
33
34 connection = self.database.connect()
35- connection.execute("INSERT INTO test VALUES (1, '%s')" % raw_str)
36+ connection.execute(
37+ (b"INSERT INTO test VALUES (1, '%s')" % raw_str).decode("UTF-8"))
38
39 result = connection.execute("SELECT title FROM test WHERE id=1")
40 title = result.get_one()[0]
41@@ -160,11 +161,12 @@
42 self.assertEquals(title, uni_str)
43
44 def test_unicode_array(self):
45- raw_str = "\xc3\xa1\xc3\xa9\xc3\xad\xc3\xb3\xc3\xba"
46+ raw_str = b"\xc3\xa1\xc3\xa9\xc3\xad\xc3\xb3\xc3\xba"
47 uni_str = raw_str.decode("UTF-8")
48
49 connection = self.database.connect()
50- result = connection.execute("""SELECT '{"%s"}'::TEXT[]""" % raw_str)
51+ result = connection.execute(
52+ (b"""SELECT '{"%s"}'::TEXT[]""" % raw_str).decode("UTF-8"))
53 self.assertEquals(result.get_one()[0], [uni_str])
54 result = connection.execute("""SELECT ?::TEXT[]""", ([uni_str],))
55 self.assertEquals(result.get_one()[0], [uni_str])
56
57=== modified file 'tests/expr.py'
58--- tests/expr.py 2019-06-07 16:36:44 +0000
59+++ tests/expr.py 2019-08-11 11:34:17 +0000
60@@ -192,7 +192,7 @@
61
62 def test_startswith(self):
63 expr = Func1()
64- self.assertRaises(ExprError, expr.startswith, "not a unicode string")
65+ self.assertRaises(ExprError, expr.startswith, b"not a unicode string")
66
67 like_expr = expr.startswith(u"abc!!_%")
68 self.assertTrue(isinstance(like_expr, Like))
69@@ -202,7 +202,7 @@
70
71 def test_endswith(self):
72 expr = Func1()
73- self.assertRaises(ExprError, expr.startswith, "not a unicode string")
74+ self.assertRaises(ExprError, expr.startswith, b"not a unicode string")
75
76 like_expr = expr.endswith(u"abc!!_%")
77 self.assertTrue(isinstance(like_expr, Like))
78@@ -213,7 +213,7 @@
79 def test_contains_string(self):
80 expr = Func1()
81 self.assertRaises(
82- ExprError, expr.contains_string, "not a unicode string")
83+ ExprError, expr.contains_string, b"not a unicode string")
84
85 like_expr = expr.contains_string(u"abc!!_%")
86 self.assertTrue(isinstance(like_expr, Like))
87@@ -571,11 +571,11 @@
88 self.assertRaises(CompileError, compile, object())
89 self.assertRaises(CompileError, compile, [object()])
90
91- def test_str(self):
92+ def test_bytes(self):
93 state = State()
94- statement = compile("str", state)
95+ statement = compile(b"str", state)
96 self.assertEquals(statement, "?")
97- self.assertVariablesEqual(state.parameters, [RawStrVariable("str")])
98+ self.assertVariablesEqual(state.parameters, [RawStrVariable(b"str")])
99
100 def test_unicode(self):
101 state = State()
102@@ -1221,11 +1221,11 @@
103 self.assertVariablesEqual(state.parameters, [Variable("value")])
104
105 def test_like(self):
106- expr = Like(Func1(), "value")
107+ expr = Like(Func1(), b"value")
108 state = State()
109 statement = compile(expr, state)
110 self.assertEquals(statement, "func1() LIKE ?")
111- self.assertVariablesEqual(state.parameters, [RawStrVariable("value")])
112+ self.assertVariablesEqual(state.parameters, [RawStrVariable(b"value")])
113
114 expr = Func1().like("Hello")
115 state = State()
116@@ -1234,19 +1234,19 @@
117 self.assertVariablesEqual(state.parameters, [Variable("Hello")])
118
119 def test_like_escape(self):
120- expr = Like(Func1(), "value", "!")
121+ expr = Like(Func1(), b"value", b"!")
122 state = State()
123 statement = compile(expr, state)
124 self.assertEquals(statement, "func1() LIKE ? ESCAPE ?")
125 self.assertVariablesEqual(state.parameters,
126- [RawStrVariable("value"), RawStrVariable("!")])
127+ [RawStrVariable(b"value"), RawStrVariable(b"!")])
128
129- expr = Func1().like("Hello", "!")
130+ expr = Func1().like("Hello", b"!")
131 state = State()
132 statement = compile(expr, state)
133 self.assertEquals(statement, "func1() LIKE ? ESCAPE ?")
134 self.assertVariablesEqual(state.parameters,
135- [Variable("Hello"), RawStrVariable("!")])
136+ [Variable("Hello"), RawStrVariable(b"!")])
137
138 def test_like_compareable_case(self):
139 expr = Func1().like("Hello")
140@@ -1257,11 +1257,11 @@
141 self.assertEquals(expr.case_sensitive, False)
142
143 def test_in(self):
144- expr = In(Func1(), "value")
145+ expr = In(Func1(), b"value")
146 state = State()
147 statement = compile(expr, state)
148 self.assertEquals(statement, "func1() IN (?)")
149- self.assertVariablesEqual(state.parameters, [RawStrVariable("value")])
150+ self.assertVariablesEqual(state.parameters, [RawStrVariable(b"value")])
151
152 expr = In(Func1(), elem1)
153 state = State()
154@@ -2166,8 +2166,8 @@
155 self.assertRaises(CompileError, compile_python, Expr())
156 self.assertRaises(CompileError, compile_python, Func1())
157
158- def test_str(self):
159- py_expr = compile_python("str")
160+ def test_bytes(self):
161+ py_expr = compile_python(b"str")
162 self.assertEquals(py_expr, "'str'")
163
164 def test_unicode(self):
165
166=== modified file 'tests/properties.py'
167--- tests/properties.py 2019-06-05 11:41:07 +0000
168+++ tests/properties.py 2019-08-11 11:34:17 +0000
169@@ -418,8 +418,8 @@
170 self.obj.prop1 = 1
171 self.assertTrue(isinstance(self.obj.prop1, decimal))
172
173- def test_str(self):
174- self.setup(RawStr, default="def", allow_none=False)
175+ def test_bytes(self):
176+ self.setup(RawStr, default=b"def", allow_none=False)
177
178 self.assertTrue(isinstance(self.column1, Column))
179 self.assertTrue(isinstance(self.column2, Column))
180@@ -430,7 +430,7 @@
181 self.assertTrue(isinstance(self.variable1, RawStrVariable))
182 self.assertTrue(isinstance(self.variable2, RawStrVariable))
183
184- self.assertEquals(self.obj.prop1, "def")
185+ self.assertEquals(self.obj.prop1, b"def")
186 self.assertRaises(NoneError, setattr, self.obj, "prop1", None)
187 self.obj.prop2 = None
188 self.assertEquals(self.obj.prop2, None)
189@@ -454,7 +454,7 @@
190 self.obj.prop2 = None
191 self.assertEquals(self.obj.prop2, None)
192
193- self.assertRaises(TypeError, setattr, self.obj, "prop1", "str")
194+ self.assertRaises(TypeError, setattr, self.obj, "prop1", b"str")
195
196 def test_datetime(self):
197 self.setup(DateTime, default=0, allow_none=False)
198@@ -814,7 +814,7 @@
199 (Bool, BoolVariable, True),
200 (Int, IntVariable, 1),
201 (Float, FloatVariable, 1.1),
202- (RawStr, RawStrVariable, "str"),
203+ (RawStr, RawStrVariable, b"str"),
204 (Unicode, UnicodeVariable, u"unicode"),
205 (DateTime, DateTimeVariable, datetime.now()),
206 (Date, DateVariable, date.today()),
207
208=== modified file 'tests/store/base.py'
209--- tests/store/base.py 2019-06-07 17:14:33 +0000
210+++ tests/store/base.py 2019-08-11 11:34:17 +0000
211@@ -427,7 +427,7 @@
212 self.get_cache(self.store).set_size(0)
213
214 blob = self.store.get(Blob, 20)
215- blob.bin = "\x80\x02}q\x01U\x01aK\x01s."
216+ blob.bin = b"\x80\x02}q\x01U\x01aK\x01s."
217 self.store.flush()
218 del blob
219 gc.collect()
220@@ -459,7 +459,7 @@
221 self.get_cache(self.store).set_size(0)
222
223 blob = self.store.get(Blob, 20)
224- blob.bin = "\x80\x02}q\x01U\x01aK\x01s."
225+ blob.bin = b"\x80\x02}q\x01U\x01aK\x01s."
226 self.store.flush()
227 del blob
228 gc.collect()
229@@ -502,7 +502,7 @@
230 bin = Pickle()
231
232 blob = self.store.get(Blob, 20)
233- blob.bin = "\x80\x02}q\x01U\x01aK\x01s."
234+ blob.bin = b"\x80\x02}q\x01U\x01aK\x01s."
235 self.store.flush()
236 del blob
237
238@@ -4704,7 +4704,7 @@
239 bin = Pickle()
240
241 blob = self.store.get(Blob, 20)
242- blob.bin = "\x80\x02}q\x01U\x01aK\x01s."
243+ blob.bin = b"\x80\x02}q\x01U\x01aK\x01s."
244 self.store.flush()
245
246 pickle_blob = self.store.get(PickleBlob, 20)
247@@ -4726,7 +4726,7 @@
248 bin = Pickle()
249
250 blob = self.store.get(Blob, 20)
251- blob.bin = "\x80\x02}q\x01U\x01aK\x01s."
252+ blob.bin = b"\x80\x02}q\x01U\x01aK\x01s."
253 self.store.flush()
254
255 pickle_blob = self.store.get(PickleBlob, 20)
256@@ -4763,7 +4763,7 @@
257 bin = CustomPickle()
258
259 blob = self.store.get(Blob, 20)
260- blob.bin = "\x80\x02}q\x01U\x01aK\x01s."
261+ blob.bin = b"\x80\x02}q\x01U\x01aK\x01s."
262 self.store.flush()
263
264 pickle_blob = self.store.get(PickleBlob, 20)
265@@ -4798,7 +4798,7 @@
266 blobs = ReferenceSet(Foo.id, PickleBlob.foo_id)
267
268 blob = self.store.get(Blob, 20)
269- blob.bin = "\x80\x02}q\x01U\x01aK\x01s."
270+ blob.bin = b"\x80\x02}q\x01U\x01aK\x01s."
271 self.store.flush()
272
273 pickle_blob = self.store.get(PickleBlob, 20)
274@@ -4828,7 +4828,7 @@
275 class FooBlobRefSet(Foo):
276 blobs = ReferenceSet(Foo.id, PickleBlob.foo_id)
277 blob = self.store.get(Blob, 20)
278- blob.bin = "\x80\x02}q\x01U\x01aK\x01s."
279+ blob.bin = b"\x80\x02}q\x01U\x01aK\x01s."
280 self.store.flush()
281
282 pickle_blob = self.store.get(PickleBlob, 20)
283@@ -4907,7 +4907,7 @@
284 from the database and is used whenever possible.
285 """
286 blob = self.store.get(Blob, 20)
287- blob.bin = "\x80\x02}q\x01U\x01aK\x01s."
288+ blob.bin = b"\x80\x02}q\x01U\x01aK\x01s."
289 class PickleBlob(object):
290 __storm_table__ = "bin"
291 id = Int(primary=True)
292@@ -4923,7 +4923,7 @@
293 bin = Pickle()
294
295 blob = self.store.get(Blob, 20)
296- blob.bin = "\x80\x02}q\x01U\x01aK\x01s."
297+ blob.bin = b"\x80\x02}q\x01U\x01aK\x01s."
298 self.store.flush()
299
300 pickle_blob = self.store.get(PickleBlob, 20)
301
302=== modified file 'tests/variables.py'
303--- tests/variables.py 2019-06-07 17:14:33 +0000
304+++ tests/variables.py 2019-08-11 11:34:17 +0000
305@@ -443,10 +443,10 @@
306
307 def test_set_get(self):
308 variable = RawStrVariable()
309- variable.set("str")
310- self.assertEquals(variable.get(), "str")
311- variable.set(buffer("buffer"))
312- self.assertEquals(variable.get(), "buffer")
313+ variable.set(b"str")
314+ self.assertEquals(variable.get(), b"str")
315+ variable.set(buffer(b"buffer"))
316+ self.assertEquals(variable.get(), b"buffer")
317 self.assertRaises(TypeError, variable.set, u"unicode")
318
319
320@@ -456,7 +456,7 @@
321 variable = UnicodeVariable()
322 variable.set(u"unicode")
323 self.assertEquals(variable.get(), u"unicode")
324- self.assertRaises(TypeError, variable.set, "str")
325+ self.assertRaises(TypeError, variable.set, b"str")
326
327
328 class DateTimeVariableTest(TestHelper):
329@@ -910,7 +910,7 @@
330 # JSONVariable._loads() complains loudly if it does not receive a
331 # unicode string because it has no way of knowing its encoding.
332 variable = self.variable_type()
333- self.assertRaises(TypeError, variable.set, '"abc"', from_db=True)
334+ self.assertRaises(TypeError, variable.set, b'"abc"', from_db=True)
335
336 def test_unicode_to_db(self):
337 # JSONVariable._dumps() works around unicode/str handling issues in

Subscribers

People subscribed via source and target branches

to status/vote changes: