-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathdbf_test.py
More file actions
4882 lines (4727 loc) · 206 KB
/
dbf_test.py
File metadata and controls
4882 lines (4727 loc) · 206 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import codecs
import os
import sys
import unittest
import tempfile
import shutil
import dbf
import datetime
from dbf.api import *
import traceback
py_ver = sys.version_info[:2]
if dbf.version != (0, 95, 1):
raise ValueError("Wrong version of dbf -- should be %d.%02d.%03d" % dbf.version)
else:
print "\nTesting dbf version %d.%02d.%03d on %s with Python %s\n" % (
dbf.version + (sys.platform, sys.version) )
# 2.5 constructs
try:
all
except NameError:
def all(iterable):
for element in iterable:
if not element:
return False
return True
# Walker in Leaves -- by Scot Noel -- http://www.scienceandfantasyfiction.com/sciencefiction/Walker-in-Leaves/walker-in-leaves.htm
words = """
Soft rains, given time, have rounded the angles of great towers. Generation after generation, wind borne seeds have brought down cities amid the gentle tangle of their roots. All statues of stone have been worn away.
Still one statue, not of stone, holds its lines against the passing years.
Sunlight, fading autumn light, warms the sculpture as best it can, almost penetrating to its dreaming core. The figure is that of a woman, once the fair sex of a species now untroubled and long unseen. Man sleeps the sleep of extinction. This one statue remains. Behind the grace of its ivory brow and gentle, unseeing eyes, the statue dreams.
A susurrus of voices, a flutter of images, and the dream tumbles down through the long morning. Suspended. Floating on the stream that brings from the heart of time the wandering self. Maya for that is the statue s name-- is buoyed by the sensation, rising within the cage of consciousness, but asleep. She has been this way for months: the unmoving figure of a woman caught in mid stride across the glade. The warmth of sunlight on her face makes her wonder if she will ever wake again.
Even at the end, there was no proper word for what Maya has become. Robot. Cybernetic Organism. Android. These are as appropriate to her condition as calling the stars campfires of the night sky and equally precise. It is enough to know that her motive energies are no longer sun and sustenance, and though Maya was once a living woman, a scientist, now she inhabits a form of ageless attraction. It is a form whose energies are flagging.
With great determination, Maya moves toward wakefulness. Flex a finger. Move a hand. Think of the lemurs, their tongues reaching out in stroke after stroke for the drip of the honeyed thorns. Though there is little time left to save her charges, Maya s only choice is the patience of the trees. On the day her energies return, it is autumn of the year following the morning her sleep began. Maya opens her eyes. The woman, the frozen machine --that which is both-- moves once more.
Two lemur cubs tumbling near the edge of the glade take notice. One rushes forward to touch Maya s knee and laugh. Maya reaches out with an arthritic hand, cold in its sculpted smoothness, but the lemur darts away. Leaves swirl about its retreat, making a crisp sound. The cub displays a playfulness Maya s fevered mind cannot match. The second cub rolls between her moss covered feet, laughing. The lemurs are her charges, and she is failing them. Still, it is good to be awake.
Sugar maples and sumacs shoulder brilliant robes. In the low sun, their orange and purple hues startle the heart. Of course, Maya has no beating organ, no heart. Her life energies are transmitted from deep underground. Nor are the cubs truly lemurs, nor the sugar maples the trees of old. The names have carried for ten million seasons, but the species have changed. Once the lemurs inhabited an island off the southeast coast of a place called Africa. Now they are here, much changed, in the great forests of the northern climes.
The young lemurs seem hale, and it speaks well for their consanguine fellows. But their true fate lies in the story of DNA, of a few strands in the matriarchal line, of a sequence code-named "hope." No doubt a once clever acronym, today Maya s clouded mind holds nothing of the ancient codes. She knows only that a poet once spoke of hope as "the thing with feathers that perches in the soul." Emily Dickinson. A strange name, and so unlike the agnomen of the lemurs. What has become of Giver-of-Corn?
Having no reason to alarm the cubs, Maya moves with her hands high, so that any movement will be down as leaves fall. Though anxious about Giver-of-Corn, she ambles on to finish the mission begun six months earlier. Ahead, the shadow of a mound rises up beneath a great oak. A door awaits. Somewhere below the forest, the engine that gives her life weakens. Held in sway to its faltering beat her mind and body froze, sending her into an abyss of dreams. She has been striding toward that door for half a year, unknowing if she would ever wake again.
Vines lose their toughened grip as the door responds to Maya s approach. Regretfully, a tree root snaps, but the door shudders to a halt before its whine of power can cross the glade. Suddenly, an opening has been made into the earth, and Maya steps lightly on its downward slope. Without breathing, she catches a scent of mold and of deep, uncirculated water. A flutter like the sound of wings echoes from the hollow. Her vision adjusts as she descends. In spots, lights attempt to greet her, but it is a basement she enters, flickering and ancient, where the footfalls of millipedes wear tracks in grime older than the forest above. After a long descent, she steps into water.
How long ago was it that the floor was dry? The exactitude of such time, vast time, escapes her.
Once this place sustained great scholars, scientists. Now sightless fish skip through broken walls, retreating as Maya wades their private corridors, finding with each step that she remembers the labyrinthine path to the heart of power. A heart that flutters like dark wings. And with it, she flutters too. The closer she comes to the vault in which the great engine is housed, the less hopeful she becomes.
The vault housing the engine rests beneath a silvered arch. Its mirrored surface denies age, even as a new generation of snails rise up out of the dark pool, mounting first the dais of pearled stone left by their ancestors, the discarded shells of millions, then higher to where the overhang drips, layered in egg sacs bright as coral.
Maya has no need to set the vault door in motion, to break the dance of the snails. The state of things tells her all she needs to know. There shall be no repairs, no rescue; the engine will die, and she with it. Still, it is impossible not to check. At her touch, a breath of firefly lights coalesces within the patient dampness of the room. They confirm. The heart is simply too tired to go on. Its last reserves wield processes of great weight and care, banking the fires of its blood, dimming the furnace into safe resolve. Perhaps a month or two in cooling, then the last fire kindled by man shall die.
For the figure standing knee deep in water the issues are more immediate. The powers that allow her to live will be the first to fade. It is amazing, even now, that she remains cognizant.
For a moment, Maya stands transfixed by her own reflection. The silvered arch holds it as moonlight does a ghost. She is a sculpted thing with shoulders of white marble. Lips of stone. A child s face. No, the grace of a woman resides in the features, as though eternity can neither deny the sage nor touch the youth. Demeter. The Earth Mother.
Maya smiles at the Greek metaphor. She has never before thought of herself as divine, nor monumental. When the energies of the base are withdrawn entirely, she will become immobile. Once a goddess, then a statue to be worn away by endless time, the crumbling remnant of something the self has ceased to be. Maya trembles at the thought. The last conscious reserve of man will soon fade forever from the halls of time.
As if hewn of irresolute marble, Maya begins to shake; were she still human there would be sobs; there would be tears to moisten her grief and add to the dark waters at her feet.
In time, Maya breaks the spell. She sets aside her grief to work cold fingers over the dim firefly controls, giving what priorities remain to her survival. In response, the great engine promises little, but does what it can.
While life remains, Maya determines to learn what she can of the lemurs, of their progress, and the fate of the matriarchal line. There will be time enough for dreams. Dreams. The one that tumbled down through the long morning comes to her and she pauses to consider it. There was a big table. Indistinct voices gathered around it, but the energy of a family gathering filled the space. The warmth of the room curled about her, perfumed by the smell of cooking. An ancient memory, from a time before the shedding of the flesh. Outside, children laughed. A hand took hers in its own, bringing her to a table filled with colorful dishes and surrounded by relatives and friends. Thanksgiving?
They re calling me home, Maya thinks. If indeed her ancestors could reach across time and into a form not of the flesh, perhaps that was the meaning of the dream. I am the last human consciousness, and I am being called home.
With a flutter, Maya is outside, and the trees all but bare of leaves. Something has happened. Weeks have passed and she struggles to take in her situation. This time she has neither dreamed nor stood immobile, but she has been active without memory.
Her arms cradle a lemur, sheltering the pubescent female against the wind. They sit atop a ridge that separates the valley from the forest to the west, and Walker-in-Leaves has been gone too long. That much Maya remembers. The female lemur sighs. It is a rumbling, mournful noise, and she buries her head tighter against Maya. This is Giver-of-Corn, and Walker is her love.
With her free hand, Maya works at a stiff knitting of pine boughs, the blanket which covers their legs. She pulls it up to better shelter Giver-of-Corn. Beside them, on a shell of bark, a sliver of fish has gone bad from inattention.
They wait through the long afternoon, but Walker does not return. When it is warmest and Giver sleeps, Maya rises in stages, gently separating herself from the lemur. She covers her charge well. Soon it will snow.
There are few memories after reaching the vault, only flashes, and that she has been active in a semi-consciousness state frightens Maya. She stumbles away, shaking, but there is no comfort to seek. She does not know if her diminished abilities endanger the lemurs, and considers locking herself beneath the earth. But the sun is warm, and for the moment every thought is a cloudless sky. Memories descend from the past like a lost tribe wandering for home.
To the east lie once powerful lands and remembered sepulchers. The life of the gods, the pulse of kings, it has all vanished and gone. Maya thinks back to the days of man. There was no disaster at the end. Just time. Civilization did not fail, it succumbed to endless seasons. Each vast stretch of years drawn on by the next saw the conquest of earth and stars, then went on, unheeding, until man dwindled and his monuments frayed.
To the west rise groves of oaks and grassland plains, beyond them, mountains that shrugged off civilization more easily than the rest.
Where is the voyager in those leaves?
A flash of time and Maya finds herself deep in the forests to the west. A lemur call escapes her throat, and suddenly she realizes she is searching for Walker-in-Leaves. The season is the same. Though the air is crisp, the trees are not yet unburdened of their color.
"Walker!" she calls out. "Your love is dying. She mourns your absence."
At the crest of a rise, Maya finds another like herself, but one long devoid of life. This sculpted form startles her at first. It has been almost wholly absorbed into the trunk of a great tree. The knee and calf of one leg escape the surrounding wood, as does a shoulder, the curve of a breast, a mournful face. A single hand reaches out from the tree toward the valley below.
In the distance, Maya sees the remnants of a fallen orbiter. Its power nacelle lies buried deep beneath the river that cushioned its fall. Earth and water, which once heaved at the impact, have worn down impenetrable metals and grown a forest over forgotten technologies.
Had the watcher in the tree come to see the fall, or to stand vigil over the corpse? Maya knows only that she must go on before the hills and the trees conspire to bury her. She moves on, continuing to call for Walker-in-Leaves.
In the night, a coyote finally answers Maya, its frenetic howls awakening responses from many cousins, hunting packs holding court up and down the valley.
Giver-of-Corn holds the spark of her generation. It is not much. A gene here and there, a deep manipulation of the flesh. The consciousness that was man is not easy to engender. Far easier to make an eye than a mind to see. Along a path of endless complication, today Giver-of-Corn mourns the absence of her mate. That Giver may die of such stubborn love before passing on her genes forces Maya deeper into the forest, using the last of her strength to call endlessly into the night.
Maya is dreaming. It s Thanksgiving, but the table is cold. The chairs are empty, and no one answers her call. As she walks from room to room, the lights dim and it begins to rain within the once familiar walls.
When Maya opens her eyes, it is to see Giver-of-Corm sleeping beneath a blanket of pine boughs, the young lemur s bushy tail twitching to the rhythm of sorrowful dreams. Maya is awake once more, but unaware of how much time has passed, or why she decided to return. Her most frightening thought is that she may already have found Walker-in-Leaves, or what the coyotes left behind.
Up from the valley, two older lemurs walk arm in arm, supporting one another along the rise. They bring with them a twig basket and a pouch made of hide. The former holds squash, its hollowed interior brimming with water, the latter a corn mash favored by the tribe. They are not without skills, these lemurs. Nor is language unknown to them. They have known Maya forever and treat her, not as a god, but as a force of nature.
With a few brief howls, by clicks, chatters, and the sweeping gestures of their tails, the lemurs make clear their plea. Their words all but rhyme. Giver-of-Corn will not eat for them. Will she eat for Maya?
Thus has the mission to found a new race come down to this: with her last strength, Maya shall spoon feed a grieving female. The thought strikes her as both funny and sad, while beyond her thoughts, the lemurs continue to chatter.
Scouts have been sent, the elders assure Maya, brave sires skilled in tracking. They hope to find Walker before the winter snows. Their voices stir Giver, and she howls in petty anguish at her benefactors, then disappears beneath the blanket. The elders bow their heads and turn to go, oblivious of Maya s failures.
Days pass upon the ridge in a thickness of clouds. Growing. Advancing. Dimmed by the mountainous billows above, the sun gives way to snow, and Maya watches Giver focus ever more intently on the line to the west. As the lemur s strength fails, her determination to await Walker s return seems to grow stronger still.
Walker-in-Leaves holds a spark of his own. He alone ventures west after the harvest. He has done it before, always returning with a colored stone, a bit of metal, or a flower never before seen by the tribe. It is as if some mad vision compels him, for the journey s end brings a collection of smooth and colored booty to be arranged in a crescent beneath a small monolith Walker himself toiled to raise. Large stones and small, the lemur has broken two fingers of its left hand doing this. To Maya, it seems the ambition of butterflies and falling leaves, of no consequence beyond a motion in the sun. The only importance now is to keep the genes within Giver alive.
Long ago, an ambition rose among the last generation of men, of what had once been men: to cultivate a new consciousness upon the Earth. Maya neither led nor knew the masters of the effort, but she was there when the first prosimians arrived, fresh from their land of orchids and baobabs. Men gathered lemurs and said to them "we shall make you men." Long years followed in the work of the genes, gentling the generations forward. Yet with each passing season, the cultivators grew fewer and their skills less true. So while the men died of age, or boredom, or despair, the lemurs prospered in their youth.
To warm the starving lemur, Maya builds a fire. For this feat the tribe has little skill, nor do they know zero, nor that a lever can move the world. She holds Giver close and pulls the rough blanket of boughs about them both.
All this time, Maya s thoughts remain clear, and the giving of comfort comforts her as well.
The snow begins to cover the monument Walker-in-Leaves has built upon the ridge. As Maya stares on and on into the fire, watching it absorb the snow, watching the snow conquer the cold stones and the grasses already bowed under a cloak of white, she drifts into a flutter of reverie, a weakening of consciousness. The gate to the end is closing, and she shall never know never know.
"I ll take it easy like, an stay around de house this winter," her father said. "There s carpenter work for me to do."
Other voices joined in around a table upon which a vast meal had been set. Thanksgiving. At the call of their names, the children rushed in from outside, their laughter quick as sunlight, their jackets smelling of autumn and leaves. Her mother made them wash and bow their heads in prayer. Those already seated joined in.
Grandmother passed the potatoes and called Maya her little kolache, rattling on in a series of endearments and concerns Maya s ear could not follow. Her mother passed on the sense of it and reminded Maya of the Czech for Thank you, Grandma.
It s good to be home, she thinks at first, then: where is the walker in those leaves?
A hand on which two fingers lay curled by the power of an old wound touches Maya. It shakes her, then gently moves her arms so that its owner can pull back the warm pine boughs hiding Giver-of Corn. Eyes first, then smile to tail, Giver opens herself to the returning wanderer. Walker-in-Leaves has returned, and the silence of their embrace brings the whole of the ridge alive in a glitter of sun-bright snow. Maya too comes awake, though this time neither word nor movement prevails entirely upon the fog of sleep.
When the answering howls come to the ridge, those who follow help Maya to stand. She follows them back to the shelter of the valley, and though she stumbles, there is satisfaction in the hurried gait, in the growing pace of the many as they gather to celebrate the return of the one. Songs of rejoicing join the undisciplined and cacophonous barks of youth. Food is brought, from the deep stores, from the caves and their recesses. Someone heats fish over coals they have kept sheltered and going for months. The thought of this ingenuity heartens Maya.
A delicacy of honeyed thorns is offered with great ceremony to Giver-of-Corn, and she tastes at last something beyond the bitterness of loss.
Though Walker-in-Leaves hesitates to leave the side of his love, the others demand stories, persuading him to the center where he begins a cacophonous song of his own.
Maya hopes to see what stones Walker has brought from the west this time, but though she tries to speak, the sounds are forgotten. The engine fades. The last flicker of man s fire is done, and with it the effort of her desires overcome her. She is gone.
Around a table suited for the Queen of queens, a thousand and a thousand sit. Mother to daughter, side-by-side, generation after generation of lemurs share in the feast. Maya is there, hearing the excited voices and the stern warnings to prayer. To her left and her right, each daughter speaks freely. Then the rhythms change, rising along one side to the cadence of Shakespeare and falling along the other to howls the forest first knew.
Unable to contain herself, Maya rises. She pushes on toward the head of a table she cannot see, beginning at last to run. What is the height her charges have reached? How far have they advanced? Lemur faces turn to laugh, their wide eyes joyous and amused. As the generations pass, she sees herself reflected in spectacles, hears the jangle of bracelets and burnished metal, watches matrons laugh behind scarves of silk. Then at last, someone with sculpted hands directs her outside, where the other children are at play in the leaves, now and forever.
THE END""".split()
# data
numbers = [2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383,389,397,401,409,419,421,431,433,439,443,449,457,461,463,467,479,487,491,499,503,509,521,523,541]
floats = []
last = 1
for number in numbers:
floats.append(float(number ** 2 / last))
last = number
def permutate(Xs, N):
if N <= 0:
yield []
return
for x in Xs:
for sub in permutate(Xs, N-1):
result = [x]+sub # don't allow duplicates
for item in result:
if result.count(item) > 1:
break
else:
yield result
def combinate(Xs, N):
"""Generate combinations of N items from list Xs"""
if N == 0:
yield []
return
for i in xrange(len(Xs)-N+1):
for r in combinate(Xs[i+1:], N-1):
yield [Xs[i]] + r
def index(sequence):
"returns integers 0 - len(sequence)"
for i in xrange(len(sequence)):
yield i
# tests
def active(rec):
if is_deleted(rec):
return DoNotIndex
return dbf.recno(rec)
def inactive(rec):
if is_deleted(rec):
return recno(rec)
return DoNotIndex
class Test_Char(unittest.TestCase):
def test_exceptions(self):
"exceptions"
self.assertRaises(ValueError, Char, 7)
self.assertRaises(ValueError, Char, ['nope'])
self.assertRaises(ValueError, Char, True)
self.assertRaises(ValueError, Char, False)
self.assertRaises(ValueError, Char, type)
self.assertRaises(ValueError, Char, str)
self.assertRaises(ValueError, Char, None)
def test_bools_and_none(self):
"booleans and None"
empty = Char()
self.assertFalse(bool(empty))
one = Char(' ')
self.assertFalse(bool(one))
actual = Char('1')
self.assertTrue(bool(actual))
def test_equality(self):
"equality"
a1 = Char('a')
a2 = 'a '
self.assertEqual(a1, a2)
self.assertEqual(a2, a1)
a3 = 'a '
a4 = Char('a ')
self.assertEqual(a3, a4)
self.assertEqual(a4, a3)
def test_inequality(self):
"inequality"
a1 = Char('ab ')
a2 = 'a b'
self.assertNotEqual(a1, a2)
self.assertNotEqual(a2, a1)
a3 = 'ab '
a4 = Char('a b')
self.assertNotEqual(a3, a4)
self.assertNotEqual(a4, a3)
def test_less_than(self):
"less-than"
a1 = Char('a')
a2 = 'a '
self.assertFalse(a1 < a2)
self.assertFalse(a2 < a1)
a3 = 'a '
a4 = Char('a ')
self.assertFalse(a3 < a4)
self.assertFalse(a4 < a3)
a5 = 'abcd'
a6 = 'abce'
self.assertTrue(a5 < a6)
self.assertFalse(a6 < a5)
def test_less_than_equal(self):
"less-than or equal"
a1 = Char('a')
a2 = 'a '
self.assertTrue(a1 <= a2)
self.assertTrue(a2 <= a1)
a3 = 'a '
a4 = Char('a ')
self.assertTrue(a3 <= a4)
self.assertTrue(a4 <= a3)
a5 = 'abcd'
a6 = 'abce'
self.assertTrue(a5 <= a6)
self.assertFalse(a6 <= a5)
def test_greater_than(self):
"greater-than or equal"
a1 = Char('a')
a2 = 'a '
self.assertTrue(a1 >= a2)
self.assertTrue(a2 >= a1)
a3 = 'a '
a4 = Char('a ')
self.assertTrue(a3 >= a4)
self.assertTrue(a4 >= a3)
a5 = 'abcd'
a6 = 'abce'
self.assertFalse(a5 >= a6)
self.assertTrue(a6 >= a5)
def test_greater_than_equal(self):
"greater-than"
a1 = Char('a')
a2 = 'a '
self.assertFalse(a1 > a2)
self.assertFalse(a2 > a1)
a3 = 'a '
a4 = Char('a ')
self.assertFalse(a3 > a4)
self.assertFalse(a4 > a3)
a5 = 'abcd'
a6 = 'abce'
self.assertFalse(a5 > a6)
self.assertTrue(a6 > a5)
class Test_Date_Time(unittest.TestCase):
"Testing Date"
def test_date_creation(self):
"Date creation"
date0 = Date()
date1 = Date()
date2 = Date.fromymd(' ')
date5 = Date.fromordinal(0)
date6 = Date.today()
date7 = Date.max
date8 = Date.min
self.assertRaises(ValueError, Date.fromymd, '00000')
self.assertRaises(ValueError, Date.fromymd, '00000000')
self.assertRaises(ValueError, Date, 0, 0, 0)
def test_date_compare(self):
"Date comparisons"
nodate1 = Date()
nodate2 = Date()
date1 = Date.fromordinal(1000)
date2 = Date.fromordinal(2000)
date3 = Date.fromordinal(3000)
self.compareTimes(nodate1, nodate2, date1, date2, date3)
def test_datetime_creation(self):
"DateTime creation"
datetime0 = DateTime()
datetime1 = DateTime()
datetime5 = DateTime.fromordinal(0)
datetime6 = DateTime.today()
datetime7 = DateTime.max
datetime8 = DateTime.min
def test_datetime_compare(self):
"DateTime comparisons"
nodatetime1 = DateTime()
nodatetime2 = DateTime()
datetime1 = Date.fromordinal(1000)
datetime2 = Date.fromordinal(20000)
datetime3 = Date.fromordinal(300000)
self.compareTimes(nodatetime1, nodatetime2, datetime1, datetime2, datetime3)
def test_time_creation(self):
"Time creation"
time0 = Time()
time1 = Time()
time7 = Time.max
time8 = Time.min
def test_time_compare(self):
"Time comparisons"
notime1 = Time()
notime2 = Time()
time1 = Date.fromordinal(1000)
time2 = Date.fromordinal(2000)
time3 = Date.fromordinal(3000)
self.compareTimes(notime1, notime2, time1, time2, time3)
def test_arithmetic(self):
"Date, DateTime, & Time Arithmetic"
one_day = datetime.timedelta(1)
a_day = Date(1970, 5, 20)
self.assertEqual(a_day + one_day, Date(1970, 5, 21))
self.assertEqual(a_day - one_day, Date(1970, 5, 19))
self.assertEqual(datetime.date(1970, 5, 21) - a_day, one_day)
a_time = Time(12)
one_second = datetime.timedelta(0, 1, 0)
self.assertEqual(a_time + one_second, Time(12, 0, 1))
self.assertEqual(a_time - one_second, Time(11, 59, 59))
self.assertEqual(datetime.time(12, 0, 1) - a_time, one_second)
an_appt = DateTime(2012, 4, 15, 12, 30, 00)
displacement = datetime.timedelta(1, 60*60*2+60*15)
self.assertEqual(an_appt + displacement, DateTime(2012, 4, 16, 14, 45, 0))
self.assertEqual(an_appt - displacement, DateTime(2012, 4, 14, 10, 15, 0))
self.assertEqual(datetime.datetime(2012, 4, 16, 14, 45, 0) - an_appt, displacement)
def test_none_compare(self):
"comparisons to None"
empty_date = Date()
empty_time = Time()
empty_datetime = DateTime()
self.assertEqual(empty_date, None)
self.assertEqual(empty_time, None)
self.assertEqual(empty_datetime, None)
def test_singletons(self):
"singletons"
empty_date = Date()
empty_time = Time()
empty_datetime = DateTime()
self.assertTrue(empty_date is NullDate)
self.assertTrue(empty_time is NullTime)
self.assertTrue(empty_datetime is NullDateTime)
def test_boolean_value(self):
"boolean evaluation"
empty_date = Date()
empty_time = Time()
empty_datetime = DateTime()
self.assertEqual(bool(empty_date), False)
self.assertEqual(bool(empty_time), False)
self.assertEqual(bool(empty_datetime), False)
actual_date = Date.today()
actual_time = Time.now()
actual_datetime = DateTime.now()
self.assertEqual(bool(actual_date), True)
self.assertEqual(bool(actual_time), True)
self.assertEqual(bool(actual_datetime), True)
def compareTimes(self, empty1, empty2, uno, dos, tres):
self.assertEqual(empty1, empty2)
self.assertEqual(uno < dos, True)
self.assertEqual(uno <= dos, True)
self.assertEqual(dos <= dos, True)
self.assertEqual(dos <= tres, True)
self.assertEqual(dos < tres, True)
self.assertEqual(tres <= tres, True)
self.assertEqual(uno == uno, True)
self.assertEqual(dos == dos, True)
self.assertEqual(tres == tres, True)
self.assertEqual(uno != dos, True)
self.assertEqual(dos != tres, True)
self.assertEqual(tres != uno, True)
self.assertEqual(tres >= tres, True)
self.assertEqual(tres > dos, True)
self.assertEqual(dos >= dos, True)
self.assertEqual(dos >= uno, True)
self.assertEqual(dos > uno, True)
self.assertEqual(uno >= uno, True)
self.assertEqual(uno >= dos, False)
self.assertEqual(uno >= tres, False)
self.assertEqual(dos >= tres, False)
self.assertEqual(tres <= dos, False)
self.assertEqual(tres <= uno, False)
self.assertEqual(tres < tres, False)
self.assertEqual(tres < dos, False)
self.assertEqual(tres < uno, False)
self.assertEqual(dos < dos, False)
self.assertEqual(dos < uno, False)
self.assertEqual(uno < uno, False)
self.assertEqual(uno == dos, False)
self.assertEqual(uno == tres, False)
self.assertEqual(dos == uno, False)
self.assertEqual(dos == tres, False)
self.assertEqual(tres == uno, False)
self.assertEqual(tres == dos, False)
self.assertEqual(uno != uno, False)
self.assertEqual(dos != dos, False)
self.assertEqual(tres != tres, False)
class Test_Null(unittest.TestCase):
def test_all(self):
null = Null = dbf.Null()
self.assertTrue(null is dbf.Null())
self.assertTrue(null + 1 is Null)
self.assertTrue(1 + null is Null)
null += 4
self.assertTrue(null is Null)
value = 5
value += null
self.assertTrue(value is Null)
self.assertTrue(null - 2 is Null)
self.assertTrue(2 - null is Null)
null -= 5
self.assertTrue(null is Null)
value = 6
value -= null
self.assertTrue(value is Null)
self.assertTrue(null / 0 is Null)
self.assertTrue(3 / null is Null)
null /= 6
self.assertTrue(null is Null)
value = 7
value /= null
self.assertTrue(value is Null)
self.assertTrue(null * -3 is Null)
self.assertTrue(4 * null is Null)
null *= 7
self.assertTrue(null is Null)
value = 8
value *= null
self.assertTrue(value is Null)
self.assertTrue(null % 1 is Null)
self.assertTrue(7 % null is Null)
null %= 1
self.assertTrue(null is Null)
value = 9
value %= null
self.assertTrue(value is Null)
self.assertTrue(null ** 2 is Null)
self.assertTrue(4 ** null is Null)
null **= 3
self.assertTrue(null is Null)
value = 9
value **= null
self.assertTrue(value is Null)
self.assertTrue(null & 1 is Null)
self.assertTrue(1 & null is Null)
null &= 1
self.assertTrue(null is Null)
value = 1
value &= null
self.assertTrue(value is Null)
self.assertTrue(null ^ 1 is Null)
self.assertTrue(1 ^ null is Null)
null ^= 1
self.assertTrue(null is Null)
value = 1
value ^= null
self.assertTrue(value is Null)
self.assertTrue(null | 1 is Null)
self.assertTrue(1 | null is Null)
null |= 1
self.assertTrue(null is Null)
value = 1
value |= null
self.assertTrue(value is Null)
self.assertTrue(str(divmod(null, 1)) == '(<null>, <null>)')
self.assertTrue(str(divmod(1, null)) == '(<null>, <null>)')
self.assertTrue(null << 1 is Null)
self.assertTrue(2 << null is Null)
null <<=3
self.assertTrue(null is Null)
value = 9
value <<= null
self.assertTrue(value is Null)
self.assertTrue(null >> 1 is Null)
self.assertTrue(2 >> null is Null)
null >>= 3
self.assertTrue(null is Null)
value = 9
value >>= null
self.assertTrue(value is Null)
self.assertTrue(-null is Null)
self.assertTrue(+null is Null)
self.assertTrue(abs(null) is Null)
self.assertTrue(~null is Null)
self.assertTrue(null.attr is Null)
self.assertTrue(null() is Null)
self.assertTrue(getattr(null, 'fake') is Null)
self.assertRaises(TypeError, hash, null)
class Test_Logical(unittest.TestCase):
"Testing Logical"
def test_unknown(self):
"Unknown"
for unk in '', '?', ' ', None, Null, Unknown, Other:
huh = unknown = Logical(unk)
self.assertEqual(huh == None, True, "huh is %r from %r, which is not None" % (huh, unk))
self.assertEqual(huh != None, False, "huh is %r from %r, which is not None" % (huh, unk))
self.assertEqual(huh != True, True, "huh is %r from %r, which is not None" % (huh, unk))
self.assertEqual(huh == True, False, "huh is %r from %r, which is not None" % (huh, unk))
self.assertEqual(huh != False, True, "huh is %r from %r, which is not None" % (huh, unk))
self.assertEqual(huh == False, False, "huh is %r from %r, which is not None" % (huh, unk))
if py_ver >= (2, 5):
self.assertEqual((0, 1, 2)[huh], 2)
def test_true(self):
"true"
for true in 'True', 'yes', 't', 'Y', 7, ['blah']:
huh = Logical(true)
self.assertEqual(huh == True, True)
self.assertEqual(huh != True, False)
self.assertEqual(huh == False, False, "%r is not True" % true)
self.assertEqual(huh != False, True)
self.assertEqual(huh == None, False)
self.assertEqual(huh != None, True)
if py_ver >= (2, 5):
self.assertEqual((0, 1, 2)[huh], 1)
def test_false(self):
"false"
for false in 'false', 'No', 'F', 'n', 0, []:
huh = Logical(false)
self.assertEqual(huh != False, False)
self.assertEqual(huh == False, True)
self.assertEqual(huh != True, True)
self.assertEqual(huh == True, False)
self.assertEqual(huh != None, True)
self.assertEqual(huh == None, False)
if py_ver >= (2, 5):
self.assertEqual((0, 1, 2)[huh], 0)
def test_singletons(self):
"singletons"
heh = Logical(True)
hah = Logical('Yes')
ick = Logical(False)
ack = Logical([])
unk = Logical('?')
bla = Logical(None)
self.assertEquals(heh is hah, True)
self.assertEquals(ick is ack, True)
self.assertEquals(unk is bla, True)
def test_error(self):
"errors"
self.assertRaises(ValueError, Logical, 'wrong')
def test_and(self):
"and"
true = Logical(True)
false = Logical(False)
unknown = Logical(None)
self.assertEquals((true & true) is true, True)
self.assertEquals((true & false) is false, True)
self.assertEquals((false & true) is false, True)
self.assertEquals((false & false) is false, True)
self.assertEquals((true & unknown) is unknown, True)
self.assertEquals((false & unknown) is false, True)
self.assertEquals((unknown & true) is unknown, True)
self.assertEquals((unknown & false) is false, True)
self.assertEquals((unknown & unknown) is unknown, True)
self.assertEquals((true & True) is true, True)
self.assertEquals((true & False) is false, True)
self.assertEquals((false & True) is false, True)
self.assertEquals((false & False) is false, True)
self.assertEquals((true & None) is unknown, True)
self.assertEquals((false & None) is false, True)
self.assertEquals((unknown & True) is unknown, True)
self.assertEquals((unknown & False) is false, True)
self.assertEquals((unknown & None) is unknown, True)
self.assertEquals((True & true) is true, True)
self.assertEquals((True & false) is false, True)
self.assertEquals((False & true) is false, True)
self.assertEquals((False & false) is false, True)
self.assertEquals((True & unknown) is unknown, True)
self.assertEquals((False & unknown) is false, True)
self.assertEquals((None & true) is unknown, True)
self.assertEquals((None & false) is false, True)
self.assertEquals((None & unknown) is unknown, True)
self.assertEquals(type(true & 0), int)
self.assertEquals(true & 0, 0)
self.assertEquals(type(true & 3), int)
self.assertEquals(true & 3, 1)
self.assertEquals(type(false & 0), int)
self.assertEquals(false & 0, 0)
self.assertEquals(type(false & 2), int)
self.assertEquals(false & 2, 0)
self.assertEquals(type(unknown & 0), int)
self.assertEquals(unknown & 0, 0)
self.assertEquals(unknown & 2, unknown)
t = true
t &= true
self.assertEquals(t is true, True)
t = true
t &= false
self.assertEquals(t is false, True)
f = false
f &= true
self.assertEquals(f is false, True)
f = false
f &= false
self.assertEquals(f is false, True)
t = true
t &= unknown
self.assertEquals(t is unknown, True)
f = false
f &= unknown
self.assertEquals(f is false, True)
u = unknown
u &= true
self.assertEquals(u is unknown, True)
u = unknown
u &= false
self.assertEquals(u is false, True)
u = unknown
u &= unknown
self.assertEquals(u is unknown, True)
t = true
t &= True
self.assertEquals(t is true, True)
t = true
t &= False
self.assertEquals(t is false, True)
f = false
f &= True
self.assertEquals(f is false, True)
f = false
f &= False
self.assertEquals(f is false, True)
t = true
t &= None
self.assertEquals(t is unknown, True)
f = false
f &= None
self.assertEquals(f is false, True)
u = unknown
u &= True
self.assertEquals(u is unknown, True)
u = unknown
u &= False
self.assertEquals(u is false, True)
u = unknown
u &= None
self.assertEquals(u is unknown, True)
t = True
t &= true
self.assertEquals(t is true, True)
t = True
t &= false
self.assertEquals(t is false, True)
f = False
f &= true
self.assertEquals(f is false, True)
f = False
f &= false
self.assertEquals(f is false, True)
t = True
t &= unknown
self.assertEquals(t is unknown, True)
f = False
f &= unknown
self.assertEquals(f is false, True)
u = None
u &= true
self.assertEquals(u is unknown, True)
u = None
u &= false
self.assertEquals(u is false, True)
u = None
u &= unknown
self.assertEquals(u is unknown, True)
t = true
t &= 0
self.assertEquals(type(true & 0), int)
t = true
t &= 0
self.assertEquals(true & 0, 0)
t = true
t &= 3
self.assertEquals(type(true & 3), int)
t = true
t &= 3
self.assertEquals(true & 3, 1)
f = false
f &= 0
self.assertEquals(type(false & 0), int)
f = false
f &= 0
self.assertEquals(false & 0, 0)
f = false
f &= 2
self.assertEquals(type(false & 2), int)
f = false
f &= 2
self.assertEquals(false & 2, 0)
u = unknown
u &= 0
self.assertEquals(type(unknown & 0), int)
u = unknown
u &= 0
self.assertEquals(unknown & 0, 0)
u = unknown
u &= 2
self.assertEquals(unknown & 2, unknown)
def test_or(self):
"or"
true = Logical(True)
false = Logical(False)
unknown = Logical(None)
self.assertEquals((true | true) is true, True)
self.assertEquals((true | false) is true, True)
self.assertEquals((false | true) is true, True)
self.assertEquals((false | false) is false, True)
self.assertEquals((true | unknown) is true, True)
self.assertEquals((false | unknown) is unknown, True)
self.assertEquals((unknown | true) is true, True)
self.assertEquals((unknown | false) is unknown, True)
self.assertEquals((unknown | unknown) is unknown, True)
self.assertEquals((true | True) is true, True)
self.assertEquals((true | False) is true, True)
self.assertEquals((false | True) is true, True)
self.assertEquals((false | False) is false, True)
self.assertEquals((true | None) is true, True)
self.assertEquals((false | None) is unknown, True)
self.assertEquals((unknown | True) is true, True)
self.assertEquals((unknown | False) is unknown, True)
self.assertEquals((unknown | None) is unknown, True)
self.assertEquals((True | true) is true, True)
self.assertEquals((True | false) is true, True)
self.assertEquals((False | true) is true, True)
self.assertEquals((False | false) is false, True)
self.assertEquals((True | unknown) is true, True)
self.assertEquals((False | unknown) is unknown, True)
self.assertEquals((None | true) is true, True)
self.assertEquals((None | false) is unknown, True)
self.assertEquals((None | unknown) is unknown, True)
self.assertEquals(type(true | 0), int)
self.assertEquals(true | 0, 1)
self.assertEquals(type(true | 2), int)
self.assertEquals(true | 2, 3)
self.assertEquals(type(false | 0), int)
self.assertEquals(false | 0, 0)
self.assertEquals(type(false | 2), int)
self.assertEquals(false | 2, 2)
self.assertEquals(unknown | 0, unknown)
self.assertEquals(unknown | 2, unknown)
t = true
t |= true
self.assertEquals(t is true, True)
t = true
t |= false
self.assertEquals(t is true, True)
f = false
f |= true
self.assertEquals(f is true, True)
f = false
f |= false
self.assertEquals(f is false, True)
t = true
t |= unknown
self.assertEquals(t is true, True)
f = false
f |= unknown
self.assertEquals(f is unknown, True)
u = unknown
u |= true
self.assertEquals(u is true, True)
u = unknown
u |= false
self.assertEquals(u is unknown, True)
u = unknown
u |= unknown
self.assertEquals(u is unknown, True)
t = true
t |= True
self.assertEquals(t is true, True)
t = true
t |= False
self.assertEquals(t is true, True)
f = false
f |= True
self.assertEquals(f is true, True)
f = false
f |= False
self.assertEquals(f is false, True)
t = true
t |= None
self.assertEquals(t is true, True)
f = false
f |= None
self.assertEquals(f is unknown, True)
u = unknown
u |= True
self.assertEquals(u is true, True)
u = unknown
u |= False
self.assertEquals(u is unknown, True)
u = unknown
u |= None
self.assertEquals(u is unknown, True)
t = True
t |= true
self.assertEquals(t is true, True)
t = True
t |= false
self.assertEquals(t is true, True)
f = False
f |= true
self.assertEquals(f is true, True)
f = False
f |= false
self.assertEquals(f is false, True)
t = True
t |= unknown
self.assertEquals(t is true, True)
f = False
f |= unknown
self.assertEquals(f is unknown, True)
u = None
u |= true
self.assertEquals(u is true, True)
u = None
u |= false
self.assertEquals(u is unknown, True)
u = None
u |= unknown
self.assertEquals(u is unknown, True)
t = true
t |= 0
self.assertEquals(type(t), int)
t = true
t |= 0
self.assertEquals(t, 1)
t = true
t |= 2
self.assertEquals(type(t), int)
t = true
t |= 2
self.assertEquals(t, 3)
f = false
f |= 0
self.assertEquals(type(f), int)
f = false
f |= 0
self.assertEquals(f, 0)
f = false
f |= 2
self.assertEquals(type(f), int)
f = false
f |= 2
self.assertEquals(f, 2)
u = unknown
u |= 0
self.assertEquals(u, unknown)
def test_xor(self):
"xor"
true = Logical(True)
false = Logical(False)
unknown = Logical(None)
self.assertEquals((true ^ true) is false, True)
self.assertEquals((true ^ false) is true, True)
self.assertEquals((false ^ true) is true, True)
self.assertEquals((false ^ false) is false, True)
self.assertEquals((true ^ unknown) is unknown, True)
self.assertEquals((false ^ unknown) is unknown, True)
self.assertEquals((unknown ^ true) is unknown, True)
self.assertEquals((unknown ^ false) is unknown, True)
self.assertEquals((unknown ^ unknown) is unknown, True)
self.assertEquals((true ^ True) is false, True)
self.assertEquals((true ^ False) is true, True)
self.assertEquals((false ^ True) is true, True)
self.assertEquals((false ^ False) is false, True)
self.assertEquals((true ^ None) is unknown, True)
self.assertEquals((false ^ None) is unknown, True)
self.assertEquals((unknown ^ True) is unknown, True)
self.assertEquals((unknown ^ False) is unknown, True)
self.assertEquals((unknown ^ None) is unknown, True)
self.assertEquals((True ^ true) is false, True)
self.assertEquals((True ^ false) is true, True)
self.assertEquals((False ^ true) is true, True)
self.assertEquals((False ^ false) is false, True)
self.assertEquals((True ^ unknown) is unknown, True)
self.assertEquals((False ^ unknown) is unknown, True)
self.assertEquals((None ^ true) is unknown, True)
self.assertEquals((None ^ false) is unknown, True)
self.assertEquals((None ^ unknown) is unknown, True)
self.assertEquals(type(true ^ 2), int)
self.assertEquals(true ^ 2, 3)
self.assertEquals(type(true ^ 0), int)
self.assertEquals(true ^ 0, 1)
self.assertEquals(type(false ^ 0), int)
self.assertEquals(false ^ 0, 0)
self.assertEquals(type(false ^ 2), int)
self.assertEquals(false ^ 2, 2)
self.assertEquals(unknown ^ 0, unknown)
self.assertEquals(unknown ^ 2, unknown)
t = true
t ^= true
self.assertEquals(t is false, True)
t = true
t ^= false
self.assertEquals(t is true, True)
f = false
f ^= true
self.assertEquals(f is true, True)
f = false
f ^= false
self.assertEquals(f is false, True)
t = true
t ^= unknown
self.assertEquals(t is unknown, True)
f = false
f ^= unknown
self.assertEquals(f is unknown, True)
u = unknown
u ^= true
self.assertEquals(u is unknown, True)
u = unknown
u ^= false
self.assertEquals(u is unknown, True)
u = unknown
u ^= unknown
self.assertEquals(u is unknown, True)
t = true
t ^= True
self.assertEquals(t is false, True)
t = true
t ^= False
self.assertEquals(t is true, True)
f = false
f ^= True
self.assertEquals(f is true, True)
f = false
f ^= False
self.assertEquals(f is false, True)
t = true
t ^= None
self.assertEquals(t is unknown, True)
f = false
f ^= None
self.assertEquals(f is unknown, True)
u = unknown
u ^= True
self.assertEquals(u is unknown, True)
u = unknown
u ^= False
self.assertEquals(u is unknown, True)
u = unknown
u ^= None
self.assertEquals(u is unknown, True)
t = True
t ^= true
self.assertEquals(t is false, True)
t = True
t ^= false
self.assertEquals(t is true, True)
f = False
f ^= true
self.assertEquals(f is true, True)
f = False
f ^= false
self.assertEquals(f is false, True)
t = True
t ^= unknown
self.assertEquals(t is unknown, True)
f = False
f ^= unknown
self.assertEquals(f is unknown, True)
u = None
u ^= true
self.assertEquals(u is unknown, True)
u = None
u ^= false
self.assertEquals(u is unknown, True)
u = None
u ^= unknown
self.assertEquals(u is unknown, True)
t = true
t ^= 0
self.assertEquals(type(true ^ 0), int)
t = true
t ^= 0
self.assertEquals(true ^ 0, 1)
t = true
t ^= 2
self.assertEquals(type(true ^ 2), int)
t = true
t ^= 2
self.assertEquals(true ^ 2, 3)
f = false
f ^= 0
self.assertEquals(type(false ^ 0), int)
f = false
f ^= 0
self.assertEquals(false ^ 0, 0)
f = false
f ^= 2
self.assertEquals(type(false ^ 2), int)
f = false
f ^= 2
self.assertEquals(false ^ 2, 2)
u = unknown
u ^= 0
self.assertEquals(unknown ^ 0, unknown)
u = unknown