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
=== modified file 'tests/databases/base.py'
--- tests/databases/base.py 2019-06-07 17:14:33 +0000
+++ tests/databases/base.py 2019-08-11 11:34:17 +0000
@@ -275,7 +275,7 @@
275275
276 def test_binary(self):276 def test_binary(self):
277 """Ensure database works with high bits and embedded zeros."""277 """Ensure database works with high bits and embedded zeros."""
278 value = "\xff\x00\xff\x00"278 value = b"\xff\x00\xff\x00"
279 self.connection.execute("INSERT INTO bin_test (b) VALUES (?)",279 self.connection.execute("INSERT INTO bin_test (b) VALUES (?)",
280 (value,))280 (value,))
281 result = self.connection.execute("SELECT b FROM bin_test")281 result = self.connection.execute("SELECT b FROM bin_test")
@@ -290,7 +290,7 @@
290 variable = RawStrVariable()290 variable = RawStrVariable()
291 # If the following doesn't raise a TypeError we're good.291 # If the following doesn't raise a TypeError we're good.
292 result.set_variable(variable, result.get_one()[0])292 result.set_variable(variable, result.get_one()[0])
293 self.assertEquals(variable.get(), "Value")293 self.assertEquals(variable.get(), b"Value")
294294
295 def test_order_by_group_by(self):295 def test_order_by_group_by(self):
296 self.connection.execute("INSERT INTO test VALUES (100, 'Title 10')")296 self.connection.execute("INSERT INTO test VALUES (100, 'Title 10')")
297297
=== modified file 'tests/databases/postgres.py'
--- tests/databases/postgres.py 2019-06-05 11:41:07 +0000
+++ tests/databases/postgres.py 2019-08-11 11:34:17 +0000
@@ -147,11 +147,12 @@
147 self.assertEquals(encoding.upper(), "UTF8")147 self.assertEquals(encoding.upper(), "UTF8")
148148
149 def test_unicode(self):149 def test_unicode(self):
150 raw_str = "\xc3\xa1\xc3\xa9\xc3\xad\xc3\xb3\xc3\xba"150 raw_str = b"\xc3\xa1\xc3\xa9\xc3\xad\xc3\xb3\xc3\xba"
151 uni_str = raw_str.decode("UTF-8")151 uni_str = raw_str.decode("UTF-8")
152152
153 connection = self.database.connect()153 connection = self.database.connect()
154 connection.execute("INSERT INTO test VALUES (1, '%s')" % raw_str)154 connection.execute(
155 (b"INSERT INTO test VALUES (1, '%s')" % raw_str).decode("UTF-8"))
155156
156 result = connection.execute("SELECT title FROM test WHERE id=1")157 result = connection.execute("SELECT title FROM test WHERE id=1")
157 title = result.get_one()[0]158 title = result.get_one()[0]
@@ -160,11 +161,12 @@
160 self.assertEquals(title, uni_str)161 self.assertEquals(title, uni_str)
161162
162 def test_unicode_array(self):163 def test_unicode_array(self):
163 raw_str = "\xc3\xa1\xc3\xa9\xc3\xad\xc3\xb3\xc3\xba"164 raw_str = b"\xc3\xa1\xc3\xa9\xc3\xad\xc3\xb3\xc3\xba"
164 uni_str = raw_str.decode("UTF-8")165 uni_str = raw_str.decode("UTF-8")
165166
166 connection = self.database.connect()167 connection = self.database.connect()
167 result = connection.execute("""SELECT '{"%s"}'::TEXT[]""" % raw_str)168 result = connection.execute(
169 (b"""SELECT '{"%s"}'::TEXT[]""" % raw_str).decode("UTF-8"))
168 self.assertEquals(result.get_one()[0], [uni_str])170 self.assertEquals(result.get_one()[0], [uni_str])
169 result = connection.execute("""SELECT ?::TEXT[]""", ([uni_str],))171 result = connection.execute("""SELECT ?::TEXT[]""", ([uni_str],))
170 self.assertEquals(result.get_one()[0], [uni_str])172 self.assertEquals(result.get_one()[0], [uni_str])
171173
=== modified file 'tests/expr.py'
--- tests/expr.py 2019-06-07 16:36:44 +0000
+++ tests/expr.py 2019-08-11 11:34:17 +0000
@@ -192,7 +192,7 @@
192192
193 def test_startswith(self):193 def test_startswith(self):
194 expr = Func1()194 expr = Func1()
195 self.assertRaises(ExprError, expr.startswith, "not a unicode string")195 self.assertRaises(ExprError, expr.startswith, b"not a unicode string")
196196
197 like_expr = expr.startswith(u"abc!!_%")197 like_expr = expr.startswith(u"abc!!_%")
198 self.assertTrue(isinstance(like_expr, Like))198 self.assertTrue(isinstance(like_expr, Like))
@@ -202,7 +202,7 @@
202202
203 def test_endswith(self):203 def test_endswith(self):
204 expr = Func1()204 expr = Func1()
205 self.assertRaises(ExprError, expr.startswith, "not a unicode string")205 self.assertRaises(ExprError, expr.startswith, b"not a unicode string")
206206
207 like_expr = expr.endswith(u"abc!!_%")207 like_expr = expr.endswith(u"abc!!_%")
208 self.assertTrue(isinstance(like_expr, Like))208 self.assertTrue(isinstance(like_expr, Like))
@@ -213,7 +213,7 @@
213 def test_contains_string(self):213 def test_contains_string(self):
214 expr = Func1()214 expr = Func1()
215 self.assertRaises(215 self.assertRaises(
216 ExprError, expr.contains_string, "not a unicode string")216 ExprError, expr.contains_string, b"not a unicode string")
217217
218 like_expr = expr.contains_string(u"abc!!_%")218 like_expr = expr.contains_string(u"abc!!_%")
219 self.assertTrue(isinstance(like_expr, Like))219 self.assertTrue(isinstance(like_expr, Like))
@@ -571,11 +571,11 @@
571 self.assertRaises(CompileError, compile, object())571 self.assertRaises(CompileError, compile, object())
572 self.assertRaises(CompileError, compile, [object()])572 self.assertRaises(CompileError, compile, [object()])
573573
574 def test_str(self):574 def test_bytes(self):
575 state = State()575 state = State()
576 statement = compile("str", state)576 statement = compile(b"str", state)
577 self.assertEquals(statement, "?")577 self.assertEquals(statement, "?")
578 self.assertVariablesEqual(state.parameters, [RawStrVariable("str")])578 self.assertVariablesEqual(state.parameters, [RawStrVariable(b"str")])
579579
580 def test_unicode(self):580 def test_unicode(self):
581 state = State()581 state = State()
@@ -1221,11 +1221,11 @@
1221 self.assertVariablesEqual(state.parameters, [Variable("value")])1221 self.assertVariablesEqual(state.parameters, [Variable("value")])
12221222
1223 def test_like(self):1223 def test_like(self):
1224 expr = Like(Func1(), "value")1224 expr = Like(Func1(), b"value")
1225 state = State()1225 state = State()
1226 statement = compile(expr, state)1226 statement = compile(expr, state)
1227 self.assertEquals(statement, "func1() LIKE ?")1227 self.assertEquals(statement, "func1() LIKE ?")
1228 self.assertVariablesEqual(state.parameters, [RawStrVariable("value")])1228 self.assertVariablesEqual(state.parameters, [RawStrVariable(b"value")])
12291229
1230 expr = Func1().like("Hello")1230 expr = Func1().like("Hello")
1231 state = State()1231 state = State()
@@ -1234,19 +1234,19 @@
1234 self.assertVariablesEqual(state.parameters, [Variable("Hello")])1234 self.assertVariablesEqual(state.parameters, [Variable("Hello")])
12351235
1236 def test_like_escape(self):1236 def test_like_escape(self):
1237 expr = Like(Func1(), "value", "!")1237 expr = Like(Func1(), b"value", b"!")
1238 state = State()1238 state = State()
1239 statement = compile(expr, state)1239 statement = compile(expr, state)
1240 self.assertEquals(statement, "func1() LIKE ? ESCAPE ?")1240 self.assertEquals(statement, "func1() LIKE ? ESCAPE ?")
1241 self.assertVariablesEqual(state.parameters,1241 self.assertVariablesEqual(state.parameters,
1242 [RawStrVariable("value"), RawStrVariable("!")])1242 [RawStrVariable(b"value"), RawStrVariable(b"!")])
12431243
1244 expr = Func1().like("Hello", "!")1244 expr = Func1().like("Hello", b"!")
1245 state = State()1245 state = State()
1246 statement = compile(expr, state)1246 statement = compile(expr, state)
1247 self.assertEquals(statement, "func1() LIKE ? ESCAPE ?")1247 self.assertEquals(statement, "func1() LIKE ? ESCAPE ?")
1248 self.assertVariablesEqual(state.parameters,1248 self.assertVariablesEqual(state.parameters,
1249 [Variable("Hello"), RawStrVariable("!")])1249 [Variable("Hello"), RawStrVariable(b"!")])
12501250
1251 def test_like_compareable_case(self):1251 def test_like_compareable_case(self):
1252 expr = Func1().like("Hello")1252 expr = Func1().like("Hello")
@@ -1257,11 +1257,11 @@
1257 self.assertEquals(expr.case_sensitive, False)1257 self.assertEquals(expr.case_sensitive, False)
12581258
1259 def test_in(self):1259 def test_in(self):
1260 expr = In(Func1(), "value")1260 expr = In(Func1(), b"value")
1261 state = State()1261 state = State()
1262 statement = compile(expr, state)1262 statement = compile(expr, state)
1263 self.assertEquals(statement, "func1() IN (?)")1263 self.assertEquals(statement, "func1() IN (?)")
1264 self.assertVariablesEqual(state.parameters, [RawStrVariable("value")])1264 self.assertVariablesEqual(state.parameters, [RawStrVariable(b"value")])
12651265
1266 expr = In(Func1(), elem1)1266 expr = In(Func1(), elem1)
1267 state = State()1267 state = State()
@@ -2166,8 +2166,8 @@
2166 self.assertRaises(CompileError, compile_python, Expr())2166 self.assertRaises(CompileError, compile_python, Expr())
2167 self.assertRaises(CompileError, compile_python, Func1())2167 self.assertRaises(CompileError, compile_python, Func1())
21682168
2169 def test_str(self):2169 def test_bytes(self):
2170 py_expr = compile_python("str")2170 py_expr = compile_python(b"str")
2171 self.assertEquals(py_expr, "'str'")2171 self.assertEquals(py_expr, "'str'")
21722172
2173 def test_unicode(self):2173 def test_unicode(self):
21742174
=== modified file 'tests/properties.py'
--- tests/properties.py 2019-06-05 11:41:07 +0000
+++ tests/properties.py 2019-08-11 11:34:17 +0000
@@ -418,8 +418,8 @@
418 self.obj.prop1 = 1418 self.obj.prop1 = 1
419 self.assertTrue(isinstance(self.obj.prop1, decimal))419 self.assertTrue(isinstance(self.obj.prop1, decimal))
420420
421 def test_str(self):421 def test_bytes(self):
422 self.setup(RawStr, default="def", allow_none=False)422 self.setup(RawStr, default=b"def", allow_none=False)
423423
424 self.assertTrue(isinstance(self.column1, Column))424 self.assertTrue(isinstance(self.column1, Column))
425 self.assertTrue(isinstance(self.column2, Column))425 self.assertTrue(isinstance(self.column2, Column))
@@ -430,7 +430,7 @@
430 self.assertTrue(isinstance(self.variable1, RawStrVariable))430 self.assertTrue(isinstance(self.variable1, RawStrVariable))
431 self.assertTrue(isinstance(self.variable2, RawStrVariable))431 self.assertTrue(isinstance(self.variable2, RawStrVariable))
432432
433 self.assertEquals(self.obj.prop1, "def")433 self.assertEquals(self.obj.prop1, b"def")
434 self.assertRaises(NoneError, setattr, self.obj, "prop1", None)434 self.assertRaises(NoneError, setattr, self.obj, "prop1", None)
435 self.obj.prop2 = None435 self.obj.prop2 = None
436 self.assertEquals(self.obj.prop2, None)436 self.assertEquals(self.obj.prop2, None)
@@ -454,7 +454,7 @@
454 self.obj.prop2 = None454 self.obj.prop2 = None
455 self.assertEquals(self.obj.prop2, None)455 self.assertEquals(self.obj.prop2, None)
456456
457 self.assertRaises(TypeError, setattr, self.obj, "prop1", "str")457 self.assertRaises(TypeError, setattr, self.obj, "prop1", b"str")
458458
459 def test_datetime(self):459 def test_datetime(self):
460 self.setup(DateTime, default=0, allow_none=False)460 self.setup(DateTime, default=0, allow_none=False)
@@ -814,7 +814,7 @@
814 (Bool, BoolVariable, True),814 (Bool, BoolVariable, True),
815 (Int, IntVariable, 1),815 (Int, IntVariable, 1),
816 (Float, FloatVariable, 1.1),816 (Float, FloatVariable, 1.1),
817 (RawStr, RawStrVariable, "str"),817 (RawStr, RawStrVariable, b"str"),
818 (Unicode, UnicodeVariable, u"unicode"),818 (Unicode, UnicodeVariable, u"unicode"),
819 (DateTime, DateTimeVariable, datetime.now()),819 (DateTime, DateTimeVariable, datetime.now()),
820 (Date, DateVariable, date.today()),820 (Date, DateVariable, date.today()),
821821
=== modified file 'tests/store/base.py'
--- tests/store/base.py 2019-06-07 17:14:33 +0000
+++ tests/store/base.py 2019-08-11 11:34:17 +0000
@@ -427,7 +427,7 @@
427 self.get_cache(self.store).set_size(0)427 self.get_cache(self.store).set_size(0)
428428
429 blob = self.store.get(Blob, 20)429 blob = self.store.get(Blob, 20)
430 blob.bin = "\x80\x02}q\x01U\x01aK\x01s."430 blob.bin = b"\x80\x02}q\x01U\x01aK\x01s."
431 self.store.flush()431 self.store.flush()
432 del blob432 del blob
433 gc.collect()433 gc.collect()
@@ -459,7 +459,7 @@
459 self.get_cache(self.store).set_size(0)459 self.get_cache(self.store).set_size(0)
460460
461 blob = self.store.get(Blob, 20)461 blob = self.store.get(Blob, 20)
462 blob.bin = "\x80\x02}q\x01U\x01aK\x01s."462 blob.bin = b"\x80\x02}q\x01U\x01aK\x01s."
463 self.store.flush()463 self.store.flush()
464 del blob464 del blob
465 gc.collect()465 gc.collect()
@@ -502,7 +502,7 @@
502 bin = Pickle()502 bin = Pickle()
503503
504 blob = self.store.get(Blob, 20)504 blob = self.store.get(Blob, 20)
505 blob.bin = "\x80\x02}q\x01U\x01aK\x01s."505 blob.bin = b"\x80\x02}q\x01U\x01aK\x01s."
506 self.store.flush()506 self.store.flush()
507 del blob507 del blob
508508
@@ -4704,7 +4704,7 @@
4704 bin = Pickle()4704 bin = Pickle()
47054705
4706 blob = self.store.get(Blob, 20)4706 blob = self.store.get(Blob, 20)
4707 blob.bin = "\x80\x02}q\x01U\x01aK\x01s."4707 blob.bin = b"\x80\x02}q\x01U\x01aK\x01s."
4708 self.store.flush()4708 self.store.flush()
47094709
4710 pickle_blob = self.store.get(PickleBlob, 20)4710 pickle_blob = self.store.get(PickleBlob, 20)
@@ -4726,7 +4726,7 @@
4726 bin = Pickle()4726 bin = Pickle()
47274727
4728 blob = self.store.get(Blob, 20)4728 blob = self.store.get(Blob, 20)
4729 blob.bin = "\x80\x02}q\x01U\x01aK\x01s."4729 blob.bin = b"\x80\x02}q\x01U\x01aK\x01s."
4730 self.store.flush()4730 self.store.flush()
47314731
4732 pickle_blob = self.store.get(PickleBlob, 20)4732 pickle_blob = self.store.get(PickleBlob, 20)
@@ -4763,7 +4763,7 @@
4763 bin = CustomPickle()4763 bin = CustomPickle()
47644764
4765 blob = self.store.get(Blob, 20)4765 blob = self.store.get(Blob, 20)
4766 blob.bin = "\x80\x02}q\x01U\x01aK\x01s."4766 blob.bin = b"\x80\x02}q\x01U\x01aK\x01s."
4767 self.store.flush()4767 self.store.flush()
47684768
4769 pickle_blob = self.store.get(PickleBlob, 20)4769 pickle_blob = self.store.get(PickleBlob, 20)
@@ -4798,7 +4798,7 @@
4798 blobs = ReferenceSet(Foo.id, PickleBlob.foo_id)4798 blobs = ReferenceSet(Foo.id, PickleBlob.foo_id)
47994799
4800 blob = self.store.get(Blob, 20)4800 blob = self.store.get(Blob, 20)
4801 blob.bin = "\x80\x02}q\x01U\x01aK\x01s."4801 blob.bin = b"\x80\x02}q\x01U\x01aK\x01s."
4802 self.store.flush()4802 self.store.flush()
48034803
4804 pickle_blob = self.store.get(PickleBlob, 20)4804 pickle_blob = self.store.get(PickleBlob, 20)
@@ -4828,7 +4828,7 @@
4828 class FooBlobRefSet(Foo):4828 class FooBlobRefSet(Foo):
4829 blobs = ReferenceSet(Foo.id, PickleBlob.foo_id)4829 blobs = ReferenceSet(Foo.id, PickleBlob.foo_id)
4830 blob = self.store.get(Blob, 20)4830 blob = self.store.get(Blob, 20)
4831 blob.bin = "\x80\x02}q\x01U\x01aK\x01s."4831 blob.bin = b"\x80\x02}q\x01U\x01aK\x01s."
4832 self.store.flush()4832 self.store.flush()
48334833
4834 pickle_blob = self.store.get(PickleBlob, 20)4834 pickle_blob = self.store.get(PickleBlob, 20)
@@ -4907,7 +4907,7 @@
4907 from the database and is used whenever possible.4907 from the database and is used whenever possible.
4908 """4908 """
4909 blob = self.store.get(Blob, 20)4909 blob = self.store.get(Blob, 20)
4910 blob.bin = "\x80\x02}q\x01U\x01aK\x01s."4910 blob.bin = b"\x80\x02}q\x01U\x01aK\x01s."
4911 class PickleBlob(object):4911 class PickleBlob(object):
4912 __storm_table__ = "bin"4912 __storm_table__ = "bin"
4913 id = Int(primary=True)4913 id = Int(primary=True)
@@ -4923,7 +4923,7 @@
4923 bin = Pickle()4923 bin = Pickle()
49244924
4925 blob = self.store.get(Blob, 20)4925 blob = self.store.get(Blob, 20)
4926 blob.bin = "\x80\x02}q\x01U\x01aK\x01s."4926 blob.bin = b"\x80\x02}q\x01U\x01aK\x01s."
4927 self.store.flush()4927 self.store.flush()
49284928
4929 pickle_blob = self.store.get(PickleBlob, 20)4929 pickle_blob = self.store.get(PickleBlob, 20)
49304930
=== modified file 'tests/variables.py'
--- tests/variables.py 2019-06-07 17:14:33 +0000
+++ tests/variables.py 2019-08-11 11:34:17 +0000
@@ -443,10 +443,10 @@
443443
444 def test_set_get(self):444 def test_set_get(self):
445 variable = RawStrVariable()445 variable = RawStrVariable()
446 variable.set("str")446 variable.set(b"str")
447 self.assertEquals(variable.get(), "str")447 self.assertEquals(variable.get(), b"str")
448 variable.set(buffer("buffer"))448 variable.set(buffer(b"buffer"))
449 self.assertEquals(variable.get(), "buffer")449 self.assertEquals(variable.get(), b"buffer")
450 self.assertRaises(TypeError, variable.set, u"unicode")450 self.assertRaises(TypeError, variable.set, u"unicode")
451451
452452
@@ -456,7 +456,7 @@
456 variable = UnicodeVariable()456 variable = UnicodeVariable()
457 variable.set(u"unicode")457 variable.set(u"unicode")
458 self.assertEquals(variable.get(), u"unicode")458 self.assertEquals(variable.get(), u"unicode")
459 self.assertRaises(TypeError, variable.set, "str")459 self.assertRaises(TypeError, variable.set, b"str")
460460
461461
462class DateTimeVariableTest(TestHelper):462class DateTimeVariableTest(TestHelper):
@@ -910,7 +910,7 @@
910 # JSONVariable._loads() complains loudly if it does not receive a910 # JSONVariable._loads() complains loudly if it does not receive a
911 # unicode string because it has no way of knowing its encoding.911 # unicode string because it has no way of knowing its encoding.
912 variable = self.variable_type()912 variable = self.variable_type()
913 self.assertRaises(TypeError, variable.set, '"abc"', from_db=True)913 self.assertRaises(TypeError, variable.set, b'"abc"', from_db=True)
914914
915 def test_unicode_to_db(self):915 def test_unicode_to_db(self):
916 # JSONVariable._dumps() works around unicode/str handling issues in916 # JSONVariable._dumps() works around unicode/str handling issues in

Subscribers

People subscribed via source and target branches

to status/vote changes: