twisted / axiom
Showing 52 of 62 files from the diff.

@@ -30,7 +30,6 @@
Loading
30 30
FAKE_POWER = 'fake power'
31 31
REAL_POWER = 'real power'
32 32
33 -
34 33
@implementer(IElectricityGrid)
35 34
class NullGrid(object):
36 35
    """
@@ -199,6 +198,7 @@
Loading
199 198
200 199
201 200
201 +
@dependency.dependable
202 202
@empowerment(IAppliance)
203 203
@empowerment(IBreadConsumer)
204 204
class Toaster(Item):
@@ -230,6 +230,9 @@
Loading
230 230
231 231
def powerstripSetup(ps):
232 232
    ps.setForUSElectricity()
233 +
234 +
235 +
@dependency.dependable
233 236
class Blender(Item):
234 237
    powerStrip = dependency.dependsOn(PowerStrip,
235 238
                                      powerstripSetup)
@@ -238,6 +241,8 @@
Loading
238 241
    def __getPowerupInterfaces__(self, powerups):
239 242
        yield (IAppliance, 0)
240 243
244 +
245 +
@dependency.dependable
241 246
class IceCrusher(Item):
242 247
    blender = dependency.dependsOn(Blender)
243 248
@@ -277,7 +282,7 @@
Loading
277 282
        """
278 283
        foo = Kitchen(store=self.store)
279 284
        e = Toaster(store=self.store)
280 -
        self.assertEquals(e.powerStrip, None)
285 +
        self.assertEqual(e.powerStrip, None)
281 286
        dependency.installOn(e, foo)
282 287
        e.toast()
283 288
        ps = self.store.findUnique(PowerStrip, default=None)
@@ -313,7 +318,7 @@
Loading
313 318
        dependency.installOn(e, foo)
314 319
315 320
        ps = self.store.findUnique(PowerStrip)
316 -
        self.failUnlessRaises(dependency.DependencyError,
321 +
        self.assertRaises(dependency.DependencyError,
317 322
                              dependency.uninstallFrom, ps, foo)
318 323
319 324
    def test_properOrphaning(self):
@@ -331,7 +336,7 @@
Loading
331 336
        f = Blender(store=self.store)
332 337
        dependency.installOn(f, foo)
333 338
334 -
        self.assertEquals(list(self.store.query(PowerStrip)), [ps])
339 +
        self.assertEqual(list(self.store.query(PowerStrip)), [ps])
335 340
        #XXX does ordering matter?
336 341
        self.assertEquals(set(dependency.installedDependents(ps, foo)),
337 342
                          {e, f})
@@ -341,10 +346,10 @@
Loading
341 346
                          [ps])
342 347
343 348
        dependency.uninstallFrom(e, foo)
344 -
        self.assertEquals(dependency.installedOn(ps), foo)
349 +
        self.assertEqual(dependency.installedOn(ps), foo)
345 350
346 351
        dependency.uninstallFrom(f, foo)
347 -
        self.assertEquals(dependency.installedOn(ps), None)
352 +
        self.assertEqual(dependency.installedOn(ps), None)
348 353
349 354
    def test_installedUniqueRequirements(self):
350 355
        """
@@ -359,7 +364,7 @@
Loading
359 364
        f = Blender(store=self.store)
360 365
        dependency.installOn(f, foo)
361 366
362 -
        self.assertEquals(list(dependency.installedUniqueRequirements(e, foo)),
367 +
        self.assertEqual(list(dependency.installedUniqueRequirements(e, foo)),
363 368
                          [bb])
364 369
365 370
    def test_customizerCalledOnce(self):
@@ -390,7 +395,7 @@
Loading
390 395
        dependency.installOn(e, foo)
391 396
        self.assertEqual(e.powerStrip, ps)
392 397
        dependency.uninstallFrom(e, foo)
393 -
        self.assertEquals(dependency.installedOn(ps), foo)
398 +
        self.assertEqual(dependency.installedOn(ps), foo)
394 399
395 400
    def test_doubleInstall(self):
396 401
        """
@@ -402,7 +407,7 @@
Loading
402 407
        e = Toaster(store=self.store)
403 408
        dependency.installOn(e, foo)
404 409
        ps = PowerStrip(store=self.store)
405 -
        self.failUnlessRaises(dependency.DependencyError,
410 +
        self.assertRaises(dependency.DependencyError,
406 411
                              dependency.installOn, ps, foo)
407 412
        e2 = Toaster(store=self.store)
408 413
        dependency.installOn(e2, foo)
@@ -419,9 +424,9 @@
Loading
419 424
        blender = self.store.findUnique(Blender)
420 425
        ps = self.store.findUnique(PowerStrip)
421 426
422 -
        self.assertEquals(dependency.installedOn(blender), foo)
423 -
        self.assertEquals(dependency.installedOn(ps), foo)
424 -
        self.assertEquals(list(dependency.installedRequirements(ic, foo)),
427 +
        self.assertEqual(dependency.installedOn(blender), foo)
428 +
        self.assertEqual(dependency.installedOn(ps), foo)
429 +
        self.assertEqual(list(dependency.installedRequirements(ic, foo)),
425 430
                          [blender])
426 431
427 432
    def test_recursiveUninstall(self):
@@ -437,9 +442,9 @@
Loading
437 442
438 443
        dependency.uninstallFrom(ic, foo)
439 444
440 -
        self.failIf(dependency.installedOn(blender))
441 -
        self.failIf(dependency.installedOn(ps))
442 -
        self.failIf(dependency.installedOn(ic))
445 +
        self.assertFalse(dependency.installedOn(blender))
446 +
        self.assertFalse(dependency.installedOn(ps))
447 +
        self.assertFalse(dependency.installedOn(ic))
443 448
444 449
    def test_wrongDependsOn(self):
445 450
        """
@@ -452,8 +457,8 @@
Loading
452 457
        dependsOn should accept (most of) attributes.reference's args.
453 458
        """
454 459
455 -
        self.failUnless("power source" in Toaster.powerStrip.doc)
456 -
        self.assertEquals(Toaster.breadFactory.whenDeleted, reference.CASCADE)
460 +
        self.assertTrue("power source" in Toaster.powerStrip.doc)
461 +
        self.assertEqual(Toaster.breadFactory.whenDeleted, reference.CASCADE)
457 462
458 463
    def test_powerupInterfaces(self):
459 464
        """
@@ -465,10 +470,10 @@
Loading
465 470
        f = Blender(store=self.store)
466 471
        dependency.installOn(e, foo)
467 472
        dependency.installOn(f, foo)
468 -
        self.assertEquals(IAppliance(foo), e)
469 -
        self.assertEquals(IBreadConsumer(foo), e)
473 +
        self.assertEqual(IAppliance(foo), e)
474 +
        self.assertEqual(IBreadConsumer(foo), e)
470 475
        dependency.uninstallFrom(e, foo)
471 -
        self.assertEquals(IAppliance(foo), f)
476 +
        self.assertEqual(IAppliance(foo), f)
472 477
        dependency.uninstallFrom(f, foo)
473 478
        self.assertRaises(TypeError, IAppliance, foo)
474 479
@@ -483,11 +488,11 @@
Loading
483 488
        self.installCallbackCalled = False
484 489
        e.callback = lambda _: setattr(self, 'installCallbackCalled', True)
485 490
        dependency.installOn(e, foo)
486 -
        self.failUnless(self.installCallbackCalled)
491 +
        self.assertTrue(self.installCallbackCalled)
487 492
        self.uninstallCallbackCalled = False
488 493
        e.callback = lambda _: setattr(self, 'uninstallCallbackCalled', True)
489 494
        dependency.uninstallFrom(e, foo)
490 -
        self.failUnless(self.uninstallCallbackCalled)
495 +
        self.assertTrue(self.uninstallCallbackCalled)
491 496
492 497
493 498
    def test_onlyInstallPowerups(self):
@@ -500,8 +505,8 @@
Loading
500 505
        f = Toaster(store=self.store)
501 506
        dependency.onlyInstallPowerups(e, foo)
502 507
        dependency.onlyInstallPowerups(f, foo)
503 -
        self.assertEquals(list(foo.powerupsFor(IBreadConsumer)), [e, f])
504 -
        self.assertEquals(list(self.store.query(
508 +
        self.assertEqual(list(foo.powerupsFor(IBreadConsumer)), [e, f])
509 +
        self.assertEqual(list(self.store.query(
505 510
                    dependency._DependencyConnector)), [])
506 511
507 512
@@ -525,7 +530,7 @@
Loading
525 530
        """
526 531
        dependency.installOn(RealGrid(store=self.store), self.store)
527 532
        substore = SubStore.createNew(self.store, ['sub']).open()
528 -
        self.assertEquals(PowerStrip(store=substore).draw(1), REAL_POWER)
533 +
        self.assertEqual(PowerStrip(store=substore).draw(1), REAL_POWER)
529 534
530 535
531 536
    def test_requiresFromSiteDefault(self):
@@ -536,8 +541,8 @@
Loading
536 541
        """
537 542
        substore = SubStore.createNew(self.store, ['sub']).open()
538 543
        ps = PowerStrip(store=substore)
539 -
        self.assertEquals(ps.draw(1), FAKE_POWER)
540 -
        self.assertEquals(ps.grid.siteStore, self.store)
544 +
        self.assertEqual(ps.draw(1), FAKE_POWER)
545 +
        self.assertEqual(ps.grid.siteStore, self.store)
541 546
542 547
543 548
    def test_requiresFromSiteInSiteStore(self):
@@ -563,11 +568,11 @@
Loading
563 568
        L{dependency.requiresFromSite}.
564 569
        """
565 570
        plant = PowerPlant(store=self.store)
566 -
        self.assertEquals(plant.grid.siteStore, self.store)
567 -
        self.assertEquals(plant.grid.draw(100), FAKE_POWER)
571 +
        self.assertEqual(plant.grid.siteStore, self.store)
572 +
        self.assertEqual(plant.grid.draw(100), FAKE_POWER)
568 573
        dependency.installOn(RealGrid(store=self.store), self.store)
569 -
        self.assertEquals(plant.grid.siteStore, self.store)
570 -
        self.assertEquals(plant.grid.draw(100), FAKE_POWER)
574 +
        self.assertEqual(plant.grid.siteStore, self.store)
575 +
        self.assertEqual(plant.grid.draw(100), FAKE_POWER)
571 576
572 577
573 578
    def test_requiresFromSiteNoDefault(self):
@@ -577,7 +582,7 @@
Loading
577 582
        """
578 583
        dependency.installOn(RealGrid(store=self.store), self.store)
579 584
        substore = SubStore.createNew(self.store, ['sub']).open()
580 -
        self.assertEquals(SpecifiedBadDefaults(store=substore).pump(),
585 +
        self.assertEqual(SpecifiedBadDefaults(store=substore).pump(),
581 586
                          REAL_POWER)
582 587
583 588

@@ -59,7 +59,7 @@
Loading
59 59
        upgradeExplicitOid(store)
60 60
61 61
        for substore in store.query(SubStore):
62 -
            print('Upgrading: {!r}'.format(substore))
62 +
            print(u'Upgrading: {!r}'.format(substore))
63 63
            self.upgradeStore(substore.open())
64 64
65 65
    def perform(self, store, count):
@@ -72,9 +72,9 @@
Loading
72 72
73 73
        try:
74 74
            self.upgradeStore(store)
75 -
            print('Upgrade complete')
75 +
            print(u'Upgrade complete')
76 76
        except errors.ItemUpgradeError as e:
77 -
            print('Upgrader error:')
77 +
            print(u'Upgrader error:')
78 78
            e.originalFailure.printTraceback(file=sys.stdout)
79 79
            print(self.errorMessageFormat % (
80 80
                e.oldType.typeName, e.storeID, e.oldType.schemaVersion,
@@ -236,15 +236,15 @@
Loading
236 236
        acc = None
237 237
        for acc in self.store.query(userbase.LoginMethod):
238 238
            if acc.domain is None:
239 -
                print(acc.localpart, end='')
239 +
                print(acc.localpart, end=u'')
240 240
            else:
241 -
                print(acc.localpart + '@' + acc.domain, end='')
241 +
                print(acc.localpart + u'@' + acc.domain, end=u'')
242 242
            if acc.account.disabled:
243 -
                print(' [DISABLED]')
243 +
                print(u' [DISABLED]')
244 244
            else:
245 -
                print()
245 +
                print(u'')
246 246
        if acc is None:
247 -
            print('No accounts')
247 +
            print(u'No accounts')
248 248
249 249
250 250

@@ -1,6 +1,8 @@
Loading
1 1
import six
2 2
# -*- test-case-name: axiom.test.test_slotmachine -*-
3 3
4 +
import six
5 +
4 6
hyper = super
5 7
6 8
_NOSLOT = object()

@@ -38,7 +38,7 @@
Loading
38 38
39 39
    def testSanity(self):
40 40
        store = Store()
41 -
        for i in xrange(self.ntimes):
41 +
        for i in range(self.ntimes):
42 42
            SimpleReferent(store=store, ref=Referee(store=store, topSecret=i))
43 43
            (referee,) = list(store.query(Referee))
44 44
            (referent,) = list(store.query(SimpleReferent))
@@ -223,7 +223,7 @@
Loading
223 223
        """
224 224
        store = Store()
225 225
        t = nonUpgradedItem(store=store)
226 -
        self.assertEquals(t.__legacy__, True)
226 +
        self.assertEqual(t.__legacy__, True)
227 227
        self.assertRaises(KeyError, store.objectCache.get, t.storeID)
228 228
        t2 = store.getItemByID(t.storeID)
229 229
        self.assertNotIdentical(t, t2)

@@ -279,7 +279,7 @@
Loading
279 279
        """
280 280
281 281
282 -
LOCAL, REMOTE = range(2)
282 +
LOCAL, REMOTE = list(range(2))
283 283
class IBatchProcessor(Interface):
284 284
    def addReliableListener(listener, style=LOCAL):
285 285
        """

@@ -27,9 +27,10 @@
Loading
27 27
        Shared part of file creation tests.
28 28
        """
29 29
        f = s.newFile('test', 'whatever.txt')
30 -
        f.write('crap')
30 +
        f.write(b'crap')
31 +
31 32
        def cb(fpath):
32 -
            self.assertEquals(fpath.open().read(), 'crap')
33 +
            self.assertEqual(fpath.open().read(), b'crap')
33 34
34 35
        return f.close().addCallback(cb)
35 36
@@ -70,7 +71,7 @@
Loading
70 71
        npath = self.mktemp()
71 72
        s = Store(spath)
72 73
        rel = s.newFile("test", "123")
73 -
        TEST_STR = "test 123"
74 +
        TEST_STR = b"test 123"
74 75
75 76
        def cb(fpath):
76 77
            fpath.setContent(TEST_STR)
@@ -83,7 +84,7 @@
Loading
83 84
            s2 = Store(npath)
84 85
            pti = list(s2.query(PathTesterItem))[0]
85 86
86 -
            self.assertEquals(pti.relpath.getContent(),
87 +
            self.assertEqual(pti.relpath.getContent(),
87 88
                              TEST_STR)
88 89
89 90
        return rel.close().addCallback(cb)

@@ -14,11 +14,14 @@
Loading
14 14
from axiom.item import Item
15 15
from axiom.attributes import reference, boolean, AND
16 16
from axiom.errors import ItemNotFound, DependencyError, UnsatisfiedRequirement
17 -
from six.moves import map
18 -
from six.moves import zip
17 +
import six
18 +
from six.moves import map, zip
19 19
20 -
#There is probably a cleaner way to do this.
21 -
_globalDependencyMap = {}
20 +
# There is probably a cleaner way to do this.
21 +
_globalDependencyMap = {
22 +
    # map depending-class: (depended-upon-class,
23 +
    # callable-to-customize-creation, reference-attribute)
24 +
}
22 25
23 26
def dependentsOf(cls):
24 27
    deps = _globalDependencyMap.get(cls, None)
@@ -60,24 +63,34 @@
Loading
60 63
        raise TypeError("dependsOn can be used only from a class definition.")
61 64
    ref = reference(reftype=itemType, doc=doc, indexed=indexed, allowNone=True,
62 65
                    whenDeleted=whenDeleted)
63 -
    if "__dependsOn_advice_data__" not in locals:
64 -
        addClassAdvisor(_dependsOn_advice)
66 +
    if "__dependsOn_advice_data__" not in locals and six.PY2:
67 +
        addClassAdvisor(dependable)
65 68
    locals.setdefault('__dependsOn_advice_data__', []).append(
66 -
    (itemType, itemCustomizer, ref))
69 +
        (itemType, itemCustomizer, ref)
70 +
    )
67 71
    return ref
68 72
69 -
def _dependsOn_advice(cls):
73 +
74 +
def dependable(cls):
75 +
    """
76 +
    Classes that use `dependsOn` in their bodies should be decorated with this
77 +
    as a class decorator, like so::
78 +
79 +
        @dependable
80 +
        class A(Item):
81 +
            b = dependsOn(B)
82 +
    """
70 83
    if cls in _globalDependencyMap:
71 -
        print("Double advising of %s. dependency map from first time: %s" % (
72 -
            cls, _globalDependencyMap[cls]))
73 -
        #bail if we end up here twice, somehow
84 +
        # bail if we end up here twice, somehow
74 85
        return cls
75 86
    for itemType, itemCustomizer, ref in cls.__dict__[
76 -
        '__dependsOn_advice_data__']:
87 +
        '__dependsOn_advice_data__'
88 +
    ]:
77 89
        classDependsOn(cls, itemType, itemCustomizer, ref)
78 90
    del cls.__dependsOn_advice_data__
79 91
    return cls
80 92
93 +
81 94
def classDependsOn(cls, itemType, itemCustomizer, ref):
82 95
    _globalDependencyMap.setdefault(cls, []).append(
83 96
        (itemType, itemCustomizer, ref))
@@ -119,7 +132,7 @@
Loading
119 132
        if (dc.installee.__class__ == self.__class__
120 133
            and self.__class__ in set(
121 134
            itertools.chain([blob[0][0] for blob in
122 -
                             _globalDependencyMap.values()]))):
135 +
                             list(_globalDependencyMap.values())]))):
123 136
            #Somebody got here before we did... let's punt
124 137
            raise DependencyError("An instance of %r is already "
125 138
                                  "installed on %r." % (self.__class__,

@@ -1,5 +1,5 @@
Loading
1 1
2 -
import operator, random
2 +
import operator, random, six
3 3
4 4
from twisted.trial.unittest import TestCase
5 5
@@ -71,12 +71,12 @@
Loading
71 71
        """
72 72
        s = Store()
73 73
        comparison = (A.reftoc == B.storeID)
74 -
        self.assertEquals(
74 +
        self.assertEqual(
75 75
            comparison.getQuery(s),
76 76
            '({}.[reftoc] = {}.oid)'.format(
77 77
                A.getTableName(s),
78 78
                B.getTableName(s)))
79 -
        self.assertEquals(comparison.getArgs(s), [])
79 +
        self.assertEqual(comparison.getArgs(s), [])
80 80
81 81
82 82
    def test_leftHandStoreIDComparison(self):
@@ -87,12 +87,12 @@
Loading
87 87
        """
88 88
        s = Store()
89 89
        comparison = (B.storeID == A.reftoc)
90 -
        self.assertEquals(
90 +
        self.assertEqual(
91 91
            comparison.getQuery(s),
92 92
            '({}.oid = {}.[reftoc])'.format(
93 93
                B.getTableName(s),
94 94
                A.getTableName(s)))
95 -
        self.assertEquals(comparison.getArgs(s), [])
95 +
        self.assertEqual(comparison.getArgs(s), [])
96 96
97 97
98 98
    def test_simplestQuery(self):
@@ -103,7 +103,7 @@
Loading
103 103
        s = Store()
104 104
        query = ItemQuery(s, A)
105 105
        sql, args = query._sqlAndArgs('SELECT', '*')
106 -
        self.assertEquals(
106 +
        self.assertEqual(
107 107
            sql,
108 108
            'SELECT * FROM {}'.format(A.getTableName(s)))
109 109
        self.assertEquals(args, [])
@@ -117,12 +117,12 @@
Loading
117 117
        s = Store()
118 118
        query = ItemQuery(s, E, E.amount == 0)
119 119
        sql, args = query._sqlAndArgs('SELECT', '*')
120 -
        self.assertEquals(
120 +
        self.assertEqual(
121 121
            sql,
122 122
            'SELECT * FROM {} WHERE ({}.[amount] = ?)'.format(
123 123
                E.getTableName(s),
124 124
                E.getTableName(s)))
125 -
        self.assertEquals(args, [0])
125 +
        self.assertEqual(args, [0])
126 126
127 127
128 128
    def test_simpleReferenceComparison(self):
@@ -133,13 +133,13 @@
Loading
133 133
        s = Store()
134 134
        query = ItemQuery(s, A, A.reftoc == A.storeID)
135 135
        sql, args = query._sqlAndArgs('SELECT', '*')
136 -
        self.assertEquals(
136 +
        self.assertEqual(
137 137
            sql,
138 138
            'SELECT * FROM {} WHERE ({}.[reftoc] = {}.oid)'.format(
139 139
                A.getTableName(s),
140 140
                A.getTableName(s),
141 141
                A.getTableName(s)))
142 -
        self.assertEquals(args, [])
142 +
        self.assertEqual(args, [])
143 143
144 144
145 145
    def test_reversedReferenceComparison(self):
@@ -151,13 +151,13 @@
Loading
151 151
        s = Store()
152 152
        query = ItemQuery(s, A, A.storeID == A.reftoc)
153 153
        sql, args = query._sqlAndArgs('SELECT', '*')
154 -
        self.assertEquals(
154 +
        self.assertEqual(
155 155
            sql,
156 156
            'SELECT * FROM {} WHERE ({}.oid = {}.[reftoc])'.format(
157 157
                A.getTableName(s),
158 158
                A.getTableName(s),
159 159
                A.getTableName(s)))
160 -
        self.assertEquals(args, [])
160 +
        self.assertEqual(args, [])
161 161
162 162
163 163
    def test_unionComparison(self):
@@ -169,7 +169,7 @@
Loading
169 169
        query = ItemQuery(s, A, AND(A.reftoc == B.storeID,
170 170
                                    B.cref == C.storeID))
171 171
        sql, args = query._sqlAndArgs('SELECT', '*')
172 -
        self.assertEquals(
172 +
        self.assertEqual(
173 173
            sql,
174 174
            'SELECT * FROM %s, %s, %s '
175 175
            'WHERE ((%s.[reftoc] = %s.oid) AND '
@@ -181,7 +181,7 @@
Loading
181 181
                B.getTableName(s),
182 182
                B.getTableName(s),
183 183
                C.getTableName(s)))
184 -
        self.assertEquals(args, [])
184 +
        self.assertEqual(args, [])
185 185
186 186
187 187
    def testBasicQuery(self):
@@ -189,41 +189,41 @@
Loading
189 189
190 190
        def entesten():
191 191
            c1 = C(store=s,
192 -
                   name=u'yes')
192 +
                   name='yes')
193 193
194 194
            c2 = C(store=s,
195 -
                   name=u'no')
195 +
                   name='no')
196 196
197 197
            A(store=s,
198 198
              reftoc=c1,
199 -
              type=u'testc')
199 +
              type='testc')
200 200
201 201
            A(store=s,
202 202
              reftoc=c2,
203 -
              type=u'testc')
203 +
              type='testc')
204 204
205 205
            A(store=s,
206 206
              reftoc=c1,
207 -
              type=u'testx')
207 +
              type='testx')
208 208
209 209
            yesb = B(store=s,
210 210
                     cref=c1,
211 -
                     name=u'correct')
211 +
                     name='correct')
212 212
213 213
            B(store=s,
214 214
              cref=c2,
215 -
              name=u'not correct')
215 +
              name='not correct')
216 216
217 217
            s.checkpoint()
218 218
219 219
            q = list(s.query(B,
220 -
                             AND(AND(C.name == u'yes',
221 -
                                     A.type == u'testc'),
220 +
                             AND(AND(C.name == 'yes',
221 +
                                     A.type == 'testc'),
222 222
                                 AND(C.storeID == B.cref,
223 223
                                     A.reftoc == C.storeID)),
224 224
                             ))
225 225
226 -
            self.assertEquals(q, [yesb])
226 +
            self.assertEqual(q, [yesb])
227 227
228 228
        s.transact(entesten)
229 229
        s.close()
@@ -235,7 +235,7 @@
Loading
235 235
        def createAndStuff():
236 236
            text1 = u'Hello, \u1234 world.'
237 237
            text2 = u'ThIs sTrInG iS nOt cAsE sEnSiTIvE.  \u4567'
238 -
            bytes1 = '\x00, punk'
238 +
            bytes1 = b'\x00, punk'
239 239
240 240
            x = ThingWithCharacterAndByteStrings(
241 241
                store=s,
@@ -249,55 +249,55 @@
Loading
249 249
                s.query(ThingWithCharacterAndByteStrings,
250 250
                        ThingWithCharacterAndByteStrings.characterString == text1.lower(),
251 251
                        ))
252 -
            self.failIf(q, q)
252 +
            self.assertFalse(q, q)
253 253
254 254
            q = list(
255 255
                s.query(ThingWithCharacterAndByteStrings,
256 256
                        ThingWithCharacterAndByteStrings.characterString == text1.upper(),
257 257
                        ))
258 -
            self.failIf(q, q)
258 +
            self.assertFalse(q, q)
259 259
260 260
            q = list(
261 261
                s.query(ThingWithCharacterAndByteStrings,
262 262
                        ThingWithCharacterAndByteStrings.characterString == text1,
263 263
                        ))
264 264
265 -
            self.assertEquals(q, [x])
265 +
            self.assertEqual(q, [x])
266 266
267 267
            q = list(
268 268
                s.query(ThingWithCharacterAndByteStrings,
269 269
                        ThingWithCharacterAndByteStrings.caseInsensitiveCharString == text2,
270 270
                        ))
271 271
272 -
            self.assertEquals(q, [x])
272 +
            self.assertEqual(q, [x])
273 273
274 274
            q = list(
275 275
                s.query(ThingWithCharacterAndByteStrings,
276 276
                        ThingWithCharacterAndByteStrings.caseInsensitiveCharString == text2.lower(),
277 277
                        ))
278 278
279 -
            self.assertEquals(q, [x])
279 +
            self.assertEqual(q, [x])
280 280
281 281
            q = list(
282 282
                s.query(ThingWithCharacterAndByteStrings,
283 283
                        ThingWithCharacterAndByteStrings.caseInsensitiveCharString == text2.upper(),
284 284
                        ))
285 285
286 -
            self.assertEquals(q, [x])
286 +
            self.assertEqual(q, [x])
287 287
288 288
            q = list(
289 289
                s.query(ThingWithCharacterAndByteStrings,
290 290
                        ThingWithCharacterAndByteStrings.byteString == bytes1,
291 291
                        ))
292 292
293 -
            self.assertEquals(q, [x])
293 +
            self.assertEqual(q, [x])
294 294
295 295
            q = list(
296 296
                s.query(ThingWithCharacterAndByteStrings,
297 297
                        ThingWithCharacterAndByteStrings.byteString == bytes1.upper(),
298 298
                        ))
299 299
300 -
            self.failIf(q, q)
300 +
            self.assertFalse(q, q)
301 301
302 302
        s.transact(createAndStuff)
303 303
        s.close()
@@ -306,27 +306,27 @@
Loading
306 306
    def testAggregateQueries(self):
307 307
        s = Store()
308 308
        def entesten():
309 -
            self.assertEquals(s.query(E).count(), 0)
310 -
            self.assertEquals(s.query(E).getColumn("amount").sum(), 0)
309 +
            self.assertEqual(s.query(E).count(), 0)
310 +
            self.assertEqual(s.query(E).getColumn("amount").sum(), 0)
311 311
312 -
            E(store=s, name=u'widgets', amount=37)
313 -
            E(store=s, name=u'widgets', amount=63)
314 -
            E(store=s, name=u'quatloos', amount=99, transaction=u'yes')
312 +
            E(store=s, name='widgets', amount=37)
313 +
            E(store=s, name='widgets', amount=63)
314 +
            E(store=s, name='quatloos', amount=99, transaction='yes')
315 315
            s.checkpoint()
316 -
            q = s.count(E, E.name == u'widgets')
317 -
            self.failUnlessEqual(q, 2)
318 -
            q = s.sum(E.amount, E.name == u'widgets')
319 -
            self.failUnlessEqual(q, 100)
316 +
            q = s.count(E, E.name == 'widgets')
317 +
            self.assertEqual(q, 2)
318 +
            q = s.sum(E.amount, E.name == 'widgets')
319 +
            self.assertEqual(q, 100)
320 320
        s.transact(entesten)
321 321
        s.close()
322 322
323 323
    def testAttributeQueries(self):
324 324
        s = Store()
325 325
        def entesten():
326 -
            E(store=s, name=u'b', amount=456)
327 -
            E(store=s, name=u'a', amount=123)
328 -
            E(store=s, name=u'c', amount=789)
329 -
            self.assertEquals(list(s.query(E, sort=E.name.ascending).getColumn("amount")),
326 +
            E(store=s, name='b', amount=456)
327 +
            E(store=s, name='a', amount=123)
328 +
            E(store=s, name='c', amount=789)
329 +
            self.assertEqual(list(s.query(E, sort=E.name.ascending).getColumn("amount")),
330 330
                              [123, 456, 789])
331 331
332 332
        s.transact(entesten)
@@ -335,21 +335,21 @@
Loading
335 335
    def testAttributeQueryCount(self):
336 336
        s = Store()
337 337
        def entesten():
338 -
            E(store=s, name=u'a', amount=123)
339 -
            E(store=s, name=u'b', amount=456)
340 -
            E(store=s, name=u'c')  # no amount given
341 -
            self.assertEquals(s.query(E).getColumn("amount").count(), 2)
338 +
            E(store=s, name='a', amount=123)
339 +
            E(store=s, name='b', amount=456)
340 +
            E(store=s, name='c')  # no amount given
341 +
            self.assertEqual(s.query(E).getColumn("amount").count(), 2)
342 342
        s.transact(entesten)
343 343
        s.close()
344 344
345 345
    def testAttributeQueryDistinct(self):
346 346
        s = Store()
347 347
        def entesten():
348 -
            E(store=s, name=u'a', amount=123)
349 -
            E(store=s, name=u'b', amount=789)
350 -
            E(store=s, name=u'a', amount=456)
351 -
            self.assertEquals(list(s.query(E, sort=E.name.ascending).getColumn("name").distinct()),
352 -
                              [u"a", u"b"])
348 +
            E(store=s, name='a', amount=123)
349 +
            E(store=s, name='b', amount=789)
350 +
            E(store=s, name='a', amount=456)
351 +
            self.assertEqual(list(s.query(E, sort=E.name.ascending).getColumn("name").distinct()),
352 +
                              ["a", "b"])
353 353
        s.transact(entesten)
354 354
        s.close()
355 355
@@ -369,10 +369,10 @@
Loading
369 369
        """
370 370
        s = Store()
371 371
        def entesten():
372 -
            C(store=s, name=u'a')
373 -
            C(store=s, name=u'b')
372 +
            C(store=s, name='a')
373 +
            C(store=s, name='b')
374 374
            q = s.query(C, C.name != None).getColumn('name').distinct()
375 -
            self.assertEqual(sorted(q), [u'a', u'b'])
375 +
            self.assertEqual(sorted(q), ['a', 'b'])
376 376
        s.transact(entesten)
377 377
        s.close()
378 378
@@ -384,11 +384,11 @@
Loading
384 384
        """
385 385
        s = Store()
386 386
        def entesten():
387 -
            theC = C(store=s, name=u'it')
387 +
            theC = C(store=s, name='it')
388 388
            B(store=s, cref=theC)
389 389
            B(store=s, cref=theC)
390 390
            B(store=s, cref=theC)
391 -
            self.assertEquals(list(s.query(C, B.cref == C.storeID).distinct()),
391 +
            self.assertEqual(list(s.query(C, B.cref == C.storeID).distinct()),
392 392
                              [theC])
393 393
        s.transact(entesten)
394 394
        s.close()
@@ -401,11 +401,11 @@
Loading
401 401
        """
402 402
        s = Store()
403 403
        def entesten():
404 -
            for n, name in (2, u'it'), (3, u'indefinite nominative'):
404 +
            for n, name in (2, 'it'), (3, 'indefinite nominative'):
405 405
                theC = C(store=s, name=name)
406 406
                for i in range(n):
407 407
                    B(store=s, cref=theC)
408 -
            self.assertEquals(
408 +
            self.assertEqual(
409 409
                s.query(C, B.cref == C.storeID).distinct().count(),
410 410
                2)
411 411
        s.transact(entesten)
@@ -523,14 +523,14 @@
Loading
523 523
            E(store=s, amount=99)
524 524
            E(store=s, amount=456)
525 525
526 -
            self.assertEquals(s.query(E).getColumn("amount").min(), -4)
527 -
            self.assertEquals(s.query(E).getColumn("amount").max(), 456)
526 +
            self.assertEqual(s.query(E).getColumn("amount").min(), -4)
527 +
            self.assertEqual(s.query(E).getColumn("amount").max(), 456)
528 528
529 529
            self.assertRaises(ValueError, s.query(D).getColumn("id").max)
530 530
            self.assertRaises(ValueError, s.query(D).getColumn("id").min)
531 531
532 -
            self.assertEquals(s.query(D).getColumn("id").min(default=41), 41)
533 -
            self.assertEquals(s.query(D).getColumn("id").max(default=42), 42)
532 +
            self.assertEqual(s.query(D).getColumn("id").min(default=41), 41)
533 +
            self.assertEqual(s.query(D).getColumn("id").max(default=42), 42)
534 534
535 535
536 536
        s.transact(entesten)
@@ -596,26 +596,26 @@
Loading
596 596
        s = Store()
597 597
        def entesten():
598 598
            for i in range(3):
599 -
                c = C(store=s, name=u"C.%s" % i)
600 -
                B(store=s, name=u"B.%s" % (2-i), cref=c)
599 +
                c = C(store=s, name="C.%s" % i)
600 +
                B(store=s, name="B.%s" % (2-i), cref=c)
601 601
602 602
            query = s.query( (B, C),
603 603
                             B.cref == C.storeID,
604 604
                             sort=C.name.ascending)
605 605
606 -
            self.assertEquals(query.count(), 3)
606 +
            self.assertEqual(query.count(), 3)
607 607
608 608
            result = next(iter(query))
609 609
610 -
            self.assertEquals(len(result), 2)
610 +
            self.assertEqual(len(result), 2)
611 611
612 612
            b, c = result
613 613
614 614
            self.assertTrue(isinstance(b, B))
615 615
            self.assertTrue(isinstance(c, C))
616 616
617 -
            self.assertEquals(b.name, u"B.2")
618 -
            self.assertEquals(c.name, u"C.0")
617 +
            self.assertEqual(b.name, "B.2")
618 +
            self.assertEqual(c.name, "C.0")
619 619
620 620
        s.transact(entesten)
621 621
        s.close()
@@ -628,16 +628,16 @@
Loading
628 628
        s = Store()
629 629
        def entesten():
630 630
            for i in range(3):
631 -
                c = C(store=s, name=u"C.%s" % i)
632 -
                B(store=s, name=u"B.%s" % (2-i), cref=c)
633 -
                B(store=s, name=u"B2.%s" % (2-i), cref=c)
631 +
                c = C(store=s, name="C.%s" % i)
632 +
                B(store=s, name="B.%s" % (2-i), cref=c)
633 +
                B(store=s, name="B2.%s" % (2-i), cref=c)
634 634
635 635
            query = s.query( (B, C),
636 636
                             B.cref == C.storeID)
637 637
638 638
            totalCombinations = 6
639 639
640 -
            self.assertEquals(query.count(), totalCombinations)
640 +
            self.assertEqual(query.count(), totalCombinations)
641 641
642 642
            for offset in range(totalCombinations):
643 643
                for limit in range(totalCombinations + 1):
@@ -661,25 +661,25 @@
Loading
661 661
        s = Store()
662 662
        def entesten():
663 663
            for i in range(3):
664 -
                c = C(store=s, name=u"C.%s" % i)
665 -
                b = B(store=s, name=u"B.%s" % i, cref=c)
666 -
                A(store=s, type=u"A.%s" % i, reftoc=b)
667 -
                A(store=s, type=u"A.%s" % i, reftoc=b)
664 +
                c = C(store=s, name="C.%s" % i)
665 +
                b = B(store=s, name="B.%s" % i, cref=c)
666 +
                A(store=s, type="A.%s" % i, reftoc=b)
667 +
                A(store=s, type="A.%s" % i, reftoc=b)
668 668
669 669
            query = s.query( (B, C),
670 670
                             AND(B.cref == C.storeID,
671 671
                                 A.reftoc == B.storeID),
672 672
                             sort = C.name.ascending )
673 673
674 -
            self.assertEquals(query.count(), 6)
674 +
            self.assertEqual(query.count(), 6)
675 675
676 676
            distinct = query.distinct()
677 677
678 -
            self.assertEquals(distinct.count(), 3)
678 +
            self.assertEqual(distinct.count(), 3)
679 679
680 680
            for i, (b, c) in enumerate(query.distinct()):
681 -
                self.assertEquals(b.name, u"B.%s" % i)
682 -
                self.assertEquals(c.name, u"C.%s" % i)
681 +
                self.assertEqual(b.name, "B.%s" % i)
682 +
                self.assertEqual(c.name, "C.%s" % i)
683 683
684 684
        s.transact(entesten)
685 685
        s.close()
@@ -691,10 +691,10 @@
Loading
691 691
        """
692 692
        s = Store()
693 693
        def entesten():
694 -
            pops = B(store=s, name=u"Pops")
695 -
            dad = B(store=s, name=u"Dad", cref=pops)
696 -
            B(store=s, name=u"Bro", cref=dad)
697 -
            B(store=s, name=u"Sis", cref=dad)
694 +
            pops = B(store=s, name="Pops")
695 +
            dad = B(store=s, name="Dad", cref=pops)
696 +
            B(store=s, name="Bro", cref=dad)
697 +
            B(store=s, name="Sis", cref=dad)
698 698
699 699
            Gen1 = Placeholder(B)
700 700
            Gen2 = Placeholder(B)
@@ -705,7 +705,7 @@
Loading
705 705
                                 Gen2.cref == Gen1.storeID),
706 706
                             sort=Gen3.name.ascending )
707 707
708 -
            self.assertEquals(query.count(), 2)
708 +
            self.assertEqual(query.count(), 2)
709 709
710 710
            self.assertEquals(tuple(b.name for b in next(iter(query))),
711 711
                              (u"Pops", u"Dad", u"Bro"))
@@ -719,12 +719,12 @@
Loading
719 719
        s = Store()
720 720
        def entesten():
721 721
            for i in range(3):
722 -
                C(store=s, name=u"C.%s" % i)
722 +
                C(store=s, name="C.%s" % i)
723 723
724 724
            query = s.query( (C,),
725 725
                             sort=C.name.ascending)
726 726
727 -
            self.assertEquals(query.count(), 3)
727 +
            self.assertEqual(query.count(), 3)
728 728
729 729
            results = iter(query)
730 730
@@ -733,7 +733,7 @@
Loading
733 733
                self.assertEquals(len(result), 1)
734 734
                c, = result
735 735
                self.assertTrue(isinstance(c, C), "%s is not a C" % c)
736 -
                self.assertEquals(c.name, u"C.%s" % i, i)
736 +
                self.assertEqual(c.name, "C.%s" % i, i)
737 737
738 738
        s.transact(entesten)
739 739
        s.close()
@@ -846,9 +846,12 @@
Loading
846 846
    def setUp(self):
847 847
        s = self.store = Store()
848 848
        def _createStuff():
849 -
            self.d1 = D(store=s, one='d1.one', two='d1.two', three='d1.three', four=u'd1.four', id='1')
850 -
            self.d2 = D(store=s, one='d2.one', two='d2.two', three='d2.three', four=u'd2.four', id='2')
851 -
            self.d3 = D(store=s, one='d3.one', two='d3.two', three='d3.three', four=u'd3.four', id='3')
849 +
            self.d1 = D(store=s, one=b'd1.one', two=b'd1.two',
850 +
                        three=b'd1.three', four=u'd1.four', id=b'1')
851 +
            self.d2 = D(store=s, one=b'd2.one', two=b'd2.two',
852 +
                        three=b'd2.three', four=u'd2.four', id=b'2')
853 +
            self.d3 = D(store=s, one=b'd3.one', two=b'd3.two',
854 +
                        three=b'd3.three', four=u'd3.four', id=b'3')
852 855
        s.transact(_createStuff)
853 856
854 857
    def tearDown(self):
@@ -885,12 +888,12 @@
Loading
885 888
            args = []
886 889
887 890
        sql = query.getQuery(self.store)
888 -
        self.assertEquals(
891 +
        self.assertEqual(
889 892
            sql,
890 893
            expected,
891 894
            "\n%r != %r\n(if SQL generation code has changed, maybe this test "
892 895
            "should be updated)\n" % (sql, expected))
893 -
        self.assertEquals([str(a) for a in query.getArgs(self.store)], args)
896 +
        self.assertEqual([bytes(a) for a in query.getArgs(self.store)], args)
894 897
895 898
896 899
@@ -914,7 +917,7 @@
Loading
914 917
        only the table for the type being queried.
915 918
        """
916 919
        store = Store()
917 -
        query = store.query(A, A.type == u'value')
920 +
        query = store.query(A, A.type == 'value')
918 921
        self.assertEqual(query.fromClauseParts, [store.getTableName(A)])
919 922
920 923
@@ -947,7 +950,7 @@
Loading
947 950
        queried included in the FROM clause.
948 951
        """
949 952
        store = Store()
950 -
        query = store.query(A, A.type == u'value', sort=A.type.ascending)
953 +
        query = store.query(A, A.type == 'value', sort=A.type.ascending)
951 954
        self.assertEqual(query.fromClauseParts, [store.getTableName(A)])
952 955
953 956
@@ -959,7 +962,7 @@
Loading
959 962
        store = Store()
960 963
        self.assertRaises(
961 964
            ValueError,
962 -
            store.query, A, B.name == u'value')
965 +
            store.query, A, B.name == 'value')
963 966
964 967
965 968
    def test_invalidSort(self):
@@ -1038,14 +1041,14 @@
Loading
1038 1041
            OR(A.type == u'Narf!'),
1039 1042
            '(({} = ?))'.format(A.type.getColumnName(self.store)),
1040 1043
            ['Narf!'])
1041 -
        self.assertEquals(self.query(D, AND(D.one == 'd1.one')), [self.d1])
1042 -
        self.assertEquals(self.query(D, OR(D.one == 'd1.one')), [self.d1])
1044 +
        self.assertEqual(self.query(D, AND(D.one == b'd1.one')), [self.d1])
1045 +
        self.assertEqual(self.query(D, OR(D.one == b'd1.one')), [self.d1])
1043 1046
1044 1047
1045 1048
    def testMultipleAndConditions(self):
1046 -
        condition = AND(A.type == u'Narf!',
1047 -
                        A.type == u'Poiuyt!',
1048 -
                        A.type == u'Try to take over the world')
1049 +
        condition = AND(A.type == 'Narf!',
1050 +
                        A.type == 'Poiuyt!',
1051 +
                        A.type == 'Try to take over the world')
1049 1052
1050 1053
        expectedSQL = '((%s = ?) AND (%s = ?) AND (%s = ?))'
1051 1054
        expectedSQL %= (A.type.getColumnName(self.store),) * 3
@@ -1054,27 +1057,28 @@
Loading
1054 1057
            condition,
1055 1058
            expectedSQL,
1056 1059
            ['Narf!', 'Poiuyt!', 'Try to take over the world'])
1057 -
        self.assertEquals(
1058 -
            self.query(D, AND(D.one == 'd1.one',
1059 -
                              D.two == 'd1.two',
1060 -
                              D.three == 'd1.three')),
1060 +
        self.assertEqual(
1061 +
            self.query(D, AND(D.one == b'd1.one',
1062 +
                              D.two == b'd1.two',
1063 +
                              D.three == b'd1.three')),
1061 1064
            [self.d1])
1062 1065
1063 1066
    def testMultipleOrConditions(self):
1064 -
        condition = OR(A.type == u'Narf!',
1065 -
                       A.type == u'Poiuyt!',
1066 -
                       A.type == u'Try to take over the world')
1067 +
        condition = OR(A.type == 'Narf!',
1068 +
                       A.type == 'Poiuyt!',
1069 +
                       A.type == 'Try to take over the world')
1067 1070
        expectedSQL = '((%s = ?) OR (%s = ?) OR (%s = ?))'
1068 1071
        expectedSQL %= (A.type.getColumnName(self.store),) * 3
1069 1072
        self.assertQuery(
1070 1073
            condition,
1071 1074
            expectedSQL,
1072 1075
            ['Narf!', 'Poiuyt!', 'Try to take over the world'])
1073 -
        q = self.query(D, OR(D.one == 'd1.one',
1074 -
                             D.one == 'd2.one',
1075 -
                             D.one == 'd3.one'))
1076 +
        q = self.query(D, OR(D.one == b'd1.one',
1077 +
                             D.one == b'd2.one',
1078 +
                             D.one == b'd3.one'))
1076 1079
        e = [self.d1, self.d2, self.d3]
1077 -
        self.assertEquals(sorted(q), sorted(e))
1080 +
        self.assertEqual(sorted(q, key=lambda d: d.one),
1081 +
                         sorted(e, key=lambda d: d.one))
1078 1082
1079 1083
1080 1084
class SetMembershipQuery(QueryingTestCase):
@@ -1084,10 +1088,10 @@
Loading
1084 1088
        Test that comparing an attribute for containment against a value set
1085 1089
        generates the appropriate SQL.
1086 1090
        """
1087 -
        values = [u'a', u'b', u'c']
1091 +
        values = ['a', 'b', 'c']
1088 1092
        comparison = C.name.oneOf(values)
1089 -
        self.failUnless(IComparison.providedBy(comparison))
1090 -
        self.assertEquals(
1093 +
        self.assertTrue(IComparison.providedBy(comparison))
1094 +
        self.assertEqual(
1091 1095
            comparison.getQuery(self.store),
1092 1096
            '{} IN (?, ?, ?)'.format(
1093 1097
                C.name.getColumnName(self.store)))
@@ -1103,13 +1107,13 @@
Loading
1103 1107
        """
1104 1108
        values = A.type
1105 1109
        comparison = C.name.oneOf(values)
1106 -
        self.failUnless(IComparison.providedBy(comparison))
1107 -
        self.assertEquals(
1110 +
        self.assertTrue(IComparison.providedBy(comparison))
1111 +
        self.assertEqual(
1108 1112
            comparison.getQuery(self.store),
1109 1113
            '{} IN ({})'.format(
1110 1114
                C.name.getColumnName(self.store),
1111 1115
                A.type.getColumnName(self.store)))
1112 -
        self.assertEquals(
1116 +
        self.assertEqual(
1113 1117
            comparison.getArgs(self.store),
1114 1118
            [])
1115 1119
@@ -1121,14 +1125,14 @@
Loading
1121 1125
        """
1122 1126
        subselect = self.store.query(A).getColumn('type')
1123 1127
        comparison = C.name.oneOf(subselect)
1124 -
        self.failUnless(IComparison.providedBy(comparison))
1125 -
        self.assertEquals(
1128 +
        self.assertTrue(IComparison.providedBy(comparison))
1129 +
        self.assertEqual(
1126 1130
            comparison.getQuery(self.store),
1127 1131
            '{} IN (SELECT {} FROM {})'.format(
1128 1132
                C.name.getColumnName(self.store),
1129 1133
                A.type.getColumnName(self.store),
1130 1134
                A.getTableName(self.store)))
1131 -
        self.assertEquals(
1135 +
        self.assertEqual(
1132 1136
            comparison.getArgs(self.store),
1133 1137
            [])
1134 1138
@@ -1139,15 +1143,15 @@
Loading
1139 1143
        subselect and make sure they come out of the C{getArgs} method
1140 1144
        properly.
1141 1145
        """
1142 -
        value = '10'
1146 +
        value = b'10'
1143 1147
        subselect = self.store.query(
1144 1148
            D,
1145 1149
            AND(D.id == value,
1146 1150
                D.four == C.name)).getColumn('one')
1147 1151
1148 1152
        comparison = C.name.oneOf(subselect)
1149 -
        self.failUnless(IComparison.providedBy(comparison))
1150 -
        self.assertEquals(
1153 +
        self.assertTrue(IComparison.providedBy(comparison))
1154 +
        self.assertEqual(
1151 1155
            comparison.getQuery(self.store),
1152 1156
            '{} IN (SELECT {} FROM {}, {} WHERE (({} = ?) AND ({} = {})))'.format(
1153 1157
                C.name.getColumnName(self.store),
@@ -1158,27 +1162,27 @@
Loading
1158 1162
                D.four.getColumnName(self.store),
1159 1163
                C.name.getColumnName(self.store)))
1160 1164
        self.assertEquals(
1161 -
            list(map(str, comparison.getArgs(self.store))),
1165 +
            list(comparison.getArgs(self.store)),
1162 1166
            [value])
1163 1167
1164 1168
1165 1169
    def testOneOfWithList(self):
1166 -
        cx = C(store=self.store, name=u'x')
1167 -
        C(store=self.store, name=u'y')
1168 -
        cz = C(store=self.store, name=u'z')
1170 +
        cx = C(store=self.store, name='x')
1171 +
        C(store=self.store, name='y')
1172 +
        cz = C(store=self.store, name='z')
1169 1173
1170 1174
        query = self.store.query(
1171 -
            C, C.name.oneOf([u'x', u'z', u'a']), sort=C.name.ascending)
1175 +
            C, C.name.oneOf(['x', 'z', 'a']), sort=C.name.ascending)
1172 1176
1173 -
        self.assertEquals(list(query), [cx, cz])
1177 +
        self.assertEqual(list(query), [cx, cz])
1174 1178
1175 1179
1176 1180
    def testOneOfWithSet(self):
1177 1181
        s = Store()
1178 1182
1179 -
        cx = C(store=s, name=u'x')
1180 -
        C(store=s, name=u'y')
1181 -
        cz = C(store=s, name=u'z')
1183 +
        cx = C(store=s, name='x')
1184 +
        C(store=s, name='y')
1185 +
        cz = C(store=s, name='z')
1182 1186
1183 1187
        self.assertEquals(list(s.query(C, C.name.oneOf({u'x', u'z', u'a'}), sort=C.name.ascending)),
1184 1188
                          [cx, cz])
@@ -1212,42 +1216,43 @@
Loading
1212 1216
1213 1217
    def testOneString(self):
1214 1218
        self.assertQuery(
1215 -
            D.one.like('foobar%'),
1219 +
            D.one.like(b'foobar%'),
1216 1220
            '({} LIKE (?))'.format(D.one.getColumnName(self.store)),
1217 -
            ['foobar%'])
1221 +
            [b'foobar%'])
1218 1222
        self.assertQuery(
1219 -
            D.one.notLike('foobar%'),
1223 +
            D.one.notLike(b'foobar%'),
1220 1224
            '({} NOT LIKE (?))'.format(D.one.getColumnName(self.store)),
1221 -
            ['foobar%'])
1222 -
        self.assertEquals(self.query(D, D.four.like(u'd1.four')), [self.d1])
1223 -
        self.assertEquals(self.query(D, D.four.notLike(u'd%.four')), [])
1225 +
            [b'foobar%'])
1226 +
        self.assertEqual(self.query(D, D.four.like(u'd1.four')), [self.d1])
1227 +
        self.assertEqual(self.query(D, D.four.notLike(u'd%.four')), [])
1224 1228
1225 1229
    def testOneColumn(self):
1226 1230
        self.assertQuery(
1227 1231
            D.one.like(D.two),
1228 1232
            '({} LIKE ({}))'.format(D.one.getColumnName(self.store),
1229 1233
                                D.two.getColumnName(self.store)))
1230 -
        self.assertEquals(self.query(D, D.one.like(D.two)), [])
1234 +
        self.assertEqual(self.query(D, D.one.like(D.two)), [])
1231 1235
1232 1236
    def testOneColumnAndStrings(self):
1233 1237
        self.assertQuery(
1234 1238
            D.four.like(u'%', D.id, u'%four'),
1235 1239
            '({} LIKE (? || {} || ?))'.format(D.four.getColumnName(self.store),
1236 1240
                                          D.id.getColumnName(self.store)),
1237 -
            [u'%', u'%four'])
1238 -
        q = self.query(D, D.four.like(u'%', D.id, u'%four'))
1241 +
            ['%', '%four'])
1242 +
        q = self.query(D, D.four.like('%', D.id, '%four'))
1239 1243
        e = [self.d1, self.d2, self.d3]
1240 -
        self.assertEquals(sorted(q), sorted(e))
1244 +
        self.assertEqual(sorted(q, key=lambda d: d.id),
1245 +
                         sorted(e, key=lambda d: d.id))
1241 1246
1242 1247
    def testMultipleColumns(self):
1243 1248
        self.assertQuery(
1244 -
            D.one.like(D.two, '%', D.three),
1249 +
            D.one.like(D.two, b'%', D.three),
1245 1250
            '({} LIKE ({} || ? || {}))'.format(D.one.getColumnName(self.store),
1246 1251
                                           D.two.getColumnName(self.store),
1247 1252
                                           D.three.getColumnName(self.store)),
1248 -
            ['%'])
1249 -
        self.assertEquals(
1250 -
            self.query(D, D.one.like(D.two, '%', D.three)), [])
1253 +
            [b'%'])
1254 +
        self.assertEqual(
1255 +
            self.query(D, D.one.like(D.two, b'%', D.three)), [])
1251 1256
1252 1257
1253 1258
    def testStartsEndsWith(self):
@@ -1259,18 +1264,18 @@
Loading
1259 1264
            D.four.endswith(u'foo'),
1260 1265
            '({} LIKE (?))'.format(D.four.getColumnName(self.store)),
1261 1266
            ['%foo'])
1262 -
        self.assertEquals(
1263 -
            self.query(D, D.four.startswith(u'd1')), [self.d1])
1264 -
        self.assertEquals(
1265 -
            self.query(D, D.four.endswith(u'3.four')), [self.d3])
1267 +
        self.assertEqual(
1268 +
            self.query(D, D.four.startswith('d1')), [self.d1])
1269 +
        self.assertEqual(
1270 +
            self.query(D, D.four.endswith('3.four')), [self.d3])
1266 1271
1267 1272
1268 1273
    def testStartsEndsWithText(self):
1269 -
        self.assertEquals(
1270 -
            self.query(D, D.four.startswith(u'd1')),
1274 +
        self.assertEqual(
1275 +
            self.query(D, D.four.startswith('d1')),
1271 1276
            [self.d1])
1272 -
        self.assertEquals(
1273 -
            self.query(D, D.four.endswith(u'2.four')),
1277 +
        self.assertEqual(
1278 +
            self.query(D, D.four.endswith('2.four')),
1274 1279
            [self.d2])
1275 1280
1276 1281
@@ -1279,26 +1284,26 @@
Loading
1279 1284
1280 1285
    def setUp(self):
1281 1286
        s = self.s = Store()
1282 -
        self.c = C(store=s, name=u'unique')
1283 -
        self.dupc1 = C(store=s, name=u'non-unique')
1284 -
        self.dupc2 = C(store=s, name=u'non-unique')
1287 +
        self.c = C(store=s, name='unique')
1288 +
        self.dupc1 = C(store=s, name='non-unique')
1289 +
        self.dupc2 = C(store=s, name='non-unique')
1285 1290
1286 1291
    def testUniqueFound(self):
1287 -
        self.assertEquals(self.s.findUnique(C, C.name == u'unique'), self.c)
1292 +
        self.assertEqual(self.s.findUnique(C, C.name == 'unique'), self.c)
1288 1293
1289 1294
    def testUniqueNotFoundError(self):
1290 1295
        self.assertRaises(errors.ItemNotFound, self.s.findUnique,
1291 -
                          C, C.name == u'non-existent')
1296 +
                          C, C.name == 'non-existent')
1292 1297
1293 1298
    def testUniqueNotFoundDefault(self):
1294 1299
        bing = object()
1295 -
        self.assertEquals(bing, self.s.findUnique(
1296 -
                C, C.name == u'non-existent',
1300 +
        self.assertEqual(bing, self.s.findUnique(
1301 +
                C, C.name == 'non-existent',
1297 1302
                default=bing))
1298 1303
1299 1304
    def testUniqueDuplicate(self):
1300 1305
        self.assertRaises(errors.DuplicateUniqueItem,
1301 -
                          self.s.findUnique, C, C.name == u'non-unique')
1306 +
                          self.s.findUnique, C, C.name == 'non-unique')
1302 1307
1303 1308
1304 1309
@@ -1336,7 +1341,7 @@
Loading
1336 1341
        """
1337 1342
        s = Store()
1338 1343
        p = Placeholder(PlaceholderTestItem)
1339 -
        self.assertEquals(p.getTableName(s), PlaceholderTestItem.getTableName(s))
1344 +
        self.assertEqual(p.getTableName(s), PlaceholderTestItem.getTableName(s))
1340 1345
1341 1346
1342 1347
    def test_placeholderColumnInterface(self):
@@ -1345,7 +1350,7 @@
Loading
1345 1350
        """
1346 1351
        p = Placeholder(PlaceholderTestItem)
1347 1352
        a = p.attr
1348 -
        self.failUnless(IColumn.providedBy(a))
1353 +
        self.assertTrue(IColumn.providedBy(a))
1349 1354
1350 1355
1351 1356
    def test_placeholderAttributeValueComparison(self):
@@ -1357,8 +1362,8 @@
Loading
1357 1362
        value = 0
1358 1363
        p = Placeholder(PlaceholderTestItem)
1359 1364
        for op in COMPARISON_OPS:
1360 -
            self.failUnless(IComparison.providedBy(op(p.attr, value)))
1361 -
            self.failUnless(IComparison.providedBy(op(value, p.attr)))
1365 +
            self.assertTrue(IComparison.providedBy(op(p.attr, value)))
1366 +
            self.assertTrue(IComparison.providedBy(op(value, p.attr)))
1362 1367
1363 1368
1364 1369
    def test_placeholderAttributeColumnComparison(self):
@@ -1369,13 +1374,13 @@
Loading
1369 1374
        """
1370 1375
        p = Placeholder(PlaceholderTestItem)
1371 1376
        for op in COMPARISON_OPS:
1372 -
            self.failUnless(IComparison.providedBy(op(p.attr, PlaceholderTestItem.attr)))
1373 -
            self.failUnless(IComparison.providedBy(op(PlaceholderTestItem.attr, p.attr)))
1377 +
            self.assertTrue(IComparison.providedBy(op(p.attr, PlaceholderTestItem.attr)))
1378 +
            self.assertTrue(IComparison.providedBy(op(PlaceholderTestItem.attr, p.attr)))
1374 1379
1375 1380
1376 1381
    def _placeholderAttributeSimilarity(self, kind, sql, args):
1377 1382
        s = Store()
1378 -
        value = u'text'
1383 +
        value = 'text'
1379 1384
1380 1385
        p = Placeholder(PlaceholderTestItem)
1381 1386
@@ -1383,10 +1388,10 @@
Loading
1383 1388
        p.getTableAlias(s, ())
1384 1389
1385 1390
        comparison = getattr(p.characters, kind)(value)
1386 -
        self.failUnless(IComparison.providedBy(comparison))
1387 -
        self.assertEquals(comparison.getQuery(s),
1391 +
        self.assertTrue(IComparison.providedBy(comparison))
1392 +
        self.assertEqual(comparison.getQuery(s),
1388 1393
                          sql % (p.characters.getColumnName(s),))
1389 -
        self.assertEquals(
1394 +
        self.assertEqual(
1390 1395
            comparison.getArgs(s),
1391 1396
            [args % (value,)])
1392 1397
@@ -1433,8 +1438,8 @@
Loading
1433 1438
        p.getTableAlias(s, ())
1434 1439
1435 1440
        comparison = PlaceholderTestItem.attr.like(p.attr)
1436 -
        self.failUnless(IComparison.providedBy(comparison))
1437 -
        self.assertEquals(
1441 +
        self.assertTrue(IComparison.providedBy(comparison))
1442 +
        self.assertEqual(
1438 1443
            comparison.getQuery(s),
1439 1444
            '({} LIKE (placeholder_0.[attr]))'.format(
1440 1445
                PlaceholderTestItem.attr.getColumnName(s)))
@@ -1456,8 +1461,8 @@
Loading
1456 1461
        p.getTableAlias(s, ())
1457 1462
1458 1463
        comparison = p.attr.oneOf(value)
1459 -
        self.failUnless(IComparison.providedBy(comparison))
1460 -
        self.assertEquals(
1464 +
        self.assertTrue(IComparison.providedBy(comparison))
1465 +
        self.assertEqual(
1461 1466
            comparison.getQuery(s),
1462 1467
            '{} IN (?, ?, ?)'.format(p.attr.getColumnName(s)))
1463 1468
        self.assertEquals(
@@ -1478,8 +1483,8 @@
Loading
1478 1483
        p.getTableAlias(s, ())
1479 1484
1480 1485
        comparison = p.attr.notOneOf(value)
1481 -
        self.failUnless(IComparison.providedBy(comparison))
1482 -
        self.assertEquals(
1486 +
        self.assertTrue(IComparison.providedBy(comparison))
1487 +
        self.assertEqual(
1483 1488
            comparison.getQuery(s),
1484 1489
            '{} NOT IN (?, ?, ?)'.format(p.attr.getColumnName(s)))
1485 1490
        self.assertEquals(
@@ -1499,12 +1504,12 @@
Loading
1499 1504
        p.getTableAlias(s, ())
1500 1505
1501 1506
        comparison = PlaceholderTestItem.attr.oneOf(p.attr)
1502 -
        self.failUnless(IComparison.providedBy(comparison))
1503 -
        self.assertEquals(
1507 +
        self.assertTrue(IComparison.providedBy(comparison))
1508 +
        self.assertEqual(
1504 1509
            comparison.getQuery(s),
1505 1510
            '{} IN ({})'.format(PlaceholderTestItem.attr.getColumnName(s),
1506 1511
                            p.attr.getColumnName(s)))
1507 -
        self.assertEquals(
1512 +
        self.assertEqual(
1508 1513
            comparison.getArgs(s),
1509 1514
            [])
1510 1515
@@ -1521,12 +1526,12 @@
Loading
1521 1526
        p.getTableAlias(s, ())
1522 1527
1523 1528
        comparison = PlaceholderTestItem.attr.notOneOf(p.attr)
1524 -
        self.failUnless(IComparison.providedBy(comparison))
1525 -
        self.assertEquals(
1529 +
        self.assertTrue(IComparison.providedBy(comparison))
1530 +
        self.assertEqual(
1526 1531
            comparison.getQuery(s),
1527 1532
            '{} NOT IN ({})'.format(PlaceholderTestItem.attr.getColumnName(s),
1528 1533
                            p.attr.getColumnName(s)))
1529 -
        self.assertEquals(
1534 +
        self.assertEqual(
1530 1535
            comparison.getArgs(s),
1531 1536
            [])
1532 1537
@@ -1538,7 +1543,7 @@
Loading
1538 1543
        """
1539 1544
        value = 0
1540 1545
        p = Placeholder(PlaceholderTestItem)
1541 -
        self.failUnless(IComparison.providedBy(p.storeID > value))
1546 +
        self.assertTrue(IComparison.providedBy(p.storeID > value))
1542 1547
1543 1548
1544 1549
    def test_placeholderAttributeError(self):
@@ -1564,7 +1569,7 @@
Loading
1564 1569
        theTable = next(iter(involvedTables))
1565 1570
        self.assertEquals(theTable.getTableName(s),
1566 1571
                          PlaceholderTestItem.getTableName(s))
1567 -
        self.assertEquals(theTable.getTableAlias(s, ()),
1572 +
        self.assertEqual(theTable.getTableAlias(s, ()),
1568 1573
                          'placeholder_0')
1569 1574
1570 1575
@@ -1583,10 +1588,10 @@
Loading
1583 1588
1584 1589
        value = 0
1585 1590
        comparison = (p.attr > value)
1586 -
        self.assertEquals(
1591 +
        self.assertEqual(
1587 1592
            comparison.getQuery(s),
1588 1593
            '(placeholder_0.[attr] > ?)')
1589 -
        self.assertEquals(
1594 +
        self.assertEqual(
1590 1595
            comparison.getArgs(s),
1591 1596
            [value])
1592 1597
@@ -1601,7 +1606,7 @@
Loading
1601 1606
        p = Placeholder(PlaceholderTestItem)
1602 1607
        value = 0
1603 1608
        args = (p.attr > value).getArgs(s)
1604 -
        self.assertEquals(args, [0])
1609 +
        self.assertEqual(args, [0])
1605 1610
1606 1611
1607 1612
    def test_placeholderQuery(self):
@@ -1612,7 +1617,7 @@
Loading
1612 1617
        s = Store()
1613 1618
        p = Placeholder(PlaceholderTestItem)
1614 1619
        sql, args = ItemQuery(s, p)._sqlAndArgs('SELECT', '*')
1615 -
        self.assertEquals(
1620 +
        self.assertEqual(
1616 1621
            sql,
1617 1622
            'SELECT * FROM {} AS placeholder_0'.format(
1618 1623
                PlaceholderTestItem.getTableName(s)))
@@ -1647,7 +1652,7 @@
Loading
1647 1652
            PlaceholderTestItem,
1648 1653
            PlaceholderTestItem.attr == p.attr)
1649 1654
        sql, args = query._sqlAndArgs('SELECT', '*')
1650 -
        self.assertEquals(
1655 +
        self.assertEqual(
1651 1656
            sql,
1652 1657
            'SELECT * '
1653 1658
            'FROM %s, %s AS placeholder_0 '
@@ -1655,7 +1660,7 @@
Loading
1655 1660
                PlaceholderTestItem.getTableName(s),
1656 1661
                PlaceholderTestItem.getTableName(s),
1657 1662
                PlaceholderTestItem.getTableName(s)))
1658 -
        self.assertEquals(args, [])
1663 +
        self.assertEqual(args, [])
1659 1664
1660 1665
1661 1666
    def test_placeholderOrdering(self):
@@ -1665,14 +1670,14 @@
Loading
1665 1670
        """
1666 1671
        p1 = Placeholder(PlaceholderTestItem)
1667 1672
        p2 = Placeholder(PlaceholderTestItem)
1668 -
        self.failUnless(p1 < p2)
1669 -
        self.failUnless(p2 > p1)
1670 -
        self.failIf(p1 >= p2)
1671 -
        self.failIf(p2 <= p1)
1672 -
        self.failIf(p1 == p2)
1673 -
        self.failIf(p2 == p1)
1674 -
        self.failUnless(p1 != p2)
1675 -
        self.failUnless(p2 != p1)
1673 +
        self.assertTrue(p1 < p2)
1674 +
        self.assertTrue(p2 > p1)
1675 +
        self.assertFalse(p1 >= p2)
1676 +
        self.assertFalse(p2 <= p1)
1677 +
        self.assertFalse(p1 == p2)
1678 +
        self.assertFalse(p2 == p1)
1679 +
        self.assertTrue(p1 != p2)
1680 +
        self.assertTrue(p2 != p1)
1676 1681
1677 1682
1678 1683
    def test_placeholderObjectSorting(self):
@@ -1680,11 +1685,11 @@
Loading
1680 1685
        Placeholders should sort based on the order in which they were
1681 1686
        instantiated.
1682 1687
        """
1683 -
        placeholders = [Placeholder(PlaceholderTestItem) for n in xrange(10)]
1688 +
        placeholders = [Placeholder(PlaceholderTestItem) for n in range(10)]
1684 1689
        shuffledPlaceholders = list(placeholders)
1685 1690
        random.shuffle(shuffledPlaceholders)
1686 1691
        shuffledPlaceholders.sort()
1687 -
        self.assertEquals(placeholders, shuffledPlaceholders)
1692 +
        self.assertEqual(placeholders, shuffledPlaceholders)
1688 1693
1689 1694
1690 1695
    def test_placeholderAliasAssignment(self):
@@ -1696,11 +1701,11 @@
Loading
1696 1701
        p2 = Placeholder(PlaceholderTestItem)
1697 1702
1698 1703
        aliases = []
1699 -
        self.assertEquals(p1.getTableAlias(s, aliases), 'placeholder_0')
1700 -
        self.assertEquals(p1.getTableAlias(s, aliases), 'placeholder_0')
1704 +
        self.assertEqual(p1.getTableAlias(s, aliases), 'placeholder_0')
1705 +
        self.assertEqual(p1.getTableAlias(s, aliases), 'placeholder_0')
1701 1706
        aliases.append('placeholder_')
1702 -
        self.assertEquals(p1.getTableAlias(s, aliases), 'placeholder_0')
1703 -
        self.assertEquals(p2.getTableAlias(s, aliases), 'placeholder_1')
1707 +
        self.assertEqual(p1.getTableAlias(s, aliases), 'placeholder_0')
1708 +
        self.assertEqual(p2.getTableAlias(s, aliases), 'placeholder_1')
1704 1709
1705 1710
1706 1711
    def test_multiplePlaceholderComparisons(self):
@@ -1720,7 +1725,7 @@
Loading
1720 1725
                PlaceholderTestItem.attr == p2.attr,
1721 1726
                PlaceholderTestItem.characters == p2.characters))
1722 1727
        sql, args = query._sqlAndArgs('SELECT', '*')
1723 -
        self.assertEquals(
1728 +
        self.assertEqual(
1724 1729
            sql,
1725 1730
            'SELECT * '
1726 1731
            'FROM %s, %s AS placeholder_0, %s AS placeholder_1 '
@@ -1735,7 +1740,7 @@
Loading
1735 1740
                PlaceholderTestItem.other.getColumnName(s),
1736 1741
                PlaceholderTestItem.attr.getColumnName(s),
1737 1742
                PlaceholderTestItem.characters.getColumnName(s)))
1738 -
        self.assertEquals(args, [])
1743 +
        self.assertEqual(args, [])
1739 1744
1740 1745
1741 1746
    def test_sortByPlaceholderAttribute(self):
@@ -1756,8 +1761,8 @@
Loading
1756 1761
                       'ORDER BY placeholder_0.[attr] ASC')
1757 1762
        expectedSQL %= (p.getTableName(s),)
1758 1763
1759 -
        self.assertEquals(sql, expectedSQL)
1760 -
        self.assertEquals(args, [])
1764 +
        self.assertEqual(sql, expectedSQL)
1765 +
        self.assertEqual(args, [])
1761 1766
1762 1767
1763 1768
    def test_placeholderColumnNamesInQueryTarget(self):
@@ -1772,7 +1777,11 @@
Loading
1772 1777
1773 1778
        expectedSQL = "placeholder_0.oid, placeholder_0.[attr], placeholder_0.[characters], placeholder_0.[other]"
1774 1779
1775 -
        self.assertEquals(query._queryTarget, expectedSQL)
1780 +
        self.assertEqual(query._queryTarget, expectedSQL)
1781 +
1782 +
1783 +
1784 +
bytes_deprecated_prefix = 'axiom.attributes.bytes.' if six.PY3 else 'axiom.attributes.'
1776 1785
1777 1786
1778 1787
@@ -1783,7 +1792,7 @@
Loading
1783 1792
    def test_startsWith(self):
1784 1793
        self.assertWarns(
1785 1794
            DeprecationWarning,
1786 -
            'axiom.attributes.startswith was deprecated in Axiom 0.7.5',
1795 +
            bytes_deprecated_prefix + 'startswith was deprecated in Axiom 0.7.5',
1787 1796
            __file__,
1788 1797
            lambda: D.one.startswith('string'))
1789 1798
@@ -1791,7 +1800,7 @@
Loading
1791 1800
    def test_endsWith(self):
1792 1801
        self.assertWarns(
1793 1802
            DeprecationWarning,
1794 -
            'axiom.attributes.endswith was deprecated in Axiom 0.7.5',
1803 +
            bytes_deprecated_prefix + 'endswith was deprecated in Axiom 0.7.5',
1795 1804
            __file__,
1796 1805
            lambda: D.one.endswith('string'))
1797 1806
@@ -1799,7 +1808,7 @@
Loading
1799 1808
    def test_like(self):
1800 1809
        self.assertWarns(
1801 1810
            DeprecationWarning,
1802 -
            'axiom.attributes.like was deprecated in Axiom 0.7.5',
1811 +
            bytes_deprecated_prefix + 'like was deprecated in Axiom 0.7.5',
1803 1812
            __file__,
1804 1813
            lambda: D.one.like('string'))
1805 1814
@@ -1807,6 +1816,6 @@
Loading
1807 1816
    def test_notLike(self):
1808 1817
        self.assertWarns(
1809 1818
            DeprecationWarning,
1810 -
            'axiom.attributes.notLike was deprecated in Axiom 0.7.5',
1819 +
            bytes_deprecated_prefix + 'notLike was deprecated in Axiom 0.7.5',
1811 1820
            __file__,
1812 1821
            lambda: D.one.notLike('string'))

@@ -48,9 +48,9 @@
Loading
48 48
    def testSanity(self):
49 49
        xyz = XYZ()
50 50
        val = xyz.m()
51 -
        self.assertEquals(val, 3)
51 +
        self.assertEqual(val, 3)
52 52
53 53
    def testItemSanity(self):
54 54
        xyz = ItemXYZ()
55 55
        val = xyz.m()
56 -
        self.assertEquals(val, 3)
56 +
        self.assertEqual(val, 3)

@@ -77,10 +77,10 @@
Loading
77 77
        s2 = store.Store(storedir)
78 78
        a1 = A(store=s1)
79 79
        a2 = A(store=s2)
80 -
        self.assertEquals(list(s1.query(
80 +
        self.assertEqual(list(s1.query(
81 81
                    A, sort=A.storeID.ascending).getColumn("storeID")),
82 82
                          [a1.storeID, a2.storeID])
83 -
        self.assertEquals(list(s2.query(
83 +
        self.assertEqual(list(s2.query(
84 84
                    A, sort=A.storeID.ascending).getColumn("storeID")),
85 85
                          [a1.storeID, a2.storeID])
86 86

@@ -33,18 +33,18 @@
Loading
33 33
        s = Store()
34 34
        Number(store=s, value=7.1)
35 35
        n = s.findFirst(Number)
36 -
        self.assertEquals(n.value, 7.1)
36 +
        self.assertEqual(n.value, 7.1)
37 37
38 38
    def testFPSumsAreBrokenSoDontUseThem(self):
39 39
        s = Store()
40 40
        for x in range(10):
41 41
            Number(store=s,
42 42
                   value=0.1)
43 -
        self.assertNotEquals(s.query(Number).getColumn("value").sum(),
43 +
        self.assertNotEqual(s.query(Number).getColumn("value").sum(),
44 44
                             1.0)
45 45
46 46
        # This isn't really a unit test.  It's documentation.
47 -
        self.assertEquals(s.query(Number).getColumn("value").sum(),
47 +
        self.assertEqual(s.query(Number).getColumn("value").sum(),
48 48
                          0.99999999999999989)
49 49
50 50
@@ -70,15 +70,15 @@
Loading
70 70
        A Python int roundtrips through an integer attribute.
71 71
        """
72 72
        i = _Integer(store=self.store, value=42)
73 -
        self.assertEquals(i.value, 42)
73 +
        self.assertEqual(i.value, 42)
74 74
75 75
76 76
    def test_roundtripLong(self):
77 77
        """
78 78
        A Python long roundtrips through an integer attribute.
79 79
        """
80 -
        i = _Integer(store=self.store, value=42L)
81 -
        self.assertEquals(i.value, 42)
80 +
        i = _Integer(store=self.store, value=42)
81 +
        self.assertEqual(i.value, 42)
82 82
83 83
84 84
    def test_magnitudeBound(self):
@@ -107,7 +107,7 @@
Loading
107 107
        for x in range(10):
108 108
            DecimalDoodad(store=s,
109 109
                          money=Decimal("0.10"))
110 -
        self.assertEquals(s.query(DecimalDoodad).getColumn("money").sum(),
110 +
        self.assertEqual(s.query(DecimalDoodad).getColumn("money").sum(),
111 111
                          1)
112 112
113 113
    def testRoundTrip(self):
@@ -116,28 +116,28 @@
Loading
116 116
                      money=Decimal("4.3"),
117 117
                      otherMoney=Decimal("-17.94"))
118 118
        gc.collect() # Force the item to be reloaded from the database
119 -
        self.assertEquals(s.findFirst(DecimalDoodad).integral, 19947)
120 -
        self.assertEquals(s.findFirst(DecimalDoodad).money, Decimal("4.3"))
121 -
        self.assertEquals(s.findFirst(DecimalDoodad).otherMoney, Decimal("-17.9400"))
119 +
        self.assertEqual(s.findFirst(DecimalDoodad).integral, 19947)
120 +
        self.assertEqual(s.findFirst(DecimalDoodad).money, Decimal("4.3"))
121 +
        self.assertEqual(s.findFirst(DecimalDoodad).otherMoney, Decimal("-17.9400"))
122 122
123 123
    def testComparisons(self):
124 124
        s = Store()
125 125
        DecimalDoodad(store=s,
126 126
                      money=Decimal("19947.000000"),
127 127
                      otherMoney=19947)
128 -
        self.assertEquals(
128 +
        self.assertEqual(
129 129
            s.query(DecimalDoodad,
130 130
                    DecimalDoodad.money == DecimalDoodad.otherMoney).count(),
131 131
            1)
132 -
        self.assertEquals(
132 +
        self.assertEqual(
133 133
            s.query(DecimalDoodad,
134 134
                    DecimalDoodad.money != DecimalDoodad.otherMoney).count(),
135 135
            0)
136 -
        self.assertEquals(
136 +
        self.assertEqual(
137 137
            s.query(DecimalDoodad,
138 138
                    DecimalDoodad.money == 19947).count(),
139 139
            1)
140 -
        self.assertEquals(
140 +
        self.assertEqual(
141 141
            s.query(DecimalDoodad,
142 142
                    DecimalDoodad.money == Decimal("19947")).count(),
143 143
            1)
@@ -178,7 +178,7 @@
Loading
178 178
        sid = Number(store=s, value=1.0).storeID
179 179
        self.assertRaises(TypeError, s.getItemByID, str(sid))
180 180
        self.assertRaises(TypeError, s.getItemByID, float(sid))
181 -
        self.assertRaises(TypeError, s.getItemByID, unicode(sid))
181 +
        self.assertRaises(TypeError, s.getItemByID, str(sid))
182 182
183 183
class SortedItem(Item):
184 184
    typeName = 'test_sorted_thing'
@@ -193,7 +193,7 @@
Loading
193 193
    def testCompoundSort(self):
194 194
        s = Store()
195 195
        L = []
196 -
        r10 = range(10)
196 +
        r10 = list(range(10))
197 197
        random.shuffle(r10)
198 198
        L.append(SortedItem(store=s,
199 199
                            goingUp=0,
@@ -216,15 +216,15 @@
Loading
216 216
            ascsort = [getattr(SortedItem, colnm).ascending for colnm in colnms]
217 217
            descsort = [getattr(SortedItem, colnm).descending for colnm in colnms]
218 218
219 -
            self.assertEquals(LN, list(s.query(SortedItem,
219 +
            self.assertEqual(LN, list(s.query(SortedItem,
220 220
                                               sort=ascsort)))
221 221
            LN.reverse()
222 -
            self.assertEquals(LN, list(s.query(SortedItem,
222 +
            self.assertEqual(LN, list(s.query(SortedItem,
223 223
                                               sort=descsort)))
224 224
225 225
226 226
class FunkyItem(Item):
227 -
    name = unicode()
227 +
    name = str()
228 228
229 229
class BadAttributeTest(TestCase):
230 230
@@ -233,9 +233,9 @@
Loading
233 233
        L{Item} should not allow setting undeclared attributes.
234 234
        """
235 235
        s = Store()
236 -
        err = self.failUnlessRaises(AttributeError,
237 -
                                    FunkyItem, store=s, name=u"foo")
238 -
        self.assertEquals(str(err), "'FunkyItem' can't set attribute 'name'")
236 +
        err = self.assertRaises(AttributeError,
237 +
                                    FunkyItem, store=s, name="foo")
238 +
        self.assertEqual(str(err), "'FunkyItem' can't set attribute 'name'")
239 239
240 240
241 241
@@ -276,13 +276,13 @@
Loading
276 276
    def testTimestampDefault(self):
277 277
        s = Store()
278 278
        sid = DatedThing(store=s).storeID
279 -
        self.assertEquals(s.getItemByID(sid).date,
279 +
        self.assertEqual(s.getItemByID(sid).date,
280 280
                          someRandomDate)
281 281
282 282
    def testTimestampNow(self):
283 283
        s = Store()
284 284
        sid = CreationDatedThing(store=s).storeID
285 -
        self.failUnless(
285 +
        self.assertTrue(
286 286
            (Time().asDatetime() - s.getItemByID(sid).creationDate.asDatetime()).seconds <
287 287
            10)
288 288
@@ -301,20 +301,20 @@
Loading
301 301
        """
302 302
        s = Store()
303 303
        tlt = TaggedListyThing(store=s, strlist=value)
304 -
        self.assertEquals(tlt.strlist, value)
304 +
        self.assertEqual(tlt.strlist, value)
305 305
306 306
        # Force it out of the cache, so it gets reloaded from the store
307 307
        del tlt
308 308
        gc.collect()
309 309
        tlt = s.findUnique(TaggedListyThing)
310 -
        self.assertEquals(tlt.strlist, value)
310 +
        self.assertEqual(tlt.strlist, value)
311 311
312 312
313 313
    def test_simpleListOfStrings(self):
314 314
        """
315 315
        Test that a simple list can be stored and retrieved successfully.
316 316
        """
317 -
        SOME_VALUE = [u'abc', u'def, ghi', u'jkl']
317 +
        SOME_VALUE = ['abc', 'def, ghi', 'jkl']
318 318
        self.tryRoundtrip(SOME_VALUE)
319 319
320 320
@@ -332,10 +332,10 @@
Loading
332 332
        """
333 333
334 334
        oldCases = [
335 -
            (u'foo', [u'foo']),
336 -
            (u'', [u'']),
337 -
            (u'\x1f', [u'', u'']),
338 -
            (u'foo\x1fbar', [u'foo', u'bar']),
335 +
            ('foo', ['foo']),
336 +
            ('', ['']),
337 +
            ('\x1f', ['', '']),
338 +
            ('foo\x1fbar', ['foo', 'bar']),
339 339
            ]
340 340
341 341
        for dbval, pyval in oldCases:
@@ -370,7 +370,7 @@
Loading
370 370
        """
371 371
        Test that an L{SQLAttribute} knows its own local name.
372 372
        """
373 -
        self.assertEquals(
373 +
        self.assertEqual(
374 374
            SQLAttributeDummyClass.dummyAttribute.attrname,
375 375
            'dummyAttribute')
376 376
@@ -382,7 +382,7 @@
Loading
382 382
        fully qualified Python name of the type it is defined on (plus a dot)
383 383
        plus the name of the attribute.
384 384
        """
385 -
        self.assertEquals(
385 +
        self.assertEqual(
386 386
            SQLAttributeDummyClass.dummyAttribute.fullyQualifiedName(),
387 387
            'axiom.test.test_attributes.SQLAttributeDummyClass.dummyAttribute')
388 388
@@ -394,7 +394,7 @@
Loading
394 394
        is unfortunately implemented differently than other columns, due to its
395 395
        presence on Item.
396 396
        """
397 -
        self.assertEquals(
397 +
        self.assertEqual(
398 398
            SQLAttributeDummyClass.storeID.fullyQualifiedName(),
399 399
            'axiom.test.test_attributes.SQLAttributeDummyClass.storeID')
400 400
@@ -406,7 +406,7 @@
Loading
406 406
        recognizable as an invalid Python identifier.
407 407
        """
408 408
        ph = Placeholder(SQLAttributeDummyClass)
409 -
        self.assertEquals(
409 +
        self.assertEqual(
410 410
            'axiom.test.test_attributes.SQLAttributeDummyClass'
411 411
            '.dummyAttribute.<placeholder:%d>' % (ph._placeholderCount,),
412 412
            ph.dummyAttribute.fullyQualifiedName())
@@ -418,9 +418,9 @@
Loading
418 418
        its value when given an instance.
419 419
        """
420 420
        dummy = FullImplementationDummyClass(dummyAttribute=1234)
421 -
        self.assertEquals(
421 +
        self.assertEqual(
422 422
            FullImplementationDummyClass.dummyAttribute.__get__(dummy), 1234)
423 -
        self.assertEquals(dummy.dummyAttribute, 1234)
423 +
        self.assertEqual(dummy.dummyAttribute, 1234)
424 424
425 425
426 426
    def test_storeIDAccessor(self):
@@ -438,10 +438,10 @@
Loading
438 438
        its value when given an instance.
439 439
        """
440 440
        dummy = FullImplementationDummyClass(dummyAttribute=1234)
441 -
        self.assertEquals(
441 +
        self.assertEqual(
442 442
            Placeholder(FullImplementationDummyClass
443 443
                        ).dummyAttribute.__get__(dummy), 1234)
444 -
        self.assertEquals(dummy.dummyAttribute, 1234)
444 +
        self.assertEqual(dummy.dummyAttribute, 1234)
445 445
446 446
447 447
    def test_typeAttribute(self):

@@ -19,18 +19,18 @@
Loading
19 19
    def testTagging(self):
20 20
        s = Store()
21 21
        c = Catalog(store=s)
22 -
        g1 = Gizmo(store=s, name=u'one')
23 -
        g2 = Gizmo(store=s, name=u'two')
22 +
        g1 = Gizmo(store=s, name='one')
23 +
        g2 = Gizmo(store=s, name='two')
24 24
25 -
        c.tag(g1, u'single')
26 -
        c.tag(g1, u'multi')
27 -
        c.tag(g2, u'multi')
28 -
        c.tag(g1, u'multi')
25 +
        c.tag(g1, 'single')
26 +
        c.tag(g1, 'multi')
27 +
        c.tag(g2, 'multi')
28 +
        c.tag(g1, 'multi')
29 29
30 -
        self.assertEquals(list(c.tagsOf(g1)),
31 -
                          [u'single', u'multi'])
32 -
        self.assertEquals(list(c.tagsOf(g2)),
33 -
                          [u'multi'])
30 +
        self.assertEqual(list(c.tagsOf(g1)),
31 +
                          ['single', 'multi'])
32 +
        self.assertEqual(list(c.tagsOf(g2)),
33 +
                          ['multi'])
34 34
35 -
        self.assertEquals(list(c.objectsIn(u'single')), [g1])
36 -
        self.assertEquals(list(c.objectsIn(u'multi')), [g1, g2])
35 +
        self.assertEqual(list(c.objectsIn('single')), [g1])
36 +
        self.assertEqual(list(c.objectsIn('multi')), [g1, g2])

@@ -54,10 +54,11 @@
Loading
54 54
        """
55 55
        topdb = filepath.FilePath(self.mktemp())
56 56
        s = Store(topdb)
57 +
        inparent = SubStored(store=s, a=u'text value', b=b'bytes value')
57 58
        ss = SubStore.createNew(s, ['account', 'bob@divmod.com'])
58 59
        s2 = ss.open()
59 60
60 -
        ssd = SubStored(store=s2, a=u'hello world', b='what, its text')
61 +
        ssd = SubStored(store=s2, a=u'hello world', b=b'what, its text')
61 62
        oid = ss.storeID
62 63
        oid2 = ssd.storeID
63 64
@@ -65,12 +66,17 @@
Loading
65 66
        s.close()
66 67
67 68
        reopens = Store(topdb)
69 +
        reinparent = reopens.getItemByID(inparent.storeID)
70 +
71 +
        self.assertEqual(reinparent.a, u'text value')
72 +
        self.assertEqual(reinparent.b, b'bytes value')
73 +
68 74
        reopenss = reopens.getItemByID(oid)
69 75
        reopens2 = reopenss.open()
70 76
        reopenssd = reopens2.getItemByID(oid2)
71 77
72 -
        self.assertEquals(reopenssd.a, u'hello world')
73 -
        self.assertEquals(reopenssd.b, 'what, its text')
78 +
        self.assertEqual(reopenssd.a, u'hello world')
79 +
        self.assertEqual(reopenssd.b, b'what, its text')
74 80
75 81
76 82
    def test_oneThingMemory(self):
@@ -81,7 +87,7 @@
Loading
81 87
        ss = SubStore.createNew(s, ['account', 'bob@divmod.com'])
82 88
        s2 = ss.open()
83 89
84 -
        ssd = SubStored(store=s2, a=u'hello world', b='what, its text')
90 +
        ssd = SubStored(store=s2, a=u'hello world', b=b'what, its text')
85 91
        oid = ss.storeID
86 92
        oid2 = ssd.storeID
87 93
@@ -89,8 +95,8 @@
Loading
89 95
        self.assertIdentical(s.getItemByID(oid), ss)
90 96
        self.assertIdentical(ss.open(), s2)
91 97
        item = s2.getItemByID(oid2)
92 -
        self.assertEquals(item.a, u'hello world')
93 -
        self.assertEquals(item.b, 'what, its text')
98 +
        self.assertEqual(item.a, u'hello world')
99 +
        self.assertEqual(item.b, b'what, its text')
94 100
95 101
96 102
    def test_hereTodayGoneTomorrow(self):
@@ -101,7 +107,7 @@
Loading
101 107
        ss = SubStore.createNew(s, ['account', 'bob@divmod.com'])
102 108
        s2 = ss.open()
103 109
104 -
        ssd = SubStored(store=s2, a=u'hello world', b='what, its text')
110 +
        ssd = SubStored(store=s2, a=u'hello world', b=b'what, its text')
105 111
        oid = ss.storeID
106 112
        oid2 = ssd.storeID
107 113
        s2.close()
@@ -111,8 +117,8 @@
Loading
111 117
        ss = s.getItemByID(oid)
112 118
        s2 = ss.open()
113 119
        item = s2.getItemByID(oid2)
114 -
        self.assertEquals(item.a, u'hello world')
115 -
        self.assertEquals(item.b, 'what, its text')
120 +
        self.assertEqual(item.a, u'hello world')
121 +
        self.assertEqual(item.b, b'what, its text')
116 122
117 123
118 124
    def test_memorySubstoreFile(self):
@@ -125,7 +131,7 @@
Loading
125 131
        ss = SubStore.createNew(s, ['account', 'bob@divmod.com'])
126 132
        s2 = ss.open()
127 133
        f = s2.newFile("test.txt")
128 -
        f.write("yay")
134 +
        f.write(b"yay")
129 135
        f.close()
130 136
        self.assertEqual(open(f.finalpath.path).read(), "yay")
131 137
@@ -147,11 +153,11 @@
Loading
147 153
        Substores use the debug and journal configuration of the parent store.
148 154
        """
149 155
        filesdir = filepath.FilePath(self.mktemp())
150 -
        s = Store(filesdir=filesdir, debug=True, journalMode=u'MEMORY')
156 +
        s = Store(filesdir=filesdir, debug=True, journalMode='MEMORY')
151 157
        ss = SubStore.createNew(s, ['account', 'bob@divmod.com'])
152 158
        s2 = ss.open()
153 159
        self.assertEqual(s2.debug, True)
154 -
        self.assertEqual(s2.journalMode, u'MEMORY')
160 +
        self.assertEqual(s2.journalMode, 'MEMORY')
155 161
156 162
157 163
@@ -182,7 +188,7 @@
Loading
182 188
        ycst = YouCantStartThis(store=ss)
183 189
        ss.powerUp(ycst, IService)
184 190
        self._startService()
185 -
        self.failIf(ycst.started)
191 +
        self.assertFalse(ycst.started)
186 192
187 193
    def testStartEverythingExplicitly(self):
188 194
        """
@@ -194,7 +200,7 @@
Loading
194 200
        ss.powerUp(ysst, IService)
195 201
        self.topdb.powerUp(self.ssitem, IService)
196 202
        self._startService()
197 -
        self.failUnless(ysst.started)
203 +
        self.assertTrue(ysst.started)
198 204
199 205
    def _startService(self):
200 206
        """

@@ -116,11 +116,11 @@
Loading
116 116
        axiomConnection = self.createAxiomConnection(stubConnection)
117 117
        axiomCursor = axiomConnection.cursor()
118 118
119 -
        self.assertEquals(len(stubConnection.cursors), 1)
119 +
        self.assertEqual(len(stubConnection.cursors), 1)
120 120
        statement = "SELECT foo FROM bar"
121 121
        axiomCursor.execute(statement)
122 -
        self.assertEquals(len(stubConnection.cursors[0].statements), 1)
123 -
        self.assertEquals(stubConnection.cursors[0].statements[0], statement)
122 +
        self.assertEqual(len(stubConnection.cursors[0].statements), 1)
123 +
        self.assertEqual(stubConnection.cursors[0].statements[0], statement)
124 124
125 125
126 126
    def test_timeoutExceeded(self):
@@ -152,13 +152,13 @@
Loading
152 152
            TimeoutError,
153 153
            axiomCursor.execute, statement)
154 154
155 -
        self.failUnless(
155 +
        self.assertTrue(
156 156
            self.TIMEOUT <= time() <= self.TIMEOUT + self.ALLOWED_SLOP,
157 157
            "Wallclock duration of execute() call out of bounds.")
158 158
159 -
        self.assertEquals(timeoutException.statement, statement)
160 -
        self.assertEquals(timeoutException.timeout, self.TIMEOUT)
161 -
        self.failUnless(isinstance(
159 +
        self.assertEqual(timeoutException.statement, statement)
160 +
        self.assertEqual(timeoutException.timeout, self.TIMEOUT)
161 +
        self.assertTrue(isinstance(
162 162
                timeoutException.underlying,
163 163
                self.expectedUnderlyingExceptionClass))
164 164

@@ -3,6 +3,7 @@
Loading
3 3
__metaclass__ = type
4 4
5 5
import gc
6 +
import six
6 7
from zope.interface import implementer, Interface
7 8
8 9
from inspect import getabsfile
@@ -24,6 +25,7 @@
Loading
24 25
    reference, text, integer, AND, _cascadingDeletes, _disallows)
25 26
import six
26 27
from six.moves import zip
28 +
from functools import total_ordering
27 29
28 30
_typeNameToMostRecentClass = WeakValueDictionary()
29 31
@@ -98,11 +100,36 @@
Loading
98 100
        in SQL generation, which is beneficial for debugging and performance
99 101
        purposes.
100 102
        """
101 -
        if isinstance(other, MetaItem):
103 +
        # cmp is only available on Python 2
104 +
        if six.PY2 and isinstance(other, MetaItem):
102 105
            return cmp((self.typeName, self.schemaVersion),
103 106
                       (other.typeName, other.schemaVersion))
104 107
        return NotImplemented
105 108
109 +
    def _makeComparator(opfunc):
110 +
        """
111 +
        since @total_ordering doesn't work on metaclasses, let's do our own
112 +
        """
113 +
        def __op__(self, other):
114 +
            if not isinstance(other, MetaItem): # pragma: no cover
115 +
                return NotImplemented
116 +
            return opfunc((self.typeName, self.schemaVersion), (other.typeName, other.schemaVersion))
117 +
        return __op__
118 +
119 +
    import operator
120 +
    __lt__ = _makeComparator(operator.lt)
121 +
    __le__ = _makeComparator(operator.le)
122 +
    __gt__ = _makeComparator(operator.gt)
123 +
    __ge__ = _makeComparator(operator.ge)
124 +
    __eq__ = _makeComparator(operator.eq)
125 +
126 +
    def __hash__(self):
127 +
        """
128 +
        Since we've defined an ordering, we have to implement hashability for py3 as well.
129 +
        """
130 +
        return hash((self.typeName, self.schemaVersion)) + 7
131 +
132 +
106 133
107 134
def noop():
108 135
    pass
@@ -268,7 +295,7 @@
Loading
268 295
        else:
269 296
            forc = self.store.findOrCreate(_PowerupConnector,
270 297
                                           item=self,
271 -
                                           interface=unicode(qual(interface)),
298 +
                                           interface=str(qual(interface)),
272 299
                                           powerup=powerup)
273 300
            forc.priority = priority
274 301
@@ -298,7 +325,7 @@
Loading
298 325
        else:
299 326
            for cable in self.store.query(_PowerupConnector,
300 327
                                          AND(_PowerupConnector.item == self,
301 -
                                              _PowerupConnector.interface == unicode(qual(interface)),
328 +
                                              _PowerupConnector.interface == str(qual(interface)),
302 329
                                              _PowerupConnector.powerup == powerup)):
303 330
                cable.deleteFromStore()
304 331
                return
@@ -344,7 +371,7 @@
Loading
344 371
            yield inMemoryPowerup
345 372
        if self.store is None:
346 373
            return
347 -
        name = unicode(qual(interface), 'ascii')
374 +
        name = qual(interface)
348 375
        for cable in self.store.query(
349 376
            _PowerupConnector,
350 377
            AND(_PowerupConnector.interface == name,
@@ -570,7 +597,7 @@
Loading
570 597
        """
571 598
        attrs = ", ".join("{n}={v}".format(n=name, v=attr.reprFor(self))
572 599
                          for name, attr in sorted(self.getSchema()))
573 -
        template = b"{s.__name__}({attrs}, storeID={s.storeID})@{id:#x}"
600 +
        template = "{s.__name__}({attrs}, storeID={s.storeID})@{id:#x}"
574 601
        return template.format(s=self, attrs=attrs, id=id(self))
575 602
576 603
@@ -955,7 +982,6 @@
Loading
955 982
    getTableAlias = classmethod(getTableAlias)
956 983
957 984
958 -
959 985
@implementer(IColumn)
960 986
class _PlaceholderColumn(_ContainableMixin, _ComparisonOperatorMuxer,
961 987
                         _MatchingOperationMuxer, _OrderingMixin):
@@ -1007,6 +1033,7 @@
Loading
1007 1033
1008 1034
_placeholderCount = 0
1009 1035
1036 +
@total_ordering
1010 1037
class Placeholder(object):
1011 1038
    """
1012 1039
    Wrap an existing L{Item} type to provide a different name for it.
@@ -1046,6 +1073,24 @@
Loading
1046 1073
        self.existingInStore = self._placeholderItemClass.existingInStore
1047 1074
1048 1075
1076 +
    def __lt__(self, other):
1077 +
        """
1078 +
        Provide a deterministic sort order between Placeholder instances.
1079 +
        """
1080 +
        if isinstance(other, Placeholder):
1081 +
            return self._placeholderCount < other._placeholderCount
1082 +
        return NotImplemented
1083 +
1084 +
1085 +
    def __eq__(self, other):
1086 +
        """
1087 +
        Provide a deterministic sort order between Placeholder instances.
1088 +
        """
1089 +
        if isinstance(other, Placeholder):
1090 +
            return self._placeholderCount == other._placeholderCount
1091 +
        return NotImplemented
1092 +
1093 +
1049 1094
    def __cmp__(self, other):
1050 1095
        """
1051 1096
        Provide a deterministic sort order between Placeholder instances.

@@ -155,12 +155,12 @@
Loading
155 155
            length += 1
156 156
        self.length = length
157 157
158 -
    def sort(self, *args):
158 +
    def sort(self, *args, **kwargs):
159 159
        # We want to sort by value, not sort by _ListItem.  We could
160 160
        # accomplish this by having _ListItem.__cmp__ do something
161 161
        # with self._value, but that seemed wrong. This was easier.
162 162
        values = [li._value for li in self._queryListItems()]
163 -
        values.sort(*args)
163 +
        values.sort(*args, **kwargs)
164 164
        index = 0
165 165
        for li in self._queryListItems():
166 166
            # XXX: Well, can it?

@@ -32,6 +32,7 @@
Loading
32 32
33 33
import warnings
34 34
from threading import Thread
35 +
import six
35 36
36 37
from zope.interface import implementer, Interface
37 38
@@ -56,7 +57,7 @@
Loading
56 57
from axiom.scheduler import IScheduler
57 58
from axiom import upgrade, iaxiom
58 59
59 -
ANY_PROTOCOL = u'*'
60 +
ANY_PROTOCOL = '*'
60 61
61 62
def dflip(x):
62 63
    warnings.warn("Don't use dflip no more", stacklevel=2)
@@ -336,7 +337,9 @@
Loading
336 337
        realm = self.store.findUnique(LoginSystem)
337 338
338 339
        def _hashed(hash):
339 -
            self.passwordHash = hash.decode('ascii')
340 +
            # apparently txpasslib gives us bytes hashes on py2, text hashes on
341 +
            # py3; let's make those consistent.
342 +
            self.passwordHash = hash.decode('ascii') if isinstance(hash, bytes) else hash
340 343
341 344
        return realm._getCC().hash(newPassword).addCallback(_hashed)
342 345
@@ -464,7 +467,7 @@
Loading
464 467
    password = oldAccount.password
465 468
    if password is not None:
466 469
        try:
467 -
            password = password.decode('ascii')
470 +
            password = six.ensure_str(password)
468 471
        except UnicodeDecodeError:
469 472
            password = None
470 473
@@ -480,7 +483,7 @@
Loading
480 483
            localpart=oldAccount.username,
481 484
            domain=oldAccount.domain,
482 485
            internal=False,
483 -
            protocol=u'email',
486 +
            protocol='email',
484 487
            account=acc,
485 488
            verified=True)
486 489
@@ -510,7 +513,7 @@
Loading
510 513
    if oldAccount.password is None:
511 514
        passwordHash = None
512 515
    else:
513 -
        passwordHash = _globalCC.hash(oldAccount.password).decode('ascii')
516 +
        passwordHash = six.ensure_str(_globalCC.hash(oldAccount.password))
514 517
    return oldAccount.upgradeVersion(
515 518
        'login', 2, 3,
516 519
        passwordHash=passwordHash,
@@ -558,7 +561,7 @@
Loading
558 561
559 562
560 563
    def addAccount(self, username, domain, password, avatars=None,
561 -
                   protocol=u'email', disabled=0, internal=False,
564 +
                   protocol='email', disabled=0, internal=False,
562 565
                   verified=True):
563 566
        """
564 567
        Create a user account, add it to this LoginBase, and return it.
@@ -590,14 +593,14 @@
Loading
590 593
591 594
        # unicode(None) == u'None', kids.
592 595
        if username is not None:
593 -
            username = unicode(username)
596 +
            username = six.ensure_text(username)
594 597
        if domain is not None:
595 -
            domain = unicode(domain)
598 +
            domain = six.ensure_text(domain)
596 599
        if password is None:
597 600
            passwordHash = None
598 601
        else:
599 -
            password = unicode(password)
600 -
            passwordHash = _globalCC.hash(password).decode('ascii')
602 +
            password = six.ensure_text(password)
603 +
            passwordHash = six.ensure_str(_globalCC.hash(password))
601 604
602 605
        if self.accountByAddress(username, domain) is not None:
603 606
            raise DuplicateUser(username, domain)
@@ -663,8 +666,8 @@
Loading
663 666
            self.failedLogins += 1
664 667
            raise MissingDomainPart(credentials.username)
665 668
666 -
        username = unicode(username)
667 -
        domain = unicode(domain)
669 +
        username = six.ensure_text(username)
670 +
        domain = six.ensure_text(domain)
668 671
669 672
        acct = self.accountByAddress(username, domain)
670 673
        if acct is not None:
@@ -697,7 +700,7 @@
Loading
697 700
    them by protocol
698 701
    """
699 702
    if protocol is not None:
700 -
        comp = OR(LoginMethod.protocol == u'*',
703 +
        comp = OR(LoginMethod.protocol == '*',
701 704
                  LoginMethod.protocol == protocol)
702 705
    else:
703 706
        comp = None

@@ -16,7 +16,8 @@
Loading
16 16
        p = Portal(IRealm(self.store),
17 17
                   [ICredentialsChecker(self.store)])
18 18
19 -
        def loggedIn((ifc, av, lgo)):
19 +
        def loggedIn(args):
20 +
            (ifc, av, lgo) = args
20 21
            assert av.garbage == 7
21 22
            return av.store.whenFullyUpgraded()
22 23
        d = p.login(

@@ -6,7 +6,11 @@
Loading
6 6
from axiom.sequence import List
7 7
from axiom.store import Store
8 8
9 +
from functools import total_ordering
10 +
from operator import lt, eq
9 11
12 +
13 +
@total_ordering
10 14
class SomeItem(Item):
11 15
    schemaVersion = 1
12 16
    typeName = 'test_sequence_some_item'
@@ -20,6 +24,16 @@
Loading
20 24
            return cmp(super(SomeItem, self), other)
21 25
        return cmp(self.foo, other.foo)
22 26
27 +
    def __lt__(self, other):
28 +
        if not isinstance(other, self.__class__):
29 +
            return lt(super(SomeItem, self), other)
30 +
        return lt(self.foo, other.foo)
31 +
32 +
    def __eq__(self, other):
33 +
        if not isinstance(other, self.__class__):
34 +
            return eq(super(SomeItem, self), other)
35 +
        return eq(self.foo, other.foo)
36 +
23 37
class SequenceTestCase(unittest.TestCase):
24 38
    def setUp(self):
25 39
        self.store = Store()
@@ -29,14 +43,14 @@
Loading
29 43
            setattr(self, 'i%i'%i, item)
30 44
31 45
    def assertContents(self, seq, L):
32 -
        self.assertEquals(len(seq), len(L))
46 +
        self.assertEqual(len(seq), len(L))
33 47
        for i in range(len(L)):
34 48
            self.assertIdentical(seq[i], L[i])
35 49
36 50
class TestSequenceOfItems(SequenceTestCase):
37 51
    def test_createItem(self):
38 52
        seq = List(store=self.store)
39 -
        self.assertEquals(len(seq), 0)
53 +
        self.assertEqual(len(seq), 0)
40 54
41 55
    def test_createItemWithDefaults(self):
42 56
        seq = List([self.i0, self.i1], store=self.store)
@@ -55,12 +69,12 @@
Loading
55 69
    def test_appendAndGetItem(self):
56 70
        seq = List(store=self.store)
57 71
        seq.append(self.i0)
58 -
        self.assertEquals(len(seq), 1)
59 -
        self.assertEquals(seq[0], self.i0)
72 +
        self.assertEqual(len(seq), 1)
73 +
        self.assertEqual(seq[0], self.i0)
60 74
        seq.append(self.i1)
61 75
        seq.append(self.i2)
62 -
        self.assertEquals(seq[1], self.i1)
63 -
        self.assertEquals(seq[2], self.i2)
76 +
        self.assertEqual(seq[1], self.i1)
77 +
        self.assertEqual(seq[2], self.i2)
64 78
65 79
    def test_appendSliceSyntax(self):
66 80
        seq = List(store=self.store)
@@ -77,7 +91,7 @@
Loading
77 91
        seq = List(store=self.store)
78 92
        self.assertRaises(IndexError, seq.__getitem__, 0)
79 93
        seq.append(self.i0)
80 -
        self.assertEquals(seq[0], self.i0)
94 +
        self.assertEqual(seq[0], self.i0)
81 95
        self.assertRaises(IndexError, seq.__getitem__, 1)
82 96
83 97
    def test_negativeIndices(self):
@@ -85,34 +99,34 @@
Loading
85 99
        seq.append(self.i0)
86 100
        seq.append(self.i1)
87 101
        seq.append(self.i2)
88 -
        self.assertEquals(seq[-1], self.i2)
89 -
        self.assertEquals(seq[-2], self.i1)
90 -
        self.assertEquals(seq[-3], self.i0)
102 +
        self.assertEqual(seq[-1], self.i2)
103 +
        self.assertEqual(seq[-2], self.i1)
104 +
        self.assertEqual(seq[-3], self.i0)
91 105
        self.assertRaises(IndexError, seq.__getitem__, -4)
92 106
93 107
    def test_setItem(self):
94 108
        seq = List(store=self.store)
95 109
        seq.append(self.i0)
96 110
        seq.append(self.i1)
97 -
        self.assertEquals(len(seq), 2)
98 -
        self.assertEquals(seq[0], self.i0)
99 -
        self.assertEquals(seq[1], self.i1)
111 +
        self.assertEqual(len(seq), 2)
112 +
        self.assertEqual(seq[0], self.i0)
113 +
        self.assertEqual(seq[1], self.i1)
100 114
        seq[1] = self.i2
101 -
        self.assertEquals(seq[1], self.i2)
115 +
        self.assertEqual(seq[1], self.i2)
102 116
103 117
    def test_delItem(self):
104 118
        seq = List(store=self.store)
105 119
        seq.append(self.i1)
106 120
        seq.append(self.i2)
107 121
        seq.append(self.i3)
108 -
        self.assertEquals(seq.length, 3)
109 -
        self.assertEquals(seq[0], self.i1)
110 -
        self.assertEquals(seq[1], self.i2)
111 -
        self.assertEquals(seq[2], self.i3)
122 +
        self.assertEqual(seq.length, 3)
123 +
        self.assertEqual(seq[0], self.i1)
124 +
        self.assertEqual(seq[1], self.i2)
125 +
        self.assertEqual(seq[2], self.i3)
112 126
        del seq[1]
113 -
        self.assertEquals(seq.length, 2)
114 -
        self.assertEquals(seq[0], self.i1)
115 -
        self.assertEquals(seq[1], self.i3)
127 +
        self.assertEqual(seq.length, 2)
128 +
        self.assertEqual(seq[0], self.i1)
129 +
        self.assertEqual(seq[1], self.i3)
116 130
        self.assertRaises(IndexError, seq.__getitem__, 2)
117 131
118 132
@@ -125,14 +139,14 @@
Loading
125 139
    def test_x_in_s(self):
126 140
        seq = List(store=self.store)
127 141
        seq.append(self.i0)
128 -
        self.failUnless(self.i0 in seq)
129 -
        self.failIf(self.xy in seq)
142 +
        self.assertTrue(self.i0 in seq)
143 +
        self.assertFalse(self.xy in seq)
130 144
131 145
    def test_x_not_in_s(self):
132 146
        seq = List(store=self.store)
133 147
        seq.append(self.i0)
134 -
        self.failUnless(self.xy not in seq)
135 -
        self.failIf(self.i0 not in seq)
148 +
        self.assertTrue(self.xy not in seq)
149 +
        self.assertFalse(self.i0 not in seq)
136 150
137 151
    def test_s_plus_t(self):
138 152
        L1 = List(store=self.store)
@@ -142,13 +156,13 @@
Loading
142 156
        # XXX ASSUMPTION: all operations which return another
143 157
        # instance will return regular lists, *not* Lists.
144 158
        L = L1 + L2
145 -
        self.assertEquals(L, [self.i0, self.i1])
159 +
        self.assertEqual(L, [self.i0, self.i1])
146 160
147 161
    def test_shallow_copies(self, n=3):
148 162
        seq = List(store=self.store)
149 163
        seq.append(self.i0)
150 164
        for L in (seq * n, n * seq):
151 -
            self.assertEquals(L, [self.i0]*n)
165 +
            self.assertEqual(L, [self.i0]*n)
152 166
153 167
    def test_index(self):
154 168
        seq = List(store=self.store)
@@ -165,10 +179,10 @@
Loading
165 179
        seq.append(self.i1)
166 180
        seq.append(self.i2)
167 181
        seq.append(self.i3)
168 -
        self.assertEquals(seq[0:2], [self.i0, self.i1])
169 -
        self.assertEquals(seq[0:3], [self.i0, self.i1, self.i2])
170 -
        self.assertEquals(seq[1:0], [])
171 -
        self.assertEquals(seq[-1:], [self.i3])
182 +
        self.assertEqual(seq[0:2], [self.i0, self.i1])
183 +
        self.assertEqual(seq[0:3], [self.i0, self.i1, self.i2])
184 +
        self.assertEqual(seq[1:0], [])
185 +
        self.assertEqual(seq[-1:], [self.i3])
172 186
    test_slices.todo = "Slices are not supported yet"
173 187
174 188
    def test_slice_with_step(self):
@@ -177,19 +191,19 @@
Loading
177 191
        seq.append(self.i1)
178 192
        seq.append(self.i2)
179 193
        seq.append(self.i3)
180 -
        self.assertEquals(seq[0:4:2], [self.i0, self.i2])
181 -
        self.assertEquals(seq[1:5:2], [self.i1, self.i3])
194 +
        self.assertEqual(seq[0:4:2], [self.i0, self.i2])
195 +
        self.assertEqual(seq[1:5:2], [self.i1, self.i3])
182 196
    test_slice_with_step.todo = "Slices are not supported yet"
183 197
184 198
    def test_len(self):
185 199
        seq = List(store=self.store)
186 -
        self.assertEquals(len(seq), 0)
200 +
        self.assertEqual(len(seq), 0)
187 201
        seq.append(self.i0)
188 -
        self.assertEquals(len(seq), 1)
202 +
        self.assertEqual(len(seq), 1)
189 203
        seq.append(self.i0)
190 -
        self.assertEquals(len(seq), 2)
204 +
        self.assertEqual(len(seq), 2)
191 205
        seq.append(self.i0)
192 -
        self.assertEquals(len(seq), 3)
206 +
        self.assertEqual(len(seq), 3)
193 207
194 208
    def test_min_max(self):
195 209
        seq = List(store=self.store)
@@ -245,7 +259,7 @@
Loading
245 259
        seq.append(self.i2)
246 260
        seq.append(self.i3)
247 261
        del seq[1:3]
248 -
        self.assertEquals(len(seq), 2)
262 +
        self.assertEqual(len(seq), 2)
249 263
        self.assertIdentical(seq[0], self.i0)
250 264
        self.assertIdentical(seq[1], self.i3)
251 265
    test_deleteSlice.todo = "Slices are not supported yet"
@@ -329,10 +343,10 @@
Loading
329 343
        seq.append(self.i2)
330 344
        seq.append(self.i0)
331 345
        seq.append(self.i2)
332 -
        self.assertEquals(seq.count(self.i0), 3)
333 -
        self.assertEquals(seq.count(self.i1), 1)
334 -
        self.assertEquals(seq.count(self.i2), 2)
335 -
        self.assertEquals(seq.count(self.i3), 0)
346 +
        self.assertEqual(seq.count(self.i0), 3)
347 +
        self.assertEqual(seq.count(self.i1), 1)
348 +
        self.assertEqual(seq.count(self.i2), 2)
349 +
        self.assertEqual(seq.count(self.i3), 0)
336 350
337 351
    def test_index(self):
338 352
        seq = List(store=self.store)
@@ -342,13 +356,13 @@
Loading
342 356
        seq.append(self.i2)
343 357
        seq.append(self.i0)
344 358
        seq.append(self.i2)
345 -
        self.assertEquals(seq.index(self.i0),    0)
346 -
        self.assertEquals(seq.index(self.i0, 0), 0)
347 -
        self.assertEquals(seq.index(self.i0, 1), 2)
348 -
        self.assertEquals(seq.index(self.i1),    1)
349 -
        self.assertEquals(seq.index(self.i1, 1), 1)
350 -
        self.assertEquals(seq.index(self.i2),    3)
351 -
        self.assertEquals(seq.index(self.i2, 4), 5)
359 +
        self.assertEqual(seq.index(self.i0),    0)
360 +
        self.assertEqual(seq.index(self.i0, 0), 0)
361 +
        self.assertEqual(seq.index(self.i0, 1), 2)
362 +
        self.assertEqual(seq.index(self.i1),    1)
363 +
        self.assertEqual(seq.index(self.i1, 1), 1)
364 +
        self.assertEqual(seq.index(self.i2),    3)
365 +
        self.assertEqual(seq.index(self.i2, 4), 5)
352 366
        self.assertRaises(ValueError, seq.index, self.i3)
353 367
        self.assertRaises(ValueError, seq.index, self.i1, 3)
354 368
        self.assertRaises(ValueError, seq.index, self.i0, 1, 1)
@@ -501,42 +515,21 @@
Loading
501 515
                                  self.i4])
502 516
503 517
        seq_randomize()
504 -
        seq.sort(lambda x,y: cmp(y,x))
518 +
        seq.sort(key=lambda each: -each.foo)
505 519
        self.assertContents(seq, [self.i4,
506 520
                                  self.i3,
507 521
                                  self.i2,
508 522
                                  self.i1,
509 523
                                  self.i0])
510 524
511 -
        def strangecmp(x, y):
512 -
            xfoo, yfoo = x.foo, y.foo
513 -
            if xfoo < 3:
514 -
                xfoo += 100
515 -
            if yfoo < 3:
516 -
                yfoo += 100
517 -
            return cmp(xfoo, yfoo)
518 -
        seq_randomize()
519 -
        seq.sort(strangecmp)
520 -
        self.assertContents(seq, [self.i3,
521 -
                                  self.i4,
522 -
                                  self.i0,
523 -
                                  self.i1,
524 -
                                  self.i2])
525 -
526 525
        seq_randomize()
527 -
        seq.sort(None, lambda x:x, True)
526 +
        seq.sort(reverse=True)
528 527
        self.assertContents(seq, [self.i4,
529 528
                                  self.i3,
530 529
                                  self.i2,
531 530
                                  self.i1,
532 531
                                  self.i0])
533 532
        seq_randomize()
534 -
        seq.sort(strangecmp, lambda x:x, True)
535 -
        self.assertContents(seq, [self.i2,
536 -
                                  self.i1,
537 -
                                  self.i0,
538 -
                                  self.i4,
539 -
                                  self.i3])
540 533
541 534
    def test_count(self):
542 535
        seq = List(store=self.store)
@@ -546,27 +539,27 @@
Loading
546 539
        seq.append(self.i3)
547 540
        seq.append(self.i3)
548 541
        seq.append(self.i3)
549 -
        self.assertEquals(seq.count(self.i1), 1)
550 -
        self.assertEquals(seq.count(self.i2), 2)
551 -
        self.assertEquals(seq.count(self.i3), 3)
542 +
        self.assertEqual(seq.count(self.i1), 1)
543 +
        self.assertEqual(seq.count(self.i2), 2)
544 +
        self.assertEqual(seq.count(self.i3), 3)
552 545
553 546
    def test_contains(self):
554 547
        seq = List(store=self.store)
555 548
        seq.append(self.i1)
556 549
        seq.append(self.i2)
557 -
        self.failUnless(self.i1 in seq)
558 -
        self.failUnless(self.i2 in seq)
559 -
        self.failIf(self.i3 in seq)
550 +
        self.assertTrue(self.i1 in seq)
551 +
        self.assertTrue(self.i2 in seq)
552 +
        self.assertFalse(self.i3 in seq)
560 553
561 554
    def test_multicontains(self):
562 555
        seq1 = List(store=self.store)
563 556
        seq2 = List(store=self.store)
564 557
        seq1.append(self.i1)
565 558
        seq2.append(self.i2)
566 -
        self.failUnless(self.i1 in seq1)
567 -
        self.failUnless(self.i2 in seq2)
568 -
        self.failIf(self.i1 in seq2)
569 -
        self.failIf(self.i2 in seq1)
559 +
        self.assertTrue(self.i1 in seq1)
560 +
        self.assertTrue(self.i2 in seq2)
561 +
        self.assertFalse(self.i1 in seq2)
562 +
        self.assertFalse(self.i2 in seq1)
570 563
571 564
    def test_multidelitem(self):
572 565
        seq1 = List(store=self.store)

@@ -7,9 +7,8 @@
Loading
7 7
from __future__ import print_function
8 8
9 9
import six
10 -
from six.moves import map
11 10
12 -
import time, os, itertools, warnings, sys, operator, weakref
11 +
import time, os, itertools, warnings, sys, operator, weakref, six, io
13 12
14 13
from zope.interface import implementer
15 14
@@ -62,7 +61,7 @@
Loading
62 61
63 62
64 63
@implementer(iaxiom.IAtomicFile)
65 -
class AtomicFile(file):
64 +
class AtomicFile(io.FileIO, object):
66 65
    """I am a file which is moved from temporary to permanent storage when it
67 66
    is closed.
68 67
@@ -79,7 +78,7 @@
Loading
79 78
        called.
80 79
        """
81 80
        self._destpath = destpath
82 -
        file.__init__(self, tempname, 'w+b')
81 +
        super(AtomicFile, self).__init__(tempname, 'w+')
83 82
84 83
    def close(self):
85 84
        """
@@ -90,12 +89,12 @@
Loading
90 89
        """
91 90
        now = time.time()
92 91
        try:
93 -
            file.close(self)
92 +
            super(AtomicFile, self).close()
94 93
            _mkdirIfNotExists(self._destpath.dirname())
95 94
            self.finalpath = self._destpath
96 95
            os.rename(self.name, self.finalpath.path)
97 96
            os.utime(self.finalpath.path, (now, now))
98 -
        except:
97 +
        except Exception:
99 98
            return defer.fail()
100 99
        return defer.succeed(self.finalpath)
101 100
@@ -167,7 +166,6 @@
Loading
167 166
            and ((typename, version) not in _legacyTypes))
168 167
169 168
170 -
171 169
@implementer(iaxiom.IQuery)
172 170
class BaseQuery:
173 171
    """
@@ -181,7 +179,7 @@
Loading
181 179
    # XXX: need a better convention for this sort of
182 180
    # abstract-but-provide-most-of-a-base-implementation thing. -glyph
183 181
184 -
    # How about not putting the implements(iaxiom.IQuery) here, but on
182 +
    # How about not putting the @implementer(iaxiom.IQuery) here, but on
185 183
    # subclasses instead? -exarkun
186 184
187 185
    def __init__(self, store, tableClass,
@@ -634,10 +632,13 @@
Loading
634 632
        # If there's a 'deleted' callback on the Item type or 'deleteFromStore'
635 633
        # is overridden, we have to do it the slow way.
636 634
        deletedOverridden = (
637 -
            self.tableClass.deleted.im_func is not item.Item.deleted.im_func)
635 +
            six.get_unbound_function(self.tableClass.deleted) is not
636 +
            six.get_unbound_function(item.Item.deleted)
637 +
        )
638 638
        deleteFromStoreOverridden = (
639 -
            self.tableClass.deleteFromStore.im_func is not
640 -
            item.Item.deleteFromStore.im_func)
639 +
            six.get_unbound_function(self.tableClass.deleteFromStore) is not
640 +
            six.get_unbound_function(item.Item.deleteFromStore)
641 +
        )
641 642
642 643
        if deletedOverridden or deleteFromStoreOverridden:
643 644
            for it in self:
@@ -1021,14 +1022,13 @@
Loading
1021 1022
    diff = []
1022 1023
    if diskOnly:
1023 1024
        diff.append('Only on disk:')
1024 -
        diff.extend(map(repr, diskOnly))
1025 +
        diff.extend(list(map(repr, diskOnly)))
1025 1026
    if memoryOnly:
1026 1027
        diff.append('Only in memory:')
1027 -
        diff.extend(map(repr, memoryOnly))
1028 +
        diff.extend(list(map(repr, memoryOnly)))
1028 1029
    return '\n'.join(diff)
1029 1030
1030 1031
1031 -
1032 1032
@implementer(iaxiom.IBeneficiary)
1033 1033
class Store(Empowered):
1034 1034
    """
@@ -1167,7 +1167,9 @@
Loading
1167 1167
        self.typeToDeleteSQLCache = {}
1168 1168
1169 1169
        self.typeToTableNameCache = {}
1170 -
        self.attrToColumnNameCache = {}
1170 +
        self.attrNameToColumnNameCache = {}  # map fully-qualified attribute
1171 +
                                             # names (native str?) to database
1172 +
                                             # column names
1171 1173
1172 1174
        self._upgradeManager = upgrade._StoreUpgrade(self)
1173 1175
@@ -1752,13 +1754,13 @@
Loading
1752 1754
        indices = {}
1753 1755
        schema = [attr for (name, attr) in itemType.getSchema()]
1754 1756
        for i, attr in enumerate(itemAttributes):
1755 -
            indices[attr] = i
1757 +
            indices[attr.attrname] = i
1756 1758
        for row in dataRows:
1757 1759
            oid = self.store.executeSchemaSQL(
1758 1760
                _schema.CREATE_OBJECT, [self.store.getTypeID(itemType)])
1759 1761
            insertArgs = [oid]
1760 1762
            for attr in schema:
1761 -
                i = indices.get(attr, _NEEDS_DEFAULT)
1763 +
                i = indices.get(attr.attrname, _NEEDS_DEFAULT)
1762 1764
                if i is _NEEDS_DEFAULT:
1763 1765
                    pyval = attr.default
1764 1766
                else:
@@ -1921,11 +1923,13 @@
Loading
1921 1923
                          self.typeToTableNameCache) :
1922 1924
                if tableClass in cache:
1923 1925
                    del cache[tableClass]
1924 -
            if tableClass.storeID in self.attrToColumnNameCache:
1925 -
                del self.attrToColumnNameCache[tableClass.storeID]
1926 +
            qualifiedStoreIDName = tableClass.storeID.fullyQualifiedName()
1927 +
            if qualifiedStoreIDName in self.attrNameToColumnNameCache:
1928 +
                del self.attrNameToColumnNameCache[qualifiedStoreIDName]
1926 1929
            for name, attr in tableClass.getSchema():
1927 -
                if attr in self.attrToColumnNameCache:
1928 -
                    del self.attrToColumnNameCache[attr]
1930 +
                attrFQN = attr.fullyQualifiedName()
1931 +
                if attrFQN in self.attrNameToColumnNameCache:
1932 +
                    del self.attrNameToColumnNameCache[attrFQN]
1929 1933
1930 1934
        for sub in self._attachedChildren.values():
1931 1935
            sub._inMemoryRollback()
@@ -1937,7 +1941,7 @@
Loading
1937 1941
        self.touched = None
1938 1942
        self.executedThisTransaction = None
1939 1943
        self.tablesCreatedThisTransaction = []
1940 -
        for sub in self._attachedChildren.values():
1944 +
        for sub in list(self._attachedChildren.values()):
1941 1945
            sub._cleanupTxnState()
1942 1946
1943 1947
    def close(self, _report=True):
@@ -2045,11 +2049,12 @@
Loading
2045 2049
2046 2050
        @return: a string
2047 2051
        """
2048 -
        if attribute not in self.attrToColumnNameCache:
2049 -
            self.attrToColumnNameCache[attribute] = '.'.join(
2052 +
        name = attribute.fullyQualifiedName()
2053 +
        if name not in self.attrNameToColumnNameCache:
2054 +
            self.attrNameToColumnNameCache[name] = '.'.join(
2050 2055
                (self.getTableName(attribute.type),
2051 2056
                 self.getShortColumnName(attribute)))
2052 -
        return self.attrToColumnNameCache[attribute]
2057 +
        return self.attrNameToColumnNameCache[name]
2053 2058
2054 2059
2055 2060
    def getTypeID(self, tableClass):

@@ -3,6 +3,7 @@
Loading
3 3
from __future__ import print_function
4 4
import sys
5 5
import os
6 +
import six
6 7
7 8
from twisted.trial import unittest
8 9
from twisted.internet import protocol, defer
@@ -119,7 +120,7 @@
Loading
119 120
        x = len(s.typeToTableNameCache)
120 121
        for i in range(10):
121 122
            s.getTableName(TestItem)
122 -
        self.assertEquals(x, len(s.typeToTableNameCache))
123 +
        self.assertEqual(x, len(s.typeToTableNameCache))
123 124
124 125
125 126
    def testStoreIDComparerIdentity(self):
@@ -174,7 +175,7 @@
Loading
174 175
            TestItem,
175 176
            {(TestItem.typeName, TestItem.schemaVersion): schema[:-1]})
176 177
        self.assertEqual(
177 -
            e1[0],
178 +
            e1.args[0],
178 179
            "Schema mismatch on already-loaded "
179 180
            "<class 'axiom.test.test_xatop.TestItem'> <'TestItem'> object "
180 181
            "version 1:\n"
@@ -189,7 +190,7 @@
Loading
189 190
            {(TestItem.typeName, TestItem.schemaVersion):
190 191
             schema + [('extra', 'INTEGER')]})
191 192
        self.assertEqual(
192 -
            e2[0],
193 +
            e2.args[0],
193 194
            "Schema mismatch on already-loaded "
194 195
            "<class 'axiom.test.test_xatop.TestItem'> <'TestItem'> object "
195 196
            "version 1:\n"
@@ -204,7 +205,7 @@
Loading
204 205
            {(TestItem.typeName, TestItem.schemaVersion):
205 206
             [(schema[0][0], 'VARCHAR(64) (this is made up)')] + schema[1:]})
206 207
        self.assertEqual(
207 -
            e3[0],
208 +
            e3.args[0],
208 209
            "Schema mismatch on already-loaded "
209 210
            "<class 'axiom.test.test_xatop.TestItem'> <'TestItem'> object "
210 211
            "version 1:\n"
@@ -358,7 +359,7 @@
Loading
358 359
359 360
            # Write out the source.
360 361
            modulePath = importPath.child(moduleName + ".py")
361 -
            modulePath.setContent("""\
362 +
            modulePath.setContent(b"""\
362 363
from axiom.item import Item
363 364
from axiom.attributes import integer
364 365
@@ -370,7 +371,7 @@
Loading
370 371
        # loaded in this process, create a store containing instances of the
371 372
        # Unloaded types.
372 373
        script = filepath.FilePath(self.mktemp())
373 -
        script.setContent("""\
374 +
        script.setContent(b"""\
374 375
from sys import argv
375 376
from twisted.python.reflect import namedAny
376 377
from axiom.store import Store
@@ -427,10 +428,10 @@
Loading
427 428
        Passing a journalling mode sets that mode on open.
428 429
        """
429 430
        dbdir = filepath.FilePath(self.mktemp())
430 -
        s = store.Store(dbdir, journalMode=u'MEMORY')
431 -
        self.assertEquals(
431 +
        s = store.Store(dbdir, journalMode='MEMORY')
432 +
        self.assertEqual(
432 433
            s.querySchemaSQL('PRAGMA *DATABASE*.journal_mode'),
433 -
            [(u'memory',)])
434 +
            [('memory',)])
434 435
435 436
436 437
    def test_journalModeNone(self):
@@ -438,12 +439,12 @@
Loading
438 439
        Passing a journalling mode of C{None} sets no mode.
439 440
        """
440 441
        dbdir = filepath.FilePath(self.mktemp())
441 -
        s = store.Store(dbdir, journalMode=u'WAL')
442 +
        s = store.Store(dbdir, journalMode='WAL')
442 443
        s.close()
443 444
        s = store.Store(dbdir, journalMode=None)
444 -
        self.assertEquals(
445 +
        self.assertEqual(
445 446
            s.querySchemaSQL('PRAGMA *DATABASE*.journal_mode'),
446 -
            [(u'wal',)])
447 +
            [('wal',)])
447 448
448 449
449 450
@@ -472,7 +473,7 @@
Loading
472 473
473 474
        t3.store = s1
474 475
475 -
        self.assertEquals(list(s1.query(TestItem)),
476 +
        self.assertEqual(list(s1.query(TestItem)),
476 477
                          [t1, t3])
477 478
478 479
@@ -490,14 +491,14 @@
Loading
490 491
                      checkactive=True,
491 492
                      other=tio)
492 493
493 -
        self.assertEquals(ti.checked, True)
494 +
        self.assertEqual(ti.checked, True)
494 495
495 496
    def testItemCreation(self):
496 497
        timeval = extime.Time.fromISO8601TimeAndDate('2004-10-05T10:12:14.1234')
497 498
498 499
        s = TestItem(
499 500
            foo = 42,
500 -
            bar = u'hello world',
501 +
            bar = 'hello world',
501 502
            baz = timeval,
502 503
            booleanT = True,
503 504
            booleanF = False
@@ -509,16 +510,16 @@
Loading
509 510
        self.store.close()
510 511
        self.store = store.Store(self.dbdir)
511 512
        s2 = self.store.getItemByID(sid)
512 -
        self.assertEquals(s2.foo, s.foo)
513 -
        self.assertEquals(s2.booleanT, s.booleanT)
514 -
        self.assertEquals(s2.booleanF, s.booleanF)
513 +
        self.assertEqual(s2.foo, s.foo)
514 +
        self.assertEqual(s2.booleanT, s.booleanT)