Beispiel #1
0
 def test_no_assertion(self):
     class Test(object):
         kanga = Inject("Kanga", cache=False)
     Inject.register_feature("Kanga", "They steal your youth!")
     result = Test().kanga
     self.assertTrue(result)
     self.assertEqual(result, "They steal your youth!")
Beispiel #2
0
 def test_assertionerror_is_raised_if_assertion_fails(self):
     class Test(object):
         kanga = Inject("Kanga", lambda f: isinstance(f, int), cache=False)
     Inject.register_feature("Kanga", "Roo")
     try:
         Test().kanga
         self.fail()
     except AssertionError as error:
         self.assertEqual(str(error), "The value=[%s] of feature=[%s] does not match a criteria"
                          % ("Roo", "Kanga"))
 def setUp(self):
     Inject.reset()
     self.startMock = CallableMock()
     threading_mock.Thread.reset(returns=Any(daemon=False, start=self.startMock))
     Inject.register_feature("threading", threading_mock)
     Inject.register_feature("config_service", config_mock)
     Inject.register_feature("queue", lambda: queue_mock)
     Inject.register_feature("log_service", log_service_mock)
Beispiel #4
0
    def test_factory_method(self):
        class Test(object):
            kanga = Inject("Kanga", lambda f: isinstance(f, str), cache=False)

        class TestKangaFactory(object):
            id = 0

            def __call__(self):
                TestKangaFactory.id += 1
                return "#%s" % TestKangaFactory.id

        Inject.register_feature("Kanga", TestKangaFactory())
        result1 = Test().kanga
        result2 = Test().kanga
        self.assertNotEqual(result1, result2)
Beispiel #5
0
 def setUp(self):
     self.log_service = Any(debug=CallableMock(), error=CallableMock())
     self.crawl_result = Any(link="",
                             status_code=200,
                             page_size=0,
                             links=[])
     self.parser = Any(parse=CallableMock(returns=self.crawl_result))
     self.crawler = Any(
         status=Any(urls_in_progress=[],
                    urls_to_crawl=[],
                    visited_urls=set()),
         site_parser_factory=CallableMock(returns=self.parser),
         process_links=CallableMock(),
         get_status_message=CallableMock())
     Inject.reset()
     Inject.register_feature('log_service', self.log_service)
Beispiel #6
0
 def setUp(self):
     Inject.reset()
     Inject.register_feature('site_parser_factory',
                             lambda: Any(parse=CallableMock()))
     Inject.register_feature(
         'log_service',
         Any(info=CallableMock(),
             error=CallableMock(),
             debug=CallableMock()))
     Inject.register_feature(
         'work_service',
         Any(request_work=CallableMock(callback=lambda cb: cb()),
             terminate_all=CallableMock(),
             active_count=CallableMock))
 def setUp(self):
     super(WorkerService_request_work_Tests, self).setUp()
     Inject.register_feature("queue", Queue.Queue)
     Inject.register_feature("threading", threading)
Beispiel #8
0
 def setUp(self):
     Inject.reset()
     Inject.register_feature("site_parser_factory", site_parser_factory)
     Inject.register_feature("config_service", config)
     Inject.register_feature("log_service", log)
     Inject.register_feature("work_service", work_service)
Beispiel #9
0
 def setUp(self):
     Inject.reset()
     Inject.register_feature("requests", requests)
     Inject.register_feature("log_service", log_service)
Beispiel #10
0
 def test_positive_assertion_is_silent(self):
     class Test(object):
         kanga = Inject("Kanga", lambda f: isinstance(f, int), lambda f: f % 5 == 0, cache=False)
     Inject.register_feature("Kanga", 5)
     result = Test().kanga
     self.assertEqual(result, 5)