def test_pops_top_layer_off_the_stack(self):
     bottom_canary = Canary()
     top_canary = Canary()
     bottom_context = open_dependency_context()
     bottom_context.inject(Canary, SingletonClass(bottom_canary))
     top_context = open_dependency_context()
     top_context.inject(Canary, SingletonClass(top_canary))
     top_context.close()
     touch_a_canary()
     bottom_context.close()
     expect(bottom_canary.touched).to(be_true)
 def test_uses_object_injected_at_top_of_stack(self):
     bottom_canary = Canary()
     top_canary = Canary()
     bottom_context = open_dependency_context()
     bottom_context.inject(Canary, SingletonClass(bottom_canary))
     top_context = open_dependency_context()
     top_context.inject(Canary, SingletonClass(top_canary))
     touch_a_canary()
     top_context.close()
     expect(top_canary.touched).to(be_true)
     bottom_context.close()
 def test_popped_layer_is_no_longer_used(self):
     bottom_canary = Canary()
     top_canary = Canary()
     bottom_context = open_dependency_context()
     bottom_context.inject(Canary, SingletonClass(bottom_canary))
     top_context = open_dependency_context()
     top_context.inject(Canary, SingletonClass(top_canary))
     top_context.close()
     touch_a_canary()
     bottom_context.close()
     expect(top_canary.touched).to(be_false)
 def test_does_not_use_object_injected_lower_in_stack(self):
     bottom_canary = Canary()
     top_canary = Canary()
     bottom_context = open_dependency_context()
     bottom_context.inject(Canary, SingletonClass(bottom_canary))
     top_context = open_dependency_context()
     top_context.inject(Canary, SingletonClass(top_canary))
     touch_a_canary()
     top_context.close()
     bottom_context.close()
     expect(bottom_canary.touched).to(be_false)
Beispiel #5
0
 def test_reflects_changes_to_parent(self):
     real_spam = 'real spam'
     fake_1 = 'first injection'
     fake_2 = 'second injection'
     try:
         parent = open_dependency_context()
         parent.inject(real_spam, fake_1)
         child = open_dependency_context(parent=parent)
         parent.inject(real_spam, fake_2)
         expect(dependency(real_spam)).to(equal(fake_2))
     finally:
         child.close()
         parent.close()
Beispiel #6
0
 def test_recursion(self):
     spam = 'SPAM'
     fake_spam = 'Advanced SPAM Substitute'
     one = open_dependency_context()
     one.inject(spam, fake_spam)
     two = open_dependency_context(parent=one)
     three = open_dependency_context(parent=two)
     try:
         expect(dependency(spam)).to(equal(fake_spam))
     finally:
         three.close()
         two.close()
         one.close()
Beispiel #7
0
 def setUp(self):
     self.context = open_dependency_context(supply_fs=True,
                                            supply_logging=True)
     self.context.inject(StreamHandler, EmptyFake())
     EventBroker.reset()
     subscribe_event_handlers(self)
     self.skip_events = 0
Beispiel #8
0
 def setUp(self):
     disable_default_reporters()
     self.context = open_dependency_context()
     self.fake_broker = FakeBroker()
     self.context.inject(EventBroker, self.fake_broker)
     self.fake_log = FakeLog()
     self.context.inject(logger_for_module, lambda m: self.fake_log)
Beispiel #9
0
 def setUp(self):
     close_all_dependency_contexts()
     disable_default_reporters()
     self.context = open_dependency_context(supply_fs=True)
     self.fake_logging = FakeLogging()
     self.context.inject(logging, self.fake_logging)
     EventBroker.reset()
 def setUp(self):
     self.context = open_dependency_context(supply_env=True,
                                            supply_logging=True)
     self.get_spy = FunctionSpy(return_value=EndlessFake())
     self.requests_stub = EndlessFake(pattern_obj=requests)
     self.requests_stub.get = self.get_spy
     self.context.inject(requests, self.requests_stub)
Beispiel #11
0
 def setUp(self):
     EventBroker.reset()
     self.context = open_dependency_context()
     self.fake_now = datetime.fromtimestamp(1515429469.61845)
     self.fake_datetime_module = EmptyFake()
     self.fake_datetime_module.now = lambda: self.fake_now
     self.context.inject(datetime, self.fake_datetime_module)
 def test_simple_injection(self):
     my_canary = Canary()
     context = open_dependency_context()
     context.inject(Canary, SingletonClass(my_canary))
     touch_a_canary()
     context.close()
     expect(my_canary.touched).to(be_true)
Beispiel #13
0
 def setUp(self):
     self.reports_path = "somewhere/over/the/rainbow"
     self.context = open_dependency_context()
     self.files = fakefs.FakeFilesystem()
     self.fake_open = fakefs.FakeFileOpen(self.files)
     self.fake_os = fakefs.FakeOsModule(self.files)
     self.context.inject(open, self.fake_open)
     self.context.inject(os.walk, fakefs.FakeOsModule(self.files).walk)
Beispiel #14
0
 def setUp(self):
     EventBroker.reset()
     self.published = None
     self.context = open_dependency_context()
     self.fake_requests = FakeRequests()
     self.context.inject(requests, self.fake_requests)
     EventBroker.subscribe(event=TestEvent.artifact_created,
                           func=self.on_artifact_created)
Beispiel #15
0
 def setUp(self):
     self.context = open_dependency_context()
     requests_stub = EndlessFake(pattern_obj=requests)
     session_stub = EndlessFake(pattern_obj=requests.sessions.Session())
     self.send_spy = FunctionSpy(return_value=EndlessFake())
     session_stub.send = self.send_spy
     requests_stub.Session = lambda *a, **k: session_stub
     self.context.inject(requests, requests_stub)
Beispiel #16
0
 def setUp(self):
     self.context = open_dependency_context(supply_env=True, supply_fs=True)
     self.context.inject(webdriver, EndlessFake())
     self.fake_tunnel_class = MasterSpy(EndlessFake())
     self.context.inject(BrowserStackTunnel, self.fake_tunnel_class)
     self.context.set_env(browserstack_access_key="whatever",
                          browserstack_url="gopher:hahah",
                          browserstack_username="******")
 def setUp(self):
     self.context = open_dependency_context(supply_env=True)
     fake_webdriver = FakeWebdriver()
     self.context.inject(webdriver, fake_webdriver)
     self.events_captured = []
     EventBroker.subscribe(event=TestEvent.artifact_created,
                           func=self.capture_event)
     self.sut = Browser()
Beispiel #18
0
 def setUp(self):
     self.context = open_dependency_context(supply_env=True)
     self.http_proxy = "http://munchausen-gateway:4427"
     self.https_proxy = "http://special-something:7727"
     self.context.os.environ = {"HTTP_PROXY": self.http_proxy, "HTTPS_PROXY": self.https_proxy}
     self.session_spy = MasterSpy(FakeRequests())
     self.requests_spy = MasterSpy(FakeRequests(self.session_spy))
     self.context.inject(requests, self.requests_spy)
Beispiel #19
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()
Beispiel #20
0
 def setUp(self):
     self.context = open_dependency_context()
     self.spies = MutableObject()
     requests_stub = EndlessFake(pattern_obj=requests)
     for method in ("get", "post", "put", "delete", "head"):
         fake = FakeRequestsMethod()
         setattr(self.spies, method, fake)
         setattr(requests_stub, method, fake)
     self.context.inject(requests, requests_stub)
Beispiel #21
0
 def setUp(self):
     EventBroker.reset()
     self.context = open_dependency_context(supply_env=True, supply_fs=True)
     self.fake_file = FakeFile()
     self.context.inject(open, self.fake_file.open)
     self.makedirs_spy = MasterSpy(self.context.os.makedirs)
     self.context.os.makedirs = self.makedirs_spy
     self.sut = ArtifactSaver()
     self.sut.activate()
Beispiel #22
0
 def setUp(self):
     EventBroker.reset()
     EventBroker.subscribe(event=TestEvent.artifact_created,
                           func=self.catch_artifact_event)
     self.context = open_dependency_context(supply_env=True, supply_fs=True)
     self.fake_webdriver = FakeWebdriver()
     self.context.inject(webdriver, self.fake_webdriver)
     self.sut = Browser()
     self.artifact_events = []
 def setUp(self):
     self.context = open_dependency_context(supply_fs=True,
                                            supply_env=True,
                                            supply_logging=True)
     self.context.set_env(
         DELAY_BETWEEN_CHECKS_FOR_PARALLEL_SUITE_COMPLETION=0,
         MAX_PARALLEL_SUITES=5)
     self.popen_class = FakePopenClass()
     self.context.inject(Popen, self.popen_class)
 def test_injection_does_not_affect_another_thread(self):
     my_canary = Canary()
     context = open_dependency_context()
     context.inject(Canary, SingletonClass(my_canary))
     t = Thread(target=touch_a_canary)
     t.start()
     t.join()
     context.close()
     expect(my_canary.touched).to(be_false)
 def setUp(self):
     self.context = open_dependency_context(supply_env=True,
                                            supply_fs=True,
                                            supply_logging=True)
     self.context.set_env(
         DELAY_BETWEEN_CHECKS_FOR_PARALLEL_SUITE_COMPLETION=0)
     self.fake_process = EmptyFake()
     self.context.inject_as_class(Popen, self.fake_process)
     self.pretend_process_is_running()
 def setUp(self):
     self.context = open_dependency_context(supply_env=True)
     EventBroker.reset()
     EventBroker.subscribe(event=TestEvent.artifact_created, func=self.catch_artifact_event)
     self.artifact_events_caught = []
     self.fake_webdriver = FakeWebdriver()
     self.context.inject(webdriver, self.fake_webdriver)
     self.fake_dump = "yaddayaddayadda"
     self.context.inject(dump_dom, lambda x: self.fake_dump)
     self.sut = Browser()
 def setUp(self):
     self.context = open_dependency_context(supply_env=True,
                                            supply_logging=True)
     self.fake_http_client = EndlessFake()
     self.fake_requests_response = requests.Response()
     self.fake_requests_response.json = lambda: {}
     self.post_spy = FunctionSpy(return_value=self.fake_requests_response)
     self.fake_http_client.post = self.post_spy
     self.graph_client = GraphqlClient(http_client=self.fake_http_client,
                                       url="ignore me")
 def setUp(self):
     EventBroker.reset()
     self.context = open_dependency_context(supply_env=True)
     defanged = copy(junit_xml.TestSuite)
     defanged.to_xml_string = lambda *args, **kwargs: ""
     self.spy = MasterSpy(defanged, affect_only_functions=False)
     self.context.inject(junit_xml.TestSuite, self.spy)
     self.results = SuiteResults()
     self.sut = JunitReporter()
     self.sut.activate()
 def setUp(self):
     self.context = open_dependency_context(supply_env=True, supply_fs=True)
     self.context.set_env(BROWSERSTACK_ACCESS_KEY="fake")
     # Prevent real network activity
     self.context.inject_as_class(HttpClient, HttpStub())
     self.context.set_env(BROWSER_ACCESS_KEY="spam")
     self.popen_spy = MasterSpy(PopenStub())
     self.context.inject_as_class(Popen, self.popen_spy)
     # Thwart actual sleeping
     self.context.inject(time.sleep, lambda n: None)
     self.tunnel = BrowserStackTunnel()
 def setUp(self):
     EventBroker.reset()
     self.context = open_dependency_context(supply_env=True,
                                            supply_logging=True)
     EventBroker.reset()
     boto_stub = BotoStub()
     self.put_spy = boto_stub.s3_put_object_spy
     self.context.inject(boto3, boto_stub)
     self.context.set_env(S3_BUCKET_FOR_ARTIFACTS="something")
     self.sut = S3ArtifactSaver()
     self.sut.activate()