]> scripts.mit.edu Git - wizard.git/blobdiff - wizard/tests/util_test.py
Fix bug where php.ini not being rewritten for MediaWiki.
[wizard.git] / wizard / tests / util_test.py
index c34abba73f4b7bc8ea3ac178dd5c616226b6a28a..cd444e02e392b85a3d6fb5ba2970f18a8dc3ea41 100644 (file)
@@ -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 """
@@ -9,13 +12,19 @@ class MyError(Exception):
 ERROR: Foo
 """
 
-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
+class MyErrorWithHTML(Exception):
+    def __str__(self):
+        return """
 
-def test_get_dir_uid_locker():
-    if os.getuid(): return
-    assert get_dir_uid("/mit/apo/web_scripts/") == 536956980
+ERROR: Bar
+
+<html>
+    <title>No good!</title>
+</html>
+"""
+
+def test_dictmap():
+    assert dictmap(lambda x: x + 1, {'a': 0, 'b': 1}) == {'a': 1, 'b': 2}
 
 def test_get_exception_name():
     try:
@@ -29,3 +38,43 @@ def test_get_exception_name_withstr():
     except MyError:
         assert get_exception_name(traceback.format_exc()) == "MyError"
 
+def test_get_exception_name_withhtml():
+    try:
+        raise MyErrorWithHTML
+    except MyErrorWithHTML:
+        assert get_exception_name(traceback.format_exc()) == "MyErrorWithHTML"
+
+def test_get_exception_name_withstr2():
+    try:
+        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