Repository: closeio/freezefrog

Issue:
FreezeFrog should also mock datetime.datetime.now
FreezeFrog should raise an exception when datetime.datetime.now() is used without a TZ instead of not mocking it at all.


Discussion:

Patch:
diff --git a/freezefrog/__init__.py b/freezefrog/__init__.py
index 44a232a..60463f3 100644
--- a/freezefrog/__init__.py
+++ b/freezefrog/__init__.py
@@ -47,6 +47,12 @@ class FakeDateTime(with_metaclass(FakeDateTimeMeta, real_datetime)):
             cls._start = real_datetime.utcnow()
         return (real_datetime.utcnow() - cls._start) + cls.dt
 
+    @classmethod
+    def now(cls, *args, **kwargs):
+        raise NotImplementedError(
+            '{}.now() is not implemented yet'.format(cls.__name__)
+        )
+
 
 class FakeFixedDateTime(FakeDateTime):
     @classmethod


Test patch:
diff --git a/tests/__init__.py b/tests/__init__.py
index dd74be2..093fc1c 100644
--- a/tests/__init__.py
+++ b/tests/__init__.py
@@ -27,3 +27,9 @@ class FreezeFrogTestCase(unittest.TestCase):
             end = datetime.datetime(2014, 1, 1, 0, 0, 1)
             self.assertTrue(start < dt < end)
             self.assertTrue(1388534400 < time.time() < 1388534401)
+
+    def test_now(self):
+        regular_now = datetime.datetime.now()
+        self.assertTrue(regular_now)
+        with FreezeTime(datetime.datetime(2014, 1, 1)):
+            self.assertRaises(NotImplementedError, datetime.datetime.now)