diff options
author | Eli Collins <elic@assurancetechnologies.com> | 2012-06-27 14:47:30 -0400 |
---|---|---|
committer | Eli Collins <elic@assurancetechnologies.com> | 2012-06-27 14:47:30 -0400 |
commit | 9240ba7bdc000be61a7a1d4cea8df1866e19bfd4 (patch) | |
tree | b27f7886b4dd3eb42662f4abbd70d33275105334 | |
parent | 18128955b572a858bd1559b2568aba3fd8e93d69 (diff) | |
download | passlib-9240ba7bdc000be61a7a1d4cea8df1866e19bfd4.tar.gz |
replaced HAS_INTEGER_MTIME flag with more reliable workaround
-rw-r--r-- | CHANGES | 3 | ||||
-rw-r--r-- | passlib/tests/test_apache.py | 6 | ||||
-rw-r--r-- | passlib/tests/utils.py | 10 |
3 files changed, 15 insertions, 4 deletions
@@ -12,6 +12,9 @@ Release History * FreeBSD 8.3+ has native support for SHA512-Crypt, updated unittests and documentation accordingly (:issue:`35`) + * Fixed bug in passlib.apache unittest which caused test to fail + if filesystem had mtime resolution >= 1 second (:issue:`35`). + **1.6** (2012-05-01) ==================== diff --git a/passlib/tests/test_apache.py b/passlib/tests/test_apache.py index 5023903..e2122ae 100644 --- a/passlib/tests/test_apache.py +++ b/passlib/tests/test_apache.py @@ -12,7 +12,7 @@ import time #pkg from passlib import apache from passlib.utils.compat import irange, unicode -from passlib.tests.utils import TestCase, get_file, set_file, catch_warnings, HAS_INTEGER_MTIME +from passlib.tests.utils import TestCase, get_file, set_file, catch_warnings, ensure_mtime_changed from passlib.utils.compat import b, bytes, u #module log = getLogger(__name__) @@ -473,8 +473,8 @@ class HtdigestFileTest(TestCase): hc.load(path) self.assertEqual(hc.to_string(), self.sample_01) - #change file, test deprecated force=True kwd - time.sleep(1 if HAS_INTEGER_MTIME else .1) # pause so mtime changes + #change file, test deprecated force=False kwd + ensure_mtime_changed(path) set_file(path, "") with self.assertWarningList(r"load\(force=False\) is deprecated"): ha.load(force=False) diff --git a/passlib/tests/utils.py b/passlib/tests/utils.py index 38c7a0b..ffce80a 100644 --- a/passlib/tests/utils.py +++ b/passlib/tests/utils.py @@ -9,6 +9,7 @@ import re import os import sys import tempfile +import time from passlib.exc import PasslibHashWarning from passlib.utils.compat import PY27, PY_MIN_32, PY3, JYTHON import warnings @@ -48,7 +49,14 @@ except ImportError: else: GAE = True -HAS_INTEGER_MTIME = JYTHON or sys.platform.startswith("darwin") +def ensure_mtime_changed(path): + "ensure file's mtime has changed" + # NOTE: this is hack to deal w/ filesystems whose mtime resolution is >= 1s, + # when a test needs to be sure the mtime changed after writing to the file. + last = os.path.getmtime(path) + while os.path.getmtime(path) == last: + time.sleep(0.1) + os.utime(path, None) def _get_timer_resolution(timer): def sample(): |