Merge lp:~cjwatson/storm/py3-doctest into lp:storm

Proposed by Colin Watson on 2019-08-11
Status: Merged
Merged at revision: 513
Proposed branch: lp:~cjwatson/storm/py3-doctest
Merge into: lp:storm
Diff against target: 400 lines (+120/-67)
3 files modified
tests/infoheritance.txt (+12/-6)
tests/tutorial.txt (+101/-57)
tests/zope/README.txt (+7/-4)
To merge this branch: bzr merge lp:~cjwatson/storm/py3-doctest
Reviewer Review Type Date Requested Status
Kristian Glass (community) Approve on 2019-08-12
Storm Developers 2019-08-11 Pending
Review via email: mp+371161@code.launchpad.net

Commit message

Adjust doctests for text repr changes in Python 3.

Description of the change

None of these doctests need to care about the fine details of str vs. Unicode in Python 2 (that sort of thing is tested more specifically in unit tests), and in Python 3 the repr of a text string is '...' rather than u'...'. Rearrange the doctests to tolerate this.

To post a comment you must log in.
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'tests/infoheritance.txt'
--- tests/infoheritance.txt 2009-02-04 02:00:02 +0000
+++ tests/infoheritance.txt 2019-08-11 10:01:42 +0000
@@ -224,12 +224,16 @@
224... return result224... return result
225225
226>>> secret_agent = get_persons(store, info_classes=[SecretAgent]).one()226>>> secret_agent = get_persons(store, info_classes=[SecretAgent]).one()
227>>> secret_agent.name, secret_agent.info.passcode227>>> print(secret_agent.name)
228(u'Dick Tracy', u'secret!')228Dick Tracy
229>>> print(secret_agent.info.passcode)
230secret!
229231
230>>> teacher = get_persons(store, info_classes=[Teacher]).one()232>>> teacher = get_persons(store, info_classes=[Teacher]).one()
231>>> teacher.name, teacher.info.school233>>> print(teacher.name)
232(u'Mrs. Cohen', u'Cameron Elementary School')234Mrs. Cohen
235>>> print(teacher.info.school)
236Cameron Elementary School
233237
234>>>238>>>
235}}}239}}}
@@ -260,8 +264,10 @@
260>>> store.rollback()264>>> store.rollback()
261265
262>>> ghost = get_persons(store, info_classes=[Ghost]).one()266>>> ghost = get_persons(store, info_classes=[Ghost]).one()
263>>> ghost.name, ghost.info.friendly267>>> print(ghost.name)
264(u'Casper', True)268Casper
269>>> print(ghost.info.friendly)
270True
265271
266>>>272>>>
267}}}273}}}
268274
=== modified file 'tests/tutorial.txt'
--- tests/tutorial.txt 2019-06-05 11:41:07 +0000
+++ tests/tutorial.txt 2019-08-11 10:01:42 +0000
@@ -73,8 +73,10 @@
73>>> joe = Person()73>>> joe = Person()
74>>> joe.name = u"Joe Johnes"74>>> joe.name = u"Joe Johnes"
7575
76>>> print("%r, %r" % (joe.id, joe.name))76>>> print(joe.id)
77None, u'Joe Johnes'77None
78>>> print(joe.name)
79Joe Johnes
7880
79}}}81}}}
8082
@@ -85,8 +87,10 @@
85>>> store.add(joe)87>>> store.add(joe)
86<...Person object at 0x...>88<...Person object at 0x...>
8789
88>>> print("%r, %r" % (joe.id, joe.name))90>>> print(joe.id)
89None, u'Joe Johnes'91None
92>>> print(joe.name)
93Joe Johnes
9094
91}}}95}}}
9296
@@ -116,8 +120,10 @@
116{{{#!python120{{{#!python
117>>> person = store.find(Person, Person.name == u"Joe Johnes").one()121>>> person = store.find(Person, Person.name == u"Joe Johnes").one()
118122
119>>> print("%r, %r" % (person.id, person.name))123>>> print(person.id)
1201, u'Joe Johnes'1241
125>>> print(person.name)
126Joe Johnes
121127
122>>>128>>>
123}}}129}}}
@@ -127,8 +133,8 @@
127We can also retrieve the object using its primary key.133We can also retrieve the object using its primary key.
128134
129{{{#!python135{{{#!python
130>>> store.get(Person, 1).name136>>> print(store.get(Person, 1).name)
131u'Joe Johnes'137Joe Johnes
132138
133}}}139}}}
134140
@@ -168,12 +174,16 @@
168>>> store.add(mary)174>>> store.add(mary)
169<...Person object at 0x...>175<...Person object at 0x...>
170176
171>>> print("%r, %r" % (mary.id, mary.name))177>>> print(mary.id)
172None, u'Mary Margaret'178None
179>>> print(mary.name)
180Mary Margaret
173181
174>>> store.flush()182>>> store.flush()
175>>> print("%r, %r" % (mary.id, mary.name))183>>> print(mary.id)
1762, u'Mary Margaret'1842
185>>> print(mary.name)
186Mary Margaret
177187
178}}}188}}}
179189
@@ -184,8 +194,8 @@
184194
185{{{#!python195{{{#!python
186>>> store.find(Person, Person.name == u"Mary Margaret").set(name=u"Mary Maggie")196>>> store.find(Person, Person.name == u"Mary Margaret").set(name=u"Mary Maggie")
187>>> mary.name197>>> print(mary.name)
188u'Mary Maggie'198Mary Maggie
189199
190}}}200}}}
191201
@@ -240,8 +250,10 @@
240Actually, something happened.. with Joe. He's back!250Actually, something happened.. with Joe. He's back!
241251
242{{{#!python252{{{#!python
243>>> print("%r, %r" % (joe.id, joe.name))253>>> print(joe.id)
2441, u'Joe Johnes'2541
255>>> print(joe.name)
256Joe Johnes
245257
246}}}258}}}
247259
@@ -279,8 +291,10 @@
279{{{291{{{
280>>> circus = Company(u"Circus Inc.")292>>> circus = Company(u"Circus Inc.")
281293
282>>> print("%r, %r" % (circus.id, circus.name))294>>> print(circus.id)
283None, u'Circus Inc.'295None
296>>> print(circus.name)
297Circus Inc.
284298
285}}}299}}}
286300
@@ -327,8 +341,12 @@
327{{{#!python341{{{#!python
328>>> ben = store.add(Employee(u"Ben Bill"))342>>> ben = store.add(Employee(u"Ben Bill"))
329343
330>>> print("%r, %r, %r" % (ben.id, ben.name, ben.company_id))344>>> print(ben.id)
331None, u'Ben Bill', None345None
346>>> print(ben.name)
347Ben Bill
348>>> print(ben.company_id)
349None
332350
333}}}351}}}
334352
@@ -338,8 +356,10 @@
338{{{#!python356{{{#!python
339>>> ben.company = circus357>>> ben.company = circus
340358
341>>> print("%r, %r" % (ben.company_id, ben.company.name))359>>> print(ben.company_id)
342None, u'Circus Inc.'360None
361>>> print(ben.company.name)
362Circus Inc.
343363
344}}}364}}}
345365
@@ -354,8 +374,10 @@
354{{{#!python374{{{#!python
355>>> store.flush()375>>> store.flush()
356376
357>>> print("%r, %r" % (ben.company_id, ben.company.name))377>>> print(ben.company_id)
3581, u'Circus Inc.'3781
379>>> print(ben.company.name)
380Circus Inc.
359381
360}}}382}}}
361383
@@ -381,8 +403,8 @@
381403
382{{{#!python404{{{#!python
383>>> ben.company_id = 2405>>> ben.company_id = 2
384>>> ben.company.name406>>> print(ben.company.name)
385u'Sweets Inc.'407Sweets Inc.
386>>> ben.company is sweets408>>> ben.company is sweets
387True409True
388410
@@ -419,10 +441,12 @@
41914411
420442
421>>> for employee in sweets.employees:443>>> for employee in sweets.employees:
422... print("%r, %r" % (employee.id, employee.name))444... print(employee.id)
445... print(employee.name)
423... print(employee is ben)446... print(employee is ben)
424...447...
4251, u'Ben Bill'4481
449Ben Bill
426True450True
427451
428}}}452}}}
@@ -555,11 +579,14 @@
555... CompanyAccountant.company_id,579... CompanyAccountant.company_id,
556... Company.id)580... Company.id)
557581
558>>> sorted([company.name for company in frank.companies])582>>> for name in sorted(company.name for company in frank.companies):
559[u'Circus Inc.', u'Sweets Inc.']583... print(name)
584Circus Inc.
585Sweets Inc.
560586
561>>> [company.name for company in karl.companies]587>>> for company in karl.companies:
562[u'Sweets Inc.']588... print(company.name)
589Sweets Inc.
563590
564}}}591}}}
565592
@@ -580,8 +607,9 @@
580... Employee.name.like(u"Ben %"))607... Employee.name.like(u"Ben %"))
581...608...
582609
583>>> [company.name for company in result]610>>> for company in result:
584[u'Sweets Inc.']611... print(company.name)
612Sweets Inc.
585613
586}}}614}}}
587615
@@ -592,8 +620,9 @@
592>>> origin = [Company, Join(Employee, Employee.company_id == Company.id)]620>>> origin = [Company, Join(Employee, Employee.company_id == Company.id)]
593>>> result = store.using(*origin).find(Company, Employee.name.like(u"Ben %"))621>>> result = store.using(*origin).find(Company, Employee.name.like(u"Ben %"))
594622
595>>> [company.name for company in result]623>>> for company in result:
596[u'Sweets Inc.']624... print(company.name)
625Sweets Inc.
597626
598}}}627}}}
599628
@@ -604,8 +633,9 @@
604{{{#!python633{{{#!python
605>>> result = sweets.employees.find(Employee.name.like(u"Ben %"))634>>> result = sweets.employees.find(Employee.name.like(u"Ben %"))
606635
607>>> [employee.name for employee in result]636>>> for employee in result:
608[u'Ben Bill']637... print(employee.name)
638Ben Bill
609639
610}}}640}}}
611641
@@ -642,14 +672,22 @@
642672
643>>> result = store.find(Employee)673>>> result = store.find(Employee)
644674
645>>> [employee.name for employee in result.order_by(Employee.name)]675>>> for employee in result.order_by(Employee.name):
646[u'Ben Bill', u'Garry Glare', u'Mike Mayer']676... print(employee.name)
647677Ben Bill
648>>> [employee.name for employee in result.order_by(Desc(Employee.name))]678Garry Glare
649[u'Mike Mayer', u'Garry Glare', u'Ben Bill']679Mike Mayer
650680
651>>> [employee.name for employee in result.order_by(Employee.name)[:2]]681>>> for employee in result.order_by(Desc(Employee.name)):
652[u'Ben Bill', u'Garry Glare']682... print(employee.name)
683Mike Mayer
684Garry Glare
685Ben Bill
686
687>>> for employee in result.order_by(Employee.name)[:2]:
688... print(employee.name)
689Ben Bill
690Garry Glare
653691
654}}}692}}}
655693
@@ -666,8 +704,11 @@
666... Employee.company_id == Company.id,704... Employee.company_id == Company.id,
667... Employee.name.like(u"Ben %"))705... Employee.name.like(u"Ben %"))
668706
669>>> [(company.name, employee.name) for company, employee in result]707>>> for company, employee in result:
670[(u'Sweets Inc.', u'Ben Bill')]708... print(company.name)
709... print(employee.name)
710Sweets Inc.
711Ben Bill
671712
672}}}713}}}
673714
@@ -722,8 +763,8 @@
722>>> brazil.name = u"Brazil"763>>> brazil.name = u"Brazil"
723>>> brazil.currency_id = 1764>>> brazil.currency_id = 1
724765
725>>> brazil.currency.symbol766>>> print(brazil.currency.symbol)
726u'BRL'767BRL
727768
728}}}769}}}
729770
@@ -781,8 +822,9 @@
781822
782{{{#!python823{{{#!python
783>>> result = store.execute(Select(Person.name, Person.id == 1))824>>> result = store.execute(Select(Person.name, Person.id == 1))
784>>> result.get_one()825>>> (name,) = result.get_one()
785(u'Joe Johnes',)826>>> print(name)
827Joe Johnes
786828
787}}}829}}}
788830
@@ -829,8 +871,8 @@
829from storm.locals import SQL871from storm.locals import SQL
830872
831>>> ruy.name = SQL("(SELECT name || ? FROM person WHERE id=4)", (" Ritcher",))873>>> ruy.name = SQL("(SELECT name || ? FROM person WHERE id=4)", (" Ritcher",))
832>>> ruy.name874>>> print(ruy.name)
833u'Ruy Ritcher'875Ruy Ritcher
834876
835}}}877}}}
836878
@@ -865,8 +907,10 @@
865... Employee.id > AnotherEmployee.id)907... Employee.id > AnotherEmployee.id)
866908
867>>> for employee1, employee2 in result:909>>> for employee1, employee2 in result:
868... print((employee1.name, employee2.name))910... print(employee1.name)
869(u'Mike Mayer', u'Ben Bill')911... print(employee2.name)
912Mike Mayer
913Ben Bill
870914
871}}}915}}}
872916
@@ -895,7 +939,7 @@
895... Employee.company_id == AnotherEmployee.company_id,939... Employee.company_id == AnotherEmployee.company_id,
896... Employee.id > AnotherEmployee.id)940... Employee.id > AnotherEmployee.id)
897>>> list(result)941>>> list(result)
898[...] EXECUTE: u'SELECT employee.company_id, employee.id, employee.name, "...".company_id, "...".id, "...".name FROM employee, employee AS "..." WHERE employee.company_id = "...".company_id AND employee.id > "...".id', ()942[...] EXECUTE: ...'SELECT employee.company_id, employee.id, employee.name, "...".company_id, "...".id, "...".name FROM employee, employee AS "..." WHERE employee.company_id = "...".company_id AND employee.id > "...".id', ()
899[...] DONE943[...] DONE
900[(<...Employee object at ...>, <...Employee object at ...>)]944[(<...Employee object at ...>, <...Employee object at ...>)]
901945
902946
=== modified file 'tests/zope/README.txt'
--- tests/zope/README.txt 2011-10-28 16:15:01 +0000
+++ tests/zope/README.txt 2019-08-11 10:01:42 +0000
@@ -139,16 +139,19 @@
139139
140At this point a store.find should return the new object.140At this point a store.find should return the new object.
141141
142 >>> sorted([person.name for person in store.find(Person)])142 >>> for name in sorted(person.name for person in store.find(Person)):
143 [u'Imposter!', u'John Doe']143 ... print(name)
144 Imposter!
145 John Doe
144146
145All this means is that the data has been flushed to the database; it's147All this means is that the data has been flushed to the database; it's
146still not committed. If we abort the transaction the new Person148still not committed. If we abort the transaction the new Person
147object should disappear.149object should disappear.
148150
149 >>> transaction.abort()151 >>> transaction.abort()
150 >>> [person.name for person in store.find(Person)]152 >>> for person in store.find(Person):
151 [u'John Doe']153 ... print(person.name)
154 John Doe
152155
153Excellent! As you can see, ZStorm makes working with SQL databases156Excellent! As you can see, ZStorm makes working with SQL databases
154and Zope 3 very natural.157and Zope 3 very natural.

Subscribers

People subscribed via source and target branches

to status/vote changes: