MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / test_funky_ordering

Method test_funky_ordering

test/ext/test_orderinglist.py:410–467  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

408 eq_([b.position for b in s1.bullets], [0, 1, 2])
409
410 def test_funky_ordering(self):
411 class Pos:
412 def __init__(self):
413 self.position = None
414
415 step_factory = ordering_list(
416 "position", ordering_func=step_numbering(2)
417 )
418
419 stepped = step_factory()
420 stepped.append(Pos())
421 stepped.append(Pos())
422 stepped.append(Pos())
423 stepped.append(Pos())
424
425 for li, pos in (0, 0), (1, 2), (2, 4), (3, 6):
426 self.assert_(stepped[li].position == pos)
427
428 fib_factory = ordering_list(
429 "position", ordering_func=fibonacci_numbering("position")
430 )
431
432 fibbed = fib_factory()
433 fibbed.append(Pos())
434 fibbed.append(Pos())
435 fibbed.append(Pos())
436 fibbed.append(Pos())
437 fibbed.append(Pos())
438
439 for li, pos in (0, 1), (1, 2), (2, 3), (3, 5), (4, 8):
440 self.assert_(fibbed[li].position == pos)
441
442 fibbed.insert(2, Pos())
443 fibbed.insert(4, Pos())
444 fibbed.insert(6, Pos())
445
446 for li, pos in (
447 (0, 1),
448 (1, 2),
449 (2, 3),
450 (3, 5),
451 (4, 8),
452 (5, 13),
453 (6, 21),
454 (7, 34),
455 ):
456 self.assert_(fibbed[li].position == pos)
457
458 alpha_factory = ordering_list("position", ordering_func=alpha_ordering)
459 alpha = alpha_factory()
460 alpha.append(Pos())
461 alpha.append(Pos())
462 alpha.append(Pos())
463
464 alpha.insert(1, Pos())
465
466 for li, pos in (0, "A"), (1, "B"), (2, "C"), (3, "D"):
467 self.assert_(alpha[li].position == pos)

Callers

nothing calls this directly

Calls 7

ordering_listFunction · 0.90
step_numberingFunction · 0.85
PosClass · 0.85
fibonacci_numberingFunction · 0.85
appendMethod · 0.45
assert_Method · 0.45
insertMethod · 0.45

Tested by

no test coverage detected