X-Git-Url: https://scripts.mit.edu/gitweb/wizard.git/blobdiff_plain/b29d182f610f68dcdc9525e08d5ad4fab65ffaa4..5b428fce4566ed627ad61f204935aaa8bc367932:/wizard/tests/util_test.py diff --git a/wizard/tests/util_test.py b/wizard/tests/util_test.py index a328cd1..cd444e0 100644 --- a/wizard/tests/util_test.py +++ b/wizard/tests/util_test.py @@ -1,7 +1,10 @@ import traceback +from wizard import tests from wizard.util import * +lockfile = tests.getTestFile("util_test.lock") + class MyError(Exception): def __str__(self): return """ @@ -23,14 +26,6 @@ ERROR: Bar def test_dictmap(): assert dictmap(lambda x: x + 1, {'a': 0, 'b': 1}) == {'a': 1, 'b': 2} -def test_get_dir_uid(): - if os.getuid(): return # only run if on a scripts server. This is crude - assert get_dir_uid("/mit/ezyang/web_scripts/test-wiki") == 537864399 - -def test_get_dir_uid_locker(): - if os.getuid(): return - assert get_dir_uid("/mit/apo/web_scripts/") == 536956980 - def test_get_exception_name(): try: raise NotImplementedError @@ -54,3 +49,32 @@ def test_get_exception_name_withstr2(): raise Exception("This is extra info we don't care about"); except Exception: assert get_exception_name(traceback.format_exc()) == "Exception" + +def test_lock(): + soft_unlink(lockfile) + with LockDirectory(lockfile): + pass + +def test_locked(): + soft_unlink(lockfile) + with LockDirectory(lockfile): + try: + with LockDirectory(lockfile): + assert False + except DirectoryLockedError: + pass + +def test_break_orphan_lock(): + soft_unlink(lockfile) + open(lockfile, "w").write("obviouslyboguspid") + with LockDirectory(lockfile): + pass + +def test_break_stale_lock(): + soft_unlink(lockfile) + with LockDirectory(lockfile): + with LockDirectory(lockfile, expiry = 0): + pass + +def test_disk_usage(): + assert disk_usage(tests.getTestFile("disk_usage_test"), "ignore_me") == 7