Package: dbf / 0.96.005-1

0001-fix-tests-so-that-they-don-t-require-a-main.patch Patch series | download
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
From 7019625317141591892e32b027441a5560abd3c1 Mon Sep 17 00:00:00 2001
From: Margarita Manterola <marga@debian.org>
Date: Wed, 4 Nov 2015 01:38:17 +0000
Subject: fix tests so that they don't require a main.

Forwarded: not-yet
Last-Update: 2015-06-07
---
 dbf/tests.py | 147 ++++++++++++++++++++++++++++++++++-------------------------
 1 file changed, 84 insertions(+), 63 deletions(-)

diff --git a/dbf/tests.py b/dbf/tests.py
index 1981b9a..a68478a 100644
--- a/dbf/tests.py
+++ b/dbf/tests.py
@@ -2512,6 +2512,12 @@ class TestQuantum(unittest.TestCase):
         self.assertEqual(-none is none, True)
 
 class TestExceptions(unittest.TestCase):
+    def setUp(self):
+        self.tempdir = tempfile.mkdtemp()
+
+    def tearDown(self):
+        shutil.rmtree(self.tempdir, True)
+
     def test_bad_field_specs_on_creation(self):
         self.assertRaises(FieldSpecError, Table, 'blah', 'age N(3,2)', on_disk=False)
         self.assertRaises(FieldSpecError, Table, 'blah', 'name C(300)', on_disk=False)
@@ -2583,8 +2589,8 @@ class TestExceptions(unittest.TestCase):
         table.open(mode=dbf.READ_ONLY)
         self.assertRaises(DbfError, table.append, dict(name='uh uh!'))
     def test_clipper(self):
-        table = Table(os.path.join(tempdir, 'temptable'), 'name C(377); thesis C(20179)', dbf_type='clp')
-        self.assertRaises(BadDataError, Table, os.path.join(tempdir, 'temptable'))
+        table = Table(os.path.join(self.tempdir, 'temptable'), 'name C(377); thesis C(20179)', dbf_type='clp')
+        self.assertRaises(BadDataError, Table, os.path.join(self.tempdir, 'temptable'))
 
 class TestIndexLocation(unittest.TestCase):
     def test_false(self):
@@ -2595,6 +2601,12 @@ class TestIndexLocation(unittest.TestCase):
         self.assertTrue(IndexLocation(42, True))
 
 class TestDbfCreation(unittest.TestCase):
+    def setUp(self):
+        self.tempdir = tempfile.mkdtemp()
+
+    def tearDown(self):
+        shutil.rmtree(self.tempdir, True)
+
     "Testing table creation..."
     def test_db3_memory_tables(self):
         "dbf tables in memory"
@@ -2610,8 +2622,8 @@ class TestDbfCreation(unittest.TestCase):
         fields = ['name C(25)', 'hiredate D', 'male L', 'wisdom M', 'qty N(3,0)', 'weight F(7,3)']
         for i in range(1, len(fields)+1):
             for fieldlist in combinate(fields, i):
-                table = Table(os.path.join(tempdir, 'temptable'), ';'.join(fieldlist), dbf_type='db3')
-                table = Table(os.path.join(tempdir, 'temptable'), dbf_type='db3')
+                table = Table(os.path.join(self.tempdir, 'temptable'), ';'.join(fieldlist), dbf_type='db3')
+                table = Table(os.path.join(self.tempdir, 'temptable'), dbf_type='db3')
                 actualFields = table.structure()
                 self.assertEqual(fieldlist, actualFields)
                 table = open(table.filename, 'rb')
@@ -2631,13 +2643,13 @@ class TestDbfCreation(unittest.TestCase):
                 self.assertTrue(all([type(x) is unicode for x in table.field_names]))
     def test_clp_disk_tables(self):
         "clp table on disk"
-        table = Table(os.path.join(tempdir, 'temptable'), 'name C(377); thesis C(20179)', dbf_type='clp')
+        table = Table(os.path.join(self.tempdir, 'temptable'), 'name C(377); thesis C(20179)', dbf_type='clp')
         self.assertEqual(table.record_length, 20557)
         fields = ['name C(10977)', 'hiredate D', 'male L', 'wisdom M', 'qty N(3,0)', 'weight F(7,3)']
         for i in range(1, len(fields)+1):
             for fieldlist in combinate(fields, i):
-                table = Table(os.path.join(tempdir, 'temptable'), ';'.join(fieldlist), dbf_type='clp')
-                table = Table(os.path.join(tempdir, 'temptable'), dbf_type='clp')
+                table = Table(os.path.join(self.tempdir, 'temptable'), ';'.join(fieldlist), dbf_type='clp')
+                table = Table(os.path.join(self.tempdir, 'temptable'), dbf_type='clp')
                 actualFields = table.structure()
                 self.assertEqual(fieldlist, actualFields)
                 table = open(table.filename, 'rb')
@@ -2661,8 +2673,8 @@ class TestDbfCreation(unittest.TestCase):
                   'litres F(11,5)', 'blob G', 'graphic P', 'weight F(7,3)']
         for i in range(1, len(fields)+1):
             for fieldlist in combinate(fields, i):
-                table = Table(os.path.join(tempdir, 'tempfp'), ';'.join(fieldlist), dbf_type='vfp')
-                table = Table(os.path.join(tempdir, 'tempfp'), dbf_type='vfp')
+                table = Table(os.path.join(self.tempdir, 'tempfp'), ';'.join(fieldlist), dbf_type='vfp')
+                table = Table(os.path.join(self.tempdir, 'tempfp'), dbf_type='vfp')
                 actualFields = table.structure()
                 self.assertEqual(fieldlist, actualFields)
     def test_vfp_memory_tables(self):
@@ -2685,19 +2697,19 @@ class TestDbfCreation(unittest.TestCase):
                   'weight F(7,3)']
         for i in range(1, len(fields)+1):
             for fieldlist in combinate(fields, i):
-                table = Table(os.path.join(tempdir, 'tempvfp'), ';'.join(fieldlist), dbf_type='vfp')
-                table = Table(os.path.join(tempdir, 'tempvfp'), dbf_type='vfp')
+                table = Table(os.path.join(self.tempdir, 'tempvfp'), ';'.join(fieldlist), dbf_type='vfp')
+                table = Table(os.path.join(self.tempdir, 'tempvfp'), dbf_type='vfp')
                 actualFields = table.structure()
                 fieldlist = [f.replace('nocptrans','binary') for f in fieldlist]
                 self.assertEqual(fieldlist, actualFields)
     def test_codepage(self):
-        table = Table(os.path.join(tempdir, 'tempvfp'), 'name C(25); male L; fired D null', dbf_type='vfp')
+        table = Table(os.path.join(self.tempdir, 'tempvfp'), 'name C(25); male L; fired D null', dbf_type='vfp')
         self.assertEqual(dbf.default_codepage, 'ascii')
         self.assertEqual(table.codepage, dbf.CodePage('ascii'))
         table.close()
         table.open()
         table.close()
-        table = Table(os.path.join(tempdir, 'tempvfp'), 'name C(25); male L; fired D null', dbf_type='vfp', codepage='cp850')
+        table = Table(os.path.join(self.tempdir, 'tempvfp'), 'name C(25); male L; fired D null', dbf_type='vfp', codepage='cp850')
         self.assertEqual(table.codepage, dbf.CodePage('cp850'))
 
         newtable = table.new('tempvfp2', codepage='cp437')
@@ -2705,43 +2717,43 @@ class TestDbfCreation(unittest.TestCase):
         newtable.open()
         newtable.create_backup()
         newtable.close()
-        bckup = Table(os.path.join(tempdir, newtable.backup))
+        bckup = Table(os.path.join(self.tempdir, newtable.backup))
         self.assertEqual(bckup.codepage, newtable.codepage)
     def test_db3_ignore_memos(self):
-        table = Table(os.path.join(tempdir, 'tempdb3'), 'name C(25); wisdom M', dbf_type='db3').open()
+        table = Table(os.path.join(self.tempdir, 'tempdb3'), 'name C(25); wisdom M', dbf_type='db3').open()
         table.append(('QC Tester', 'check it twice!  check it thrice!  check it . . . uh . . . again!'))
         table.close()
-        table = Table(os.path.join(tempdir, 'tempdb3'), dbf_type='db3', ignore_memos=True)
+        table = Table(os.path.join(self.tempdir, 'tempdb3'), dbf_type='db3', ignore_memos=True)
         table.open()
         try:
             self.assertEqual(table[0].wisdom, '')
         finally:
             table.close()
     def test_fp_ignore_memos(self):
-        table = Table(os.path.join(tempdir, 'tempdb3'), 'name C(25); wisdom M', dbf_type='fp').open()
+        table = Table(os.path.join(self.tempdir, 'tempdb3'), 'name C(25); wisdom M', dbf_type='fp').open()
         table.append(('QC Tester', 'check it twice!  check it thrice!  check it . . . uh . . . again!'))
         table.close()
-        table = Table(os.path.join(tempdir, 'tempdb3'), dbf_type='fp', ignore_memos=True)
+        table = Table(os.path.join(self.tempdir, 'tempdb3'), dbf_type='fp', ignore_memos=True)
         table.open()
         try:
             self.assertEqual(table[0].wisdom, '')
         finally:
             table.close()
     def test_vfp_ignore_memos(self):
-        table = Table(os.path.join(tempdir, 'tempdb3'), 'name C(25); wisdom M', dbf_type='vfp').open()
+        table = Table(os.path.join(self.tempdir, 'tempdb3'), 'name C(25); wisdom M', dbf_type='vfp').open()
         table.append(('QC Tester', 'check it twice!  check it thrice!  check it . . . uh . . . again!'))
         table.close()
-        table = Table(os.path.join(tempdir, 'tempdb3'), dbf_type='vfp', ignore_memos=True)
+        table = Table(os.path.join(self.tempdir, 'tempdb3'), dbf_type='vfp', ignore_memos=True)
         table.open()
         try:
             self.assertEqual(table[0].wisdom, '')
         finally:
             table.close()
     def test_clp_ignore_memos(self):
-        table = Table(os.path.join(tempdir, 'tempdb3'), 'name C(25); wisdom M', dbf_type='clp').open()
+        table = Table(os.path.join(self.tempdir, 'tempdb3'), 'name C(25); wisdom M', dbf_type='clp').open()
         table.append(('QC Tester', 'check it twice!  check it thrice!  check it . . . uh . . . again!'))
         table.close()
-        table = Table(os.path.join(tempdir, 'tempdb3'), dbf_type='clp', ignore_memos=True)
+        table = Table(os.path.join(self.tempdir, 'tempdb3'), dbf_type='clp', ignore_memos=True)
         table.open()
         try:
             self.assertEqual(table[0].wisdom, '')
@@ -2750,14 +2762,16 @@ class TestDbfCreation(unittest.TestCase):
 
 class TestDbfRecords(unittest.TestCase):
     "Testing records"
+
     def setUp(self):
+        self.tempdir = tempfile.mkdtemp()
         self.dbf_table = Table(
-                os.path.join(tempdir, 'dbf_table'),
+                os.path.join(self.tempdir, 'dbf_table'),
                 'name C(25); paid L; qty N(11,5); orderdate D; desc M',
                 dbf_type='db3',
                 )
         self.vfp_table = Table(
-                os.path.join(tempdir, 'vfp_table'),
+                os.path.join(self.tempdir, 'vfp_table'),
                 'name C(25); paid L; qty N(11,5); orderdate D; desc M; mass B;' +
                 ' weight F(18,3); age I; meeting T; misc G; photo P; price Y',
                 dbf_type='vfp',
@@ -2766,6 +2780,7 @@ class TestDbfRecords(unittest.TestCase):
     def tearDown(self):
         self.dbf_table.close()
         self.vfp_table.close()
+        shutil.rmtree(self.tempdir, True)
 
     def test_slicing(self):
         table = self.dbf_table
@@ -3441,13 +3456,14 @@ class TestDbfRecords(unittest.TestCase):
 class TestDbfRecordTemplates(unittest.TestCase):
     "Testing records"
     def setUp(self):
+        self.tempdir = tempfile.mkdtemp()
         self.dbf_table = Table(
-                os.path.join(tempdir, 'dbf_table'),
+                os.path.join(self.tempdir, 'dbf_table'),
                 'name C(25); paid L; qty N(11,5); orderdate D; desc M',
                 dbf_type='db3',
                 )
         self.vfp_table = Table(
-                os.path.join(tempdir, 'vfp_table'),
+                os.path.join(self.tempdir, 'vfp_table'),
                 'name C(25); paid L; qty N(11,5); orderdate D; desc M; mass B;' +
                 ' weight F(18,3); age I; meeting T; misc G; photo P; price Y',
                 dbf_type='vfp',
@@ -3456,6 +3472,7 @@ class TestDbfRecordTemplates(unittest.TestCase):
     def tearDown(self):
         self.dbf_table.close()
         self.vfp_table.close()
+        shutil.rmtree(self.tempdir, True)
 
     def test_dbf_storage(self):
         table = self.dbf_table
@@ -3488,9 +3505,10 @@ class TestDbfRecordTemplates(unittest.TestCase):
 
 class TestDbfFunctions(unittest.TestCase):
     def setUp(self):
+        self.tempdir = tempfile.mkdtemp()
         "create a dbf and vfp table"
         self.dbf_table = table = Table(
-            os.path.join(tempdir, 'temptable'),
+            os.path.join(self.tempdir, 'temptable'),
             'name C(25); paid L; qty N(11,5); orderdate D; desc M', dbf_type='db3'
             )
         table.open()
@@ -3514,7 +3532,7 @@ class TestDbfFunctions(unittest.TestCase):
         table.close()
 
         self.vfp_table = table = Table(
-                os.path.join(tempdir, 'tempvfp'),
+                os.path.join(self.tempdir, 'tempvfp'),
                 'name C(25); paid L; qty N(11,5); orderdate D; desc M; mass B;'
                 ' weight F(18,3); age I; meeting T; misc G; photo P',
                 dbf_type='vfp',
@@ -3563,6 +3581,7 @@ class TestDbfFunctions(unittest.TestCase):
     def tearDown(self):
         self.dbf_table.close()
         self.vfp_table.close()
+        shutil.rmtree(self.tempdir, True)
 
     def test_add_fields_to_dbf_table(self):
         "dbf table:  adding and deleting fields"
@@ -3808,7 +3827,7 @@ class TestDbfFunctions(unittest.TestCase):
         table.open()
         table.append(multiple=10)
         self.assertEqual(table.next_record, table[0])
-        table = self.dbf_table              # Table(os.path.join(tempdir, 'temptable'), dbf_type='db3')
+        table = self.dbf_table              # Table(os.path.join(self.tempdir, 'temptable'), dbf_type='db3')
         table.open()
         total = len(table)
         table.bottom()
@@ -3854,7 +3873,7 @@ class TestDbfFunctions(unittest.TestCase):
 
         # check that deletes were saved to disk..
         table.close()
-        table = Table(os.path.join(tempdir, 'temptable'), dbf_type='db3')
+        table = Table(os.path.join(self.tempdir, 'temptable'), dbf_type='db3')
         table.open()
         active_records = table.create_index(active)
         i = 0
@@ -4000,7 +4019,7 @@ class TestDbfFunctions(unittest.TestCase):
         qtylist = self.dbf_qtylist
         orderlist = self.dbf_orderlist
         desclist = self.dbf_desclist
-        table2 = table.new(os.path.join(tempdir, 'temptable2'))
+        table2 = table.new(os.path.join(self.tempdir, 'temptable2'))
         table2.open()
         for record in table:
             table2.append()
@@ -4013,7 +4032,7 @@ class TestDbfFunctions(unittest.TestCase):
                 self.assertEqual(newrecord[field], record[field])
         table2.close()
         table2 = None
-        table2 = Table(os.path.join(tempdir, 'temptable2'), dbf_type='db3')
+        table2 = Table(os.path.join(self.tempdir, 'temptable2'), dbf_type='db3')
         table2.open()
         for i in range(len(table)):
             temp1 = dbf.scatter(table[i])
@@ -4052,7 +4071,7 @@ class TestDbfFunctions(unittest.TestCase):
             self.assertEqual(oldfield in table.field_names, False)
             self.assertEqual('newfield' in table.field_names, True)
             table.close()
-            table = Table(os.path.join(tempdir, 'temptable'), dbf_type='db3')
+            table = Table(os.path.join(self.tempdir, 'temptable'), dbf_type='db3')
             table.open()
             self.assertEqual(oldfield in table.field_names, False)
             self.assertEqual('newfield' in table.field_names, True)
@@ -4070,7 +4089,7 @@ class TestDbfFunctions(unittest.TestCase):
         qtylist = self.dbf_qtylist
         orderlist = self.dbf_orderlist
         desclist = self.dbf_desclist
-        table2 = table.new(os.path.join(tempdir, 'temptable2'))
+        table2 = table.new(os.path.join(self.tempdir, 'temptable2'))
         table2.open()
         for record in table:
             table2.append(record)
@@ -4082,7 +4101,7 @@ class TestDbfFunctions(unittest.TestCase):
                 if key not in table2.memo_types:
                     self.assertEqual(newrecord[field], record[field])
         table2.close()
-        table2 = Table(os.path.join(tempdir, 'temptable2'), dbf_type='db3')
+        table2 = Table(os.path.join(self.tempdir, 'temptable2'), dbf_type='db3')
         table2.open()
         for i in range(len(table)):
             dict1 = dbf.scatter(table[i], as_type=dict)
@@ -4114,7 +4133,7 @@ class TestDbfFunctions(unittest.TestCase):
         qtylist = self.dbf_qtylist
         orderlist = self.dbf_orderlist
         desclist = self.dbf_desclist
-        table2 = table.new(os.path.join(tempdir, 'temptable2'))
+        table2 = table.new(os.path.join(self.tempdir, 'temptable2'))
         table2.open()
         record = table.next_record
         table2.append(dbf.scatter(record), multiple=100)
@@ -4122,13 +4141,13 @@ class TestDbfFunctions(unittest.TestCase):
             for field in dbf.field_names(record):
                 self.assertEqual(record[field], samerecord[field])
         table2.close()
-        table2 = Table(os.path.join(tempdir, 'temptable2'), dbf_type='db3')
+        table2 = Table(os.path.join(self.tempdir, 'temptable2'), dbf_type='db3')
         table2.open()
         for samerecord in table2:
             for field in dbf.field_names(record):
                 self.assertEqual(record[field], samerecord[field])
         table2.close()
-        table3 = table.new(os.path.join(tempdir, 'temptable3'))
+        table3 = table.new(os.path.join(self.tempdir, 'temptable3'))
         table3.open()
         record = table.next_record
         table3.append(record, multiple=100)
@@ -4136,7 +4155,7 @@ class TestDbfFunctions(unittest.TestCase):
             for field in dbf.field_names(record):
                 self.assertEqual(record[field], samerecord[field])
         table3.close()
-        table3 = Table(os.path.join(tempdir, 'temptable3'), dbf_type='db3')
+        table3 = Table(os.path.join(self.tempdir, 'temptable3'), dbf_type='db3')
         table3.open()
         for samerecord in table3:
             for field in dbf.field_names(record):
@@ -4192,35 +4211,35 @@ class TestDbfFunctions(unittest.TestCase):
         dbf.write(table[0], motto='Are we there yet??')
         self.assertEqual(table[0].motto, 'Are we there yet??')
         table.close()
-        table = Table(os.path.join(tempdir, 'temptable4'), 'name C(50); age N(3,0)', dbf_type='db3')
+        table = Table(os.path.join(self.tempdir, 'temptable4'), 'name C(50); age N(3,0)', dbf_type='db3')
         table.open()
         table.append(('user', 0))
         table.close()
         table.open()
         table.close()
-        table = Table(os.path.join(tempdir, 'temptable4'), dbf_type='db3')
+        table = Table(os.path.join(self.tempdir, 'temptable4'), dbf_type='db3')
         table.open()
         table.add_fields('motto M')
         dbf.write(table[0], motto='Are we there yet??')
         self.assertEqual(table[0].motto, 'Are we there yet??')
         table.close()
-        table = Table(os.path.join(tempdir, 'temptable4'), dbf_type='db3')
+        table = Table(os.path.join(self.tempdir, 'temptable4'), dbf_type='db3')
         table.open()
         self.assertEqual(table[0].motto, 'Are we there yet??')
         table.close()
-        table = Table(os.path.join(tempdir, 'temptable4'), 'name C(50); age N(3,0)', dbf_type='vfp')
+        table = Table(os.path.join(self.tempdir, 'temptable4'), 'name C(50); age N(3,0)', dbf_type='vfp')
         table.open()
         table.append(('user', 0))
         table.close()
         table.open()
         table.close()
-        table = Table(os.path.join(tempdir, 'temptable4'), dbf_type='vfp')
+        table = Table(os.path.join(self.tempdir, 'temptable4'), dbf_type='vfp')
         table.open()
         table.add_fields('motto M')
         dbf.write(table[0], motto='Are we there yet??')
         self.assertEqual(table[0].motto, 'Are we there yet??')
         table.close()
-        table = Table(os.path.join(tempdir, 'temptable4'), dbf_type='vfp')
+        table = Table(os.path.join(self.tempdir, 'temptable4'), dbf_type='vfp')
         table.open()
         self.assertEqual(table[0].motto, 'Are we there yet??')
         table.close()
@@ -4234,49 +4253,49 @@ class TestDbfFunctions(unittest.TestCase):
         orderlist = self.dbf_orderlist
         desclist = self.dbf_desclist
         dbf.export(table, table.filename, header=False)
-        csvtable = dbf.from_csv(os.path.join(tempdir, 'temptable.csv'))
+        csvtable = dbf.from_csv(os.path.join(self.tempdir, 'temptable.csv'))
         csvtable.open()
         for i in index(table):
             for j in index(table.field_names):
                 self.assertEqual(str(table[i][j]), csvtable[i][j])
         csvtable.close()
-        csvtable = dbf.from_csv(os.path.join(tempdir, 'temptable.csv'), to_disk=True, filename=os.path.join(tempdir, 'temptable5'))
+        csvtable = dbf.from_csv(os.path.join(self.tempdir, 'temptable.csv'), to_disk=True, filename=os.path.join(self.tempdir, 'temptable5'))
         csvtable.open()
         for i in index(table):
             for j in index(table.field_names):
                 self.assertEqual(str(table[i][j]).strip(), csvtable[i][j].strip())
         csvtable.close()
-        csvtable = dbf.from_csv(os.path.join(tempdir, 'temptable.csv'), field_names=['field1','field2'])
+        csvtable = dbf.from_csv(os.path.join(self.tempdir, 'temptable.csv'), field_names=['field1','field2'])
         csvtable.open()
         for i in index(table):
             for j in index(table.field_names):
                 self.assertEqual(str(table[i][j]), csvtable[i][j])
         csvtable.close()
-        csvtable = dbf.from_csv(os.path.join(tempdir, 'temptable.csv'), field_names=['field1','field2'], to_disk=True, filename=os.path.join(tempdir, 'temptable5'))
+        csvtable = dbf.from_csv(os.path.join(self.tempdir, 'temptable.csv'), field_names=['field1','field2'], to_disk=True, filename=os.path.join(self.tempdir, 'temptable5'))
         csvtable.open()
         for i in index(table):
             for j in index(table.field_names):
                 self.assertEqual(str(table[i][j]).strip(), csvtable[i][j].strip())
         csvtable.close()
-        csvtable = dbf.from_csv(os.path.join(tempdir, 'temptable.csv'), extra_fields=['count N(5,0)','id C(10)'])
+        csvtable = dbf.from_csv(os.path.join(self.tempdir, 'temptable.csv'), extra_fields=['count N(5,0)','id C(10)'])
         csvtable.open()
         for i in index(table):
             for j in index(table.field_names):
                 self.assertEqual(str(table[i][j]), csvtable[i][j])
         csvtable.close()
-        csvtable = dbf.from_csv(os.path.join(tempdir, 'temptable.csv'), extra_fields=['count N(5,0)','id C(10)'], to_disk=True, filename=os.path.join(tempdir, 'temptable5'))
+        csvtable = dbf.from_csv(os.path.join(self.tempdir, 'temptable.csv'), extra_fields=['count N(5,0)','id C(10)'], to_disk=True, filename=os.path.join(self.tempdir, 'temptable5'))
         csvtable.open()
         for i in index(table):
             for j in index(table.field_names):
                 self.assertEqual(str(table[i][j]).strip(), csvtable[i][j].strip())
         csvtable.close()
-        csvtable = dbf.from_csv(os.path.join(tempdir, 'temptable.csv'), field_names=['name','qty','paid','desc'], extra_fields='test1 C(15);test2 L'.split(';'))
+        csvtable = dbf.from_csv(os.path.join(self.tempdir, 'temptable.csv'), field_names=['name','qty','paid','desc'], extra_fields='test1 C(15);test2 L'.split(';'))
         csvtable.open()
         for i in index(table):
             for j in index(table.field_names):
                 self.assertEqual(str(table[i][j]), csvtable[i][j])
         csvtable.close()
-        csvtable = dbf.from_csv(os.path.join(tempdir, 'temptable.csv'), field_names=['name','qty','paid','desc'], extra_fields='test1 C(15);test2 L'.split(';'), to_disk=True, filename=os.path.join(tempdir, 'temptable5'))
+        csvtable = dbf.from_csv(os.path.join(self.tempdir, 'temptable.csv'), field_names=['name','qty','paid','desc'], extra_fields='test1 C(15);test2 L'.split(';'), to_disk=True, filename=os.path.join(self.tempdir, 'temptable5'))
         csvtable.open()
         for i in index(table):
             for j in index(table.field_names):
@@ -4427,9 +4446,10 @@ class TestDbfFunctions(unittest.TestCase):
 
 class TestDbfNavigation(unittest.TestCase):
     def setUp(self):
+        self.tempdir = tempfile.mkdtemp()
         "create a dbf and vfp table"
         self.dbf_table = table = Table(
-            os.path.join(tempdir, 'temptable'),
+            os.path.join(self.tempdir, 'temptable'),
             'name C(25); paid L; qty N(11,5); orderdate D; desc M', dbf_type='db3'
             )
         table.open()
@@ -4453,7 +4473,7 @@ class TestDbfNavigation(unittest.TestCase):
         table.close()
 
         self.vfp_table = table = Table(
-                os.path.join(tempdir, 'tempvfp'),
+                os.path.join(self.tempdir, 'tempvfp'),
                 'name C(25); paid L; qty N(11,5); orderdate D; desc M; mass B;'
                 ' weight F(18,3); age I; meeting T; misc G; photo P',
                 dbf_type='vfp',
@@ -4502,6 +4522,7 @@ class TestDbfNavigation(unittest.TestCase):
     def tearDown(self):
         self.dbf_table.close()
         self.vfp_table.close()
+        shutil.rmtree(self.tempdir, True)
 
     def test_top(self):
         "top, current in Tables, Lists, and Indexes"
@@ -4728,9 +4749,10 @@ class TestDbfNavigation(unittest.TestCase):
 class TestDbfLists(unittest.TestCase):
     "DbfList tests"
     def setUp(self):
+        self.tempdir = tempfile.mkdtemp()
         "create a dbf table"
         self.dbf_table = table = Table(
-            os.path.join(tempdir, 'temptable'),
+            os.path.join(self.tempdir, 'temptable'),
             'name C(25); paid L; qty N(11,5); orderdate D; desc M', dbf_type='db3'
             )
         table.open()
@@ -4755,6 +4777,7 @@ class TestDbfLists(unittest.TestCase):
         table.close()
     def tearDown(self):
         self.dbf_table.close()
+        shutil.rmtree(self.tempdir, True)
     def test_exceptions(self):
         table = self.dbf_table
         table.open()
@@ -4879,9 +4902,10 @@ class TestDbfLists(unittest.TestCase):
 class TestWhatever(unittest.TestCase):
     "move tests here to run one at a time while debugging"
     def setUp(self):
+        self.tempdir = tempfile.mkdtemp()
         "create a dbf and vfp table"
         self.dbf_table = table = Table(
-            os.path.join(tempdir, 'temptable'),
+            os.path.join(self.tempdir, 'temptable'),
             'name C(25); paid L; qty N(11,5); orderdate D; desc M', dbf_type='db3'
             )
         table.open()
@@ -4905,7 +4929,7 @@ class TestWhatever(unittest.TestCase):
         table.close()
 
         self.vfp_table = table = Table(
-                os.path.join(tempdir, 'tempvfp'),
+                os.path.join(self.tempdir, 'tempvfp'),
                 'name C(25); paid L; qty N(11,5); orderdate D; desc M; mass B;'
                 ' weight F(18,3); age I; meeting T; misc G; photo P',
                 dbf_type='vfp',
@@ -4954,10 +4978,7 @@ class TestWhatever(unittest.TestCase):
     def tearDown(self):
         self.dbf_table.close()
         self.vfp_table.close()
+        shutil.rmtree(self.tempdir, True)
 # main
 if __name__ == '__main__':
-    tempdir = tempfile.mkdtemp()
-    try:
-        unittest.main()
-    finally:
-        shutil.rmtree(tempdir, True)
+    unittest.main()