def __init__(self, target, *args, parent_context, **kwargs):
     super().__init__(target=target, **kwargs)
     self.exception_caught = None
     self.value_returned = None
     self.fake_datetime = FakeDatetime()
     self._context = parent_context.spawn()
     self._target = target
Exemple #2
0
 def setUp(self):
     self.context = open_dependency_context()
     self.fake_time = FakeDatetime()
     self.context.inject(datetime, self.fake_time)
     self.results = None
     EventBroker.subscribe(event=TestEvent.suite_results_compiled,
                           func=self.capture_results)
     self.sut = ResultCompiler()
     self.sut.activate()
Exemple #3
0
    def test_does_not_affect_origin_context(self):
        keep_running = True

        def forrest():
            while keep_running:
                sleep(0.001)

        with dependency_context() as context:
            original_context_time = datetime.fromtimestamp(2)
            context_dt = FakeDatetime(fixed_time=original_context_time)
            context.inject(datetime, context_dt)
            tc = context.create_time_controller(target=forrest)
            tc.start()
            sleep(0.01)
            expect(dependency(datetime).now()).to(equal(original_context_time))
        keep_running = False
        tc.join()
Exemple #4
0
 def test_sets_fixed_time_if_none_specified(self):
     expect(FakeDatetime().fixed_time).to(be_a(datetime))
Exemple #5
0
 def test_delegates_calls_to_datetime(self):
     expect(FakeDatetime().__call__).to(equal(datetime))
Exemple #6
0
 def test_can_advance_by_arbitrary_days(self):
     fake = FakeDatetime()
     days = 8
     start = fake.now()
     fake.advance(days=days)
     expect(fake.now()).to(equal(start + timedelta(days=days)))
Exemple #7
0
 def test_can_advance_by_arbitrary_hours(self):
     fake = FakeDatetime()
     hours = 23
     start = fake.now()
     fake.advance(hours=hours)
     expect(fake.now()).to(equal(start + timedelta(hours=hours)))
Exemple #8
0
 def test_can_advance_by_arbitrary_minutes(self):
     fake = FakeDatetime()
     mins = 4
     start = fake.now()
     fake.advance(minutes=mins)
     expect(fake.now()).to(equal(start + timedelta(minutes=mins)))
Exemple #9
0
 def test_can_advance_by_arbitrary_sec(self):
     fake = FakeDatetime()
     sec = 235
     start = fake.now()
     fake.advance(seconds=sec)
     expect(fake.now()).to(equal(start + timedelta(seconds=sec)))
Exemple #10
0
 def test_can_advance_by_arbitrary_ms(self):
     fake = FakeDatetime()
     ms = 235
     start = fake.now()
     fake.advance(milliseconds=ms)
     expect(fake.now()).to(equal(start + timedelta(milliseconds=ms)))
Exemple #11
0
 def test_passes_other_dt_attributes_through(self):
     fake = FakeDatetime()
     for attr in dir(datetime):
         if not (attr.startswith("_") or attr in ("now", "utcnow")):
             assert getattr(fake, attr) == getattr(
                 datetime, attr), f"{attr} did not pass through"
Exemple #12
0
 def test_utcnow_returns_fixed_time(self):
     now = datetime.now()
     expect(FakeDatetime(fixed_time=now).utcnow()).to(equal(now))
Exemple #13
0
 def test_can_specify_fixed_time(self):
     now = datetime.now()
     expect(FakeDatetime(fixed_time=now).fixed_time).to(equal(now))
Exemple #14
0
 def test_passes_other_dt_attributes_through(self):
     fake = FakeDatetime()
     for attr in dir(datetime):
         if not (attr.startswith('_') or attr in ('now', 'utcnow')):
             assert getattr(fake, attr) == getattr(datetime, attr), \
                 f'{attr} did not pass through'