Georges Racinet avatar Georges Racinet committed 39aa259

Initial version. Chead README and TODO

Comments (0)

Files changed (10)

+
+
+Version 0.1 : initial version
+include *.txt
+A module to allow playing with time in tests.
+
+Before anythin, do::
+
+   >>> import anybox.testing.datetime
+
+Then you can::
+
+   >>> from datetime import datetime
+   >>> datetime.set_now(datetime(2001, 01, 01, 3, 57, 00)
+   >>> datetime.now()
+   datetime(2001, 01, 01, 3, 57, 00)
+
+Don't forget afterwards to::
+
+   >>> datetime.real_now()
+
+Otherwise many pieces of code might get very suprised if the
+system clock looks as if it's frozen.
+ - patch time.time() as well in a consistent manner
+ - hook the README as a doctest

anybox/__init__.py

+# See http://peak.telecommunity.com/DevCenter/setuptools#namespace-packages
+try:
+    __import__('pkg_resources').declare_namespace(__name__)
+except ImportError:
+    from pkgutil import extend_path
+    __path__ = extend_path(__path__, __name__)

anybox/testing/__init__.py

+# See http://peak.telecommunity.com/DevCenter/setuptools#namespace-packages
+try:
+    __import__('pkg_resources').declare_namespace(__name__)
+except ImportError:
+    from pkgutil import extend_path
+    __path__ = extend_path(__path__, __name__)

anybox/testing/datetime/__init__.py

+import sys
+import mock_dt
+
+sys.modules['datetime'] = mock_dt

anybox/testing/datetime/mock_dt.py

+import sys
+from datetime import *
+from datetime import datetime as original_datetime
+
+class datetime(original_datetime):
+
+    _current_now = None
+
+    @classmethod
+    def now(cls):
+        now = cls._current_now
+        if now is not None:
+            return cls._current_now
+        return original_datetime.now() # TODO adjust class
+
+    @classmethod
+    def set_now(cls, value):
+        """Change the value of now.
+
+        On may give None as a value to get back to system clock."""
+        cls._current_now = value
+
+    @classmethod
+    def real_now(cls):
+        """Get back to the real meaning of now.
+
+        This should be used once the test needing to play with current
+        date/time is over. Lots of other tests may fail if on a frozen value
+        of 'now'.
+        """
+        cls.set_now(None)
+[egg_info]
+tag_date = 0
+from setuptools import setup, find_packages
+
+version = 0.1
+
+setup(
+    name = "anybox.testing.datetime",
+    version = version,
+    author="Georges Racinet",
+    author_email="gracinet@anybox.fr",
+    description="Various utilities related to date and time for testing purposes.",
+    license="GPLv3",
+    long_description=open('README.txt').read() + open('CHANGES.txt').read(),
+    url="",
+    packages=find_packages(),
+    zip_safe=False,
+    include_package_data=True,
+    namespace_packages=['anybox', 'anybox.testing'],
+    install_requires=['setuptools',],
+    classifiers=[
+      ],
+    entry_points = {},
+    )
+
+
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.