forked from jaraco/path
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_path.py
709 lines (609 loc) · 23.1 KB
/
test_path.py
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
""" test_path.py - Test the path module.
This only runs on Posix and NT right now. I would like to have more
tests. You can help! Just add appropriate pathnames for your
platform (os.name) in each place where the p() function is called.
Then send me the result. If you can't get the test to run at all on
your platform, there's probably a bug in path.py -- please let me
know!
TempDirTestCase.testTouch() takes a while to run. It sleeps a few
seconds to allow some time to pass between calls to check the modify
time on files.
Authors:
Jason Orendorff <jason.orendorff\x40gmail\x2ecom>
Marc Abramowitz <msabramo\x40gmail\x2ecom>
Others - unfortunately attribution is lost
"""
from __future__ import with_statement # Needed for Python 2.5
import unittest
import codecs
import os
import random
import shutil
import tempfile
import time
import ntpath
import posixpath
from path import path, tempdir
def p(**choices):
""" Choose a value from several possible values, based on os.name """
return choices[os.name]
class BasicTestCase(unittest.TestCase):
def testRelpath(self):
root = path(p(nt='C:\\', posix='/'))
foo = root / 'foo'
quux = foo / 'quux'
bar = foo / 'bar'
boz = bar / 'Baz' / 'Boz'
up = path(os.pardir)
# basics
self.assertEqual(root.relpathto(boz), path('foo')/'bar'/'Baz'/'Boz')
self.assertEqual(bar.relpathto(boz), path('Baz')/'Boz')
self.assertEqual(quux.relpathto(boz), up/'bar'/'Baz'/'Boz')
self.assertEqual(boz.relpathto(quux), up/up/up/'quux')
self.assertEqual(boz.relpathto(bar), up/up)
# x.relpathto(x) == curdir
self.assertEqual(root.relpathto(root), os.curdir)
self.assertEqual(boz.relpathto(boz), os.curdir)
# Make sure case is properly noted (or ignored)
self.assertEqual(boz.relpathto(boz.normcase()), os.curdir)
# relpath()
cwd = path(os.getcwd())
self.assertEqual(boz.relpath(), cwd.relpathto(boz))
if os.name == 'nt':
# Check relpath across drives.
d = path('D:\\')
self.assertEqual(d.relpathto(boz), boz)
def testConstructionFromNone(self):
"""
path class raise a TypeError when constructed from None
"""
try:
path(None)
except TypeError:
pass
else:
raise Exception("DID NOT RAISE")
def testConstructionFromInt(self):
"""
path class should raise a TypeError when constructed from an integer.
"""
try:
path(1)
except TypeError:
pass
else:
raise Exception("DID NOT RAISE")
def testStringCompatibility(self):
""" Test compatibility with ordinary strings. """
x = path('xyzzy')
self.assert_(x == 'xyzzy')
self.assert_(x == u'xyzzy')
# sorting
items = [path('fhj'),
path('fgh'),
'E',
path('d'),
'A',
path('B'),
'c']
items.sort()
self.assert_(items == ['A', 'B', 'E', 'c', 'd', 'fgh', 'fhj'])
# Test p1/p1.
p1 = path("foo")
p2 = path("bar")
self.assertEqual(p1/p2, p(nt='foo\\bar', posix='foo/bar'))
def testProperties(self):
# Create sample path object.
f = p(nt='C:\\Program Files\\Python\\Lib\\xyzzy.py',
posix='/usr/local/python/lib/xyzzy.py')
f = path(f)
# .parent
self.assertEqual(f.parent, p(nt='C:\\Program Files\\Python\\Lib',
posix='/usr/local/python/lib'))
# .name
self.assertEqual(f.name, 'xyzzy.py')
self.assertEqual(f.parent.name, p(nt='Lib', posix='lib'))
# .ext
self.assertEqual(f.ext, '.py')
self.assertEqual(f.parent.ext, '')
# .drive
self.assertEqual(f.drive, p(nt='C:', posix=''))
def testMethods(self):
# .abspath()
self.assertEqual(path(os.curdir).abspath(), os.getcwd())
# .getcwd()
cwd = path.getcwd()
self.assert_(isinstance(cwd, path))
self.assertEqual(cwd, os.getcwd())
def testUNC(self):
if hasattr(os.path, 'splitunc'):
p = path(r'\\python1\share1\dir1\file1.txt')
self.assert_(p.uncshare == r'\\python1\share1')
self.assert_(p.splitunc() == os.path.splitunc(str(p)))
def testExplicitModule(self):
"""
The user may specify an explicit path module to use.
"""
nt_ok = path.using_module(ntpath)(r'foo\bar\baz')
posix_ok = path.using_module(posixpath)(r'foo/bar/baz')
posix_wrong = path.using_module(posixpath)(r'foo\bar\baz')
self.assertEqual(nt_ok.dirname(), r'foo\bar')
self.assertEqual(posix_ok.dirname(), r'foo/bar')
self.assertEqual(posix_wrong.dirname(), '')
self.assertEqual(nt_ok / 'quux', r'foo\bar\baz\quux')
self.assertEqual(posix_ok / 'quux', r'foo/bar/baz/quux')
def testExplicitModuleClasses(self):
"""
Multiple calls to path.using_module should produce the same class.
"""
nt_path = path.using_module(ntpath)
self.assert_(nt_path is path.using_module(ntpath))
self.assertEqual(nt_path.__name__, 'path_ntpath')
def test_joinpath_on_instance(self):
res = path('foo')
foo_bar = res.joinpath('bar')
assert foo_bar == p(nt='foo\\bar', posix='foo/bar')
def test_joinpath_to_nothing(self):
res = path('foo')
assert res.joinpath() == res
def test_joinpath_on_class(self):
"Construct a path from a series of strings"
foo_bar = path.joinpath('foo', 'bar')
assert foo_bar == p(nt='foo\\bar', posix='foo/bar')
def test_joinpath_fails_on_empty(self):
"It doesn't make sense to join nothing at all"
try:
path.joinpath()
except TypeError:
pass
else:
raise Exception("did not raise")
def test_joinpath_returns_same_type(self):
path_posix = path.using_module(posixpath)
res = path_posix.joinpath('foo')
assert isinstance(res, path_posix)
res2 = res.joinpath('bar')
assert isinstance(res2, path_posix)
assert res2 == 'foo/bar'
class ReturnSelfTestCase(unittest.TestCase):
"""
Some methods don't necessarily return any value (e.g. makedirs,
makedirs_p, rename, mkdir, touch, chroot). These methods should return
self anyhow to allow methods to be chained.
"""
def setUp(self):
# Create a temporary directory.
f = tempfile.mktemp()
system_tmp_dir = os.path.dirname(f)
my_dir = 'testpath_tempdir_' + str(random.random())[2:]
self.tempdir = os.path.join(system_tmp_dir, my_dir)
os.mkdir(self.tempdir)
def tearDown(self):
shutil.rmtree(self.tempdir)
def testMakedirs_pReturnsSelf(self):
"""
path('foo').makedirs_p() == path('foo')
"""
p = path(self.tempdir) / "newpath"
ret = p.makedirs_p()
self.assertEquals(p, ret)
def testMakedirs_pReturnsSelfEvenIfExists(self):
p = path(self.tempdir)
ret = p.makedirs_p()
self.assertEquals(p, ret)
def testRenameReturnsSelf(self):
p = path(self.tempdir) / "somefile"
p.touch()
target = path(self.tempdir) / "otherfile"
ret = p.rename(target)
self.assertEquals(target, ret)
def testMkdirReturnsSelf(self):
p = path(self.tempdir) / "newdir"
ret = p.mkdir()
self.assertEquals(p, ret)
def testTouchReturnsSelf(self):
p = path(self.tempdir) / "empty file"
ret = p.touch()
self.assertEquals(p, ret)
class ScratchDirTestCase(unittest.TestCase):
"""
Tests that run in a temporary directory (does not test tempdir class)
"""
def setUp(self):
# Create a temporary directory.
f = tempfile.mktemp()
system_tmp_dir = os.path.dirname(f)
my_dir = 'testpath_tempdir_' + str(random.random())[2:]
self.tempdir = os.path.join(system_tmp_dir, my_dir)
os.mkdir(self.tempdir)
def tearDown(self):
shutil.rmtree(self.tempdir)
def testContextManager(self):
"""Can be used as context manager for chdir."""
d = path(self.tempdir)
subdir = d / 'subdir'
subdir.makedirs()
old_dir = os.getcwd()
with subdir:
self.assertEquals(os.getcwd(), os.path.realpath(subdir))
self.assertEquals(os.getcwd(), old_dir)
def testTouch(self):
# NOTE: This test takes a long time to run (~10 seconds).
# It sleeps several seconds because on Windows, the resolution
# of a file's mtime and ctime is about 2 seconds.
#
# atime isn't tested because on Windows the resolution of atime
# is something like 24 hours.
d = path(self.tempdir)
f = d / 'test.txt'
t0 = time.time() - 3
f.touch()
t1 = time.time() + 3
try:
self.assert_(f.exists())
self.assert_(f.isfile())
self.assertEqual(f.size, 0)
self.assert_(t0 <= f.mtime <= t1)
if hasattr(os.path, 'getctime'):
ct = f.ctime
self.assert_(t0 <= ct <= t1)
time.sleep(5)
fobj = open(f, 'ab')
fobj.write('some bytes'.encode('utf-8'))
fobj.close()
time.sleep(5)
t2 = time.time() - 3
f.touch()
t3 = time.time() + 3
assert t0 <= t1 < t2 <= t3 # sanity check
self.assert_(f.exists())
self.assert_(f.isfile())
self.assertEqual(f.size, 10)
self.assert_(t2 <= f.mtime <= t3)
if hasattr(os.path, 'getctime'):
ct2 = f.ctime
if os.name == 'nt':
# On Windows, "ctime" is CREATION time
self.assertEqual(ct, ct2)
self.assert_(ct2 < t2)
else:
# On other systems, it might be the CHANGE time
# (especially on Unix, time of inode changes)
self.failUnless(ct == ct2 or ct2 == f.mtime)
finally:
f.remove()
def testListing(self):
d = path(self.tempdir)
self.assertEqual(d.listdir(), [])
f = 'testfile.txt'
af = d / f
self.assertEqual(af, os.path.join(d, f))
af.touch()
try:
self.assert_(af.exists())
self.assertEqual(d.listdir(), [af])
# .glob()
self.assertEqual(d.glob('testfile.txt'), [af])
self.assertEqual(d.glob('test*.txt'), [af])
self.assertEqual(d.glob('*.txt'), [af])
self.assertEqual(d.glob('*txt'), [af])
self.assertEqual(d.glob('*'), [af])
self.assertEqual(d.glob('*.html'), [])
self.assertEqual(d.glob('testfile'), [])
finally:
af.remove()
# Try a test with 20 files
files = [d / ('%d.txt' % i) for i in range(20)]
for f in files:
fobj = open(f, 'w')
fobj.write('some text\n')
fobj.close()
try:
files2 = d.listdir()
files.sort()
files2.sort()
self.assertEqual(files, files2)
finally:
for f in files:
try:
f.remove()
except:
pass
def testMakeDirs(self):
d = path(self.tempdir)
# Placeholder file so that when removedirs() is called,
# it doesn't remove the temporary directory itself.
tempf = d / 'temp.txt'
tempf.touch()
try:
foo = d / 'foo'
boz = foo / 'bar' / 'baz' / 'boz'
boz.makedirs()
try:
self.assert_(boz.isdir())
finally:
boz.removedirs()
self.failIf(foo.exists())
self.assert_(d.exists())
foo.mkdir(0750)
boz.makedirs(0700)
try:
self.assert_(boz.isdir())
finally:
boz.removedirs()
self.failIf(foo.exists())
self.assert_(d.exists())
finally:
os.remove(tempf)
def assertSetsEqual(self, a, b):
ad = {}
for i in a: ad[i] = None
bd = {}
for i in b: bd[i] = None
self.assertEqual(ad, bd)
def testShutil(self):
# Note: This only tests the methods exist and do roughly what
# they should, neglecting the details as they are shutil's
# responsibility.
d = path(self.tempdir)
testDir = d / 'testdir'
testFile = testDir / 'testfile.txt'
testA = testDir / 'A'
testCopy = testA / 'testcopy.txt'
testLink = testA / 'testlink.txt'
testB = testDir / 'B'
testC = testB / 'C'
testCopyOfLink = testC / testA.relpathto(testLink)
# Create test dirs and a file
testDir.mkdir()
testA.mkdir()
testB.mkdir()
f = open(testFile, 'w')
f.write('x' * 10000)
f.close()
# Test simple file copying.
testFile.copyfile(testCopy)
self.assert_(testCopy.isfile())
self.assert_(testFile.bytes() == testCopy.bytes())
# Test copying into a directory.
testCopy2 = testA / testFile.name
testFile.copy(testA)
self.assert_(testCopy2.isfile())
self.assert_(testFile.bytes() == testCopy2.bytes())
# Make a link for the next test to use.
if hasattr(os, 'symlink'):
testFile.symlink(testLink)
else:
testFile.copy(testLink) # fallback
# Test copying directory tree.
testA.copytree(testC)
self.assert_(testC.isdir())
self.assertSetsEqual(
testC.listdir(),
[testC / testCopy.name,
testC / testFile.name,
testCopyOfLink])
self.assert_(not testCopyOfLink.islink())
# Clean up for another try.
testC.rmtree()
self.assert_(not testC.exists())
# Copy again, preserving symlinks.
testA.copytree(testC, True)
self.assert_(testC.isdir())
self.assertSetsEqual(
testC.listdir(),
[testC / testCopy.name,
testC / testFile.name,
testCopyOfLink])
if hasattr(os, 'symlink'):
self.assert_(testCopyOfLink.islink())
self.assert_(testCopyOfLink.readlink() == testFile)
# Clean up.
testDir.rmtree()
self.assert_(not testDir.exists())
self.assertList(d.listdir(), [])
def assertList(self, listing, expected):
listing = list(listing)
listing.sort()
expected = list(expected)
expected.sort()
self.assertEqual(listing, expected)
def testPatterns(self):
d = path(self.tempdir)
names = ['x.tmp', 'x.xtmp', 'x2g', 'x22', 'x.txt']
dirs = [d, d/'xdir', d/'xdir.tmp', d/'xdir.tmp'/'xsubdir']
for e in dirs:
if not e.isdir(): e.makedirs()
for name in names:
(e/name).touch()
self.assertList(d.listdir('*.tmp'), [d/'x.tmp', d/'xdir.tmp'])
self.assertList(d.files('*.tmp'), [d/'x.tmp'])
self.assertList(d.dirs('*.tmp'), [d/'xdir.tmp'])
self.assertList(d.walk(), [e for e in dirs if e != d] + [e/n for e in dirs for n in names])
self.assertList(d.walk('*.tmp'),
[e/'x.tmp' for e in dirs] + [d/'xdir.tmp'])
self.assertList(d.walkfiles('*.tmp'), [e/'x.tmp' for e in dirs])
self.assertList(d.walkdirs('*.tmp'), [d/'xdir.tmp'])
def testUnicode(self):
d = path(self.tempdir)
p = d/'unicode.txt'
def test(enc):
""" Test that path works with the specified encoding,
which must be capable of representing the entire range of
Unicode codepoints.
"""
given = (u'Hello world\n'
u'\u0d0a\u0a0d\u0d15\u0a15\r\n'
u'\u0d0a\u0a0d\u0d15\u0a15\x85'
u'\u0d0a\u0a0d\u0d15\u0a15\u2028'
u'\r'
u'hanging')
clean = (u'Hello world\n'
u'\u0d0a\u0a0d\u0d15\u0a15\n'
u'\u0d0a\u0a0d\u0d15\u0a15\n'
u'\u0d0a\u0a0d\u0d15\u0a15\n'
u'\n'
u'hanging')
givenLines = [
u'Hello world\n',
u'\u0d0a\u0a0d\u0d15\u0a15\r\n',
u'\u0d0a\u0a0d\u0d15\u0a15\x85',
u'\u0d0a\u0a0d\u0d15\u0a15\u2028',
u'\r',
u'hanging']
expectedLines = [
u'Hello world\n',
u'\u0d0a\u0a0d\u0d15\u0a15\n',
u'\u0d0a\u0a0d\u0d15\u0a15\n',
u'\u0d0a\u0a0d\u0d15\u0a15\n',
u'\n',
u'hanging']
expectedLines2 = [
u'Hello world',
u'\u0d0a\u0a0d\u0d15\u0a15',
u'\u0d0a\u0a0d\u0d15\u0a15',
u'\u0d0a\u0a0d\u0d15\u0a15',
u'',
u'hanging']
# write bytes manually to file
f = codecs.open(p, 'w', enc)
f.write(given)
f.close()
# test all 3 path read-fully functions, including
# path.lines() in unicode mode.
self.assertEqual(p.bytes(), given.encode(enc))
self.assertEqual(p.text(enc), clean)
self.assertEqual(p.lines(enc), expectedLines)
self.assertEqual(p.lines(enc, retain=False), expectedLines2)
# If this is UTF-16, that's enough.
# The rest of these will unfortunately fail because append=True mode
# causes an extra BOM to be written in the middle of the file.
# UTF-16 is the only encoding that has this problem.
if enc == 'UTF-16':
return
# Write Unicode to file using path.write_text().
cleanNoHanging = clean + u'\n' # This test doesn't work with a hanging line.
p.write_text(cleanNoHanging, enc)
p.write_text(cleanNoHanging, enc, append=True)
# Check the result.
expectedBytes = 2 * cleanNoHanging.replace('\n', os.linesep).encode(enc)
expectedLinesNoHanging = expectedLines[:]
expectedLinesNoHanging[-1] += '\n'
self.assertEqual(p.bytes(), expectedBytes)
self.assertEqual(p.text(enc), 2 * cleanNoHanging)
self.assertEqual(p.lines(enc), 2 * expectedLinesNoHanging)
self.assertEqual(p.lines(enc, retain=False), 2 * expectedLines2)
# Write Unicode to file using path.write_lines().
# The output in the file should be exactly the same as last time.
p.write_lines(expectedLines, enc)
p.write_lines(expectedLines2, enc, append=True)
# Check the result.
self.assertEqual(p.bytes(), expectedBytes)
# Now: same test, but using various newline sequences.
# If linesep is being properly applied, these will be converted
# to the platform standard newline sequence.
p.write_lines(givenLines, enc)
p.write_lines(givenLines, enc, append=True)
# Check the result.
self.assertEqual(p.bytes(), expectedBytes)
# Same test, using newline sequences that are different
# from the platform default.
def testLinesep(eol):
p.write_lines(givenLines, enc, linesep=eol)
p.write_lines(givenLines, enc, linesep=eol, append=True)
expected = 2 * cleanNoHanging.replace(u'\n', eol).encode(enc)
self.assertEqual(p.bytes(), expected)
testLinesep(u'\n')
testLinesep(u'\r')
testLinesep(u'\r\n')
testLinesep(u'\x0d\x85')
# Again, but with linesep=None.
p.write_lines(givenLines, enc, linesep=None)
p.write_lines(givenLines, enc, linesep=None, append=True)
# Check the result.
expectedBytes = 2 * given.encode(enc)
self.assertEqual(p.bytes(), expectedBytes)
self.assertEqual(p.text(enc), 2 * clean)
expectedResultLines = expectedLines[:]
expectedResultLines[-1] += expectedLines[0]
expectedResultLines += expectedLines[1:]
self.assertEqual(p.lines(enc), expectedResultLines)
test('UTF-8')
test('UTF-16BE')
test('UTF-16LE')
test('UTF-16')
def testRmtreeP(self):
d = path(self.tempdir)
sub = d / 'subfolder'
sub.mkdir()
(sub / 'afile').write_text('something')
sub.rmtree_p()
self.assertFalse(sub.exists())
try:
sub.rmtree_p()
except OSError:
self.fail("Calling `rmtree_p` on non-existent directory "
"should not raise an exception.")
class SubclassTestCase(unittest.TestCase):
class PathSubclass(path):
pass
def test_subclass_produces_same_class(self):
"""
When operations are invoked on a subclass, they should produce another
instance of that subclass.
"""
p = self.PathSubclass('/foo')
subdir = p / 'bar'
assert isinstance(subdir, self.PathSubclass)
class TempDirTestCase(unittest.TestCase):
def test_constructor(self):
"""
One should be able to readily construct a temporary directory
"""
d = tempdir()
assert isinstance(d, path)
assert d.exists()
assert d.isdir()
d.rmdir()
assert not d.exists()
def test_next_class(self):
"""
It should be possible to invoke operations on a tempdir and get
path classes.
"""
d = tempdir()
sub = d / 'subdir'
assert isinstance(sub, path)
d.rmdir()
def test_context_manager(self):
"""
One should be able to use a tempdir object as a context, which will
clean up the contents after.
"""
d = tempdir()
res = d.__enter__()
assert res is d
(d / 'somefile.txt').touch()
assert not isinstance(d / 'somefile.txt', tempdir)
d.__exit__(None, None, None)
assert not d.exists()
def test_context_manager_exception(self):
"""
The context manager will not clean up if an exception occurs.
"""
d = tempdir()
d.__enter__()
(d / 'somefile.txt').touch()
assert not isinstance(d / 'somefile.txt', tempdir)
d.__exit__(TypeError, TypeError('foo'), None)
assert d.exists()
def test_context_manager_using_with(self):
"""
The context manager will allow using the with keyword and
provide a temporry directory that will be deleted after that.
"""
with tempdir() as d:
self.assertTrue(d.isdir())
self.assertFalse(d.isdir())
if __name__ == '__main__':
unittest.main()