3 from wizard import tests
4 from wizard.util import *
6 lockfile = tests.getTestFile("util_test.lock")
8 class MyError(Exception):
15 class MyErrorWithHTML(Exception):
22 <title>No good!</title>
27 assert dictmap(lambda x: x + 1, {'a': 0, 'b': 1}) == {'a': 1, 'b': 2}
29 def test_get_dir_uid():
30 if os.getuid(): return # only run if on a scripts server. This is crude
31 assert get_dir_uid("/mit/ezyang/web_scripts/test-wiki") == 537864399
33 def test_get_dir_uid_locker():
34 if os.getuid(): return
35 assert get_dir_uid("/mit/apo/web_scripts/") == 536956980
37 def test_get_exception_name():
39 raise NotImplementedError
40 except NotImplementedError:
41 assert get_exception_name(traceback.format_exc()) == "NotImplementedError"
43 def test_get_exception_name_withstr():
47 assert get_exception_name(traceback.format_exc()) == "MyError"
49 def test_get_exception_name_withhtml():
52 except MyErrorWithHTML:
53 assert get_exception_name(traceback.format_exc()) == "MyErrorWithHTML"
55 def test_get_exception_name_withstr2():
57 raise Exception("This is extra info we don't care about");
59 assert get_exception_name(traceback.format_exc()) == "Exception"
63 with LockDirectory(lockfile):
68 with LockDirectory(lockfile):
70 with LockDirectory(lockfile):
72 except DirectoryLockedError:
75 def test_break_orphan_lock():
77 open(lockfile, "w").write("obviouslyboguspid")
78 with LockDirectory(lockfile):
81 def test_break_stale_lock():
83 with LockDirectory(lockfile):
84 with LockDirectory(lockfile, expiry = 0):