Esempio n. 1
0
def a_backend() -> MessagingBackend:
    backend = Spy(MessagingBackend)

    with backend:
        backend.get_queue(ANY_ARG).returns({})

    return cast(MessagingBackend, backend)
def dw_instances(monkeypatch):
    import datadotworld
    with Spy(DataDotWorld) as dw, Spy(DataDotWorld) as dw_alternative:
        dw.api_client = dw_alternative.api_client = Stub(RestApiClient)
        monkeypatch.setattr(
            datadotworld, '_get_instance', lambda profile: dw
            if profile == 'default' else dw_alternative)
        return {'default': dw, 'alternative': dw_alternative}
Esempio n. 3
0
    def test_any_arg_checking_works_when_eq_raises(self):
        with Spy(Collaborator) as spy:
            spy.method_accepting_property(ANY_ARG).returns(6)

        assert_that(spy.method_accepting_property(RaisingEq()), is_(6))
        assert_that(spy.method_accepting_property,
                    called().with_args(instance_of(RaisingEq)))
Esempio n. 4
0
def test_url_without_alias():
    with Spy(FilerImage) as filer_image:
        filer_image.url.returns('dummy.url')

    res = FilerImageAdapter().url(filer_image)
    assert_that(filer_image, property_got('url'))
    assert res == 'dummy.url'
Esempio n. 5
0
 def search_api(self):
     with Spy(SearchApi) as api:
         api.search_resources_advanced = \
             lambda b: PaginatedSearchResultsDto(
                 count=1,
                 records=[])
         return api
Esempio n. 6
0
    def test_load_4x4_operands_in_2x2_processors(self):
        nprocs = 4

        # given
        A = M4(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16)

        B = M4(17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32)

        procs = [Spy(Cannon.Processor) for i in range(nprocs)]
        frontend = FrontendI(procs)

        # when
        frontend.load_processors(A, B)

        # then
        A_blocks = [
            M2(1, 2, 5, 6),
            M2(3, 4, 7, 8),
            M2(11, 12, 15, 16),
            M2(9, 10, 13, 14)
        ]

        B_blocks = [
            M2(17, 18, 21, 22),
            M2(27, 28, 31, 32),
            M2(25, 26, 29, 30),
            M2(19, 20, 23, 24)
        ]

        for i in range(nprocs):
            assert_that(procs[i].injectA, called().with_args(A_blocks[i], 0))
            assert_that(procs[i].injectB, called().with_args(B_blocks[i], 0))
Esempio n. 7
0
 def queries_api(self, query_resp):
     with Spy(QueriesApi) as api:
         api.sparql_post = \
             lambda o, d, q, queries_api_mock, _preload_content: query_resp
         api.sql_post = \
             lambda o, d, q, queries_api_mock, _preload_content: query_resp
         return api
Esempio n. 8
0
def test_retina_downscale(get_thumbnailer_mock):
    with Spy(FilerImage) as filer_image:
        filer_image.width.returns(300)
        filer_image.height.returns(300)
        filer_image.url.returns('dummy-original')

    # Mock the get_thumbnailer() function call and make it return our mocked Thumbnailer instance
    thumbnail_mock = MagicMock(name='Thumbnail')
    thumbnail_mock.url = 'dummy-generated'

    thumbnailer_mock = MagicMock(name='Thumbnailer')
    thumbnailer_mock.__getitem__.return_value = filer_image
    thumbnailer_mock.get_thumbnail.return_value = thumbnail_mock
    get_thumbnailer_mock.return_value = thumbnailer_mock

    result = FilerImageAdapter().retina_downscale(filer_image, density=3)
    assert result == ['dummy-generated', 'dummy-generated', 'dummy-original']
    thumbnailer_mock.get_thumbnail.assert_has_calls(
        [call({'size': (100, 100)}),
         call({'size': (200, 200)})], )
    thumbnailer_mock.reset_mock()

    result = FilerImageAdapter().retina_downscale(filer_image, density=4)
    assert result == [
        'dummy-generated', 'dummy-generated', 'dummy-generated',
        'dummy-original'
    ]
    thumbnailer_mock.get_thumbnail.assert_has_calls(
        [call({'size': (75, 75)}),
         call({'size': (150, 150)})],
        call({'size': (225, 225)}),
    )
Esempio n. 9
0
 def user_api(self):
     with Spy(UserApi) as api:
         api.get_user_data = lambda: UserDataResponse()
         api.fetch_liked_datasets = lambda: PaginatedDatasetResults()
         api.fetch_datasets = lambda: PaginatedDatasetResults()
         api.fetch_contributing_datasets = lambda: PaginatedDatasetResults()
         return api
Esempio n. 10
0
    def test_processor_init_3x3_operands_in_3x3_processors(self):
        # given
        nprocs = 9
        procs = [Spy(Cannon.Processor) for i in range(nprocs)]
        frontend = FrontendI(procs)

        # when
        frontend.init_processors()

        # then
        assert_that(procs[0].init,
                    called().with_args(0, 3, procs[6], procs[2], anything()))
        assert_that(procs[1].init,
                    called().with_args(1, 3, procs[7], procs[0], anything()))
        assert_that(procs[2].init,
                    called().with_args(2, 3, procs[8], procs[1], anything()))
        assert_that(procs[3].init,
                    called().with_args(3, 3, procs[0], procs[5], anything()))
        assert_that(procs[4].init,
                    called().with_args(4, 3, procs[1], procs[3], anything()))
        assert_that(procs[5].init,
                    called().with_args(5, 3, procs[2], procs[4], anything()))
        assert_that(procs[6].init,
                    called().with_args(6, 3, procs[3], procs[8], anything()))
        assert_that(procs[7].init,
                    called().with_args(7, 3, procs[4], procs[6], anything()))
        assert_that(procs[8].init,
                    called().with_args(8, 3, procs[5], procs[7], anything()))
Esempio n. 11
0
    def get_pool(self):

        with Spy() as pool:
            pool.start(ANY_ARG)
            pool.stop(ANY_ARG)

        return pool
Esempio n. 12
0
    def test_dispatch_route_bad_request(self):

        controller = StubController()
        request = Spy()

        result = yield controller.render(request)
        self.assertIsInstance(result, response.BadRequest)
Esempio n. 13
0
	def test_processors_6x6_block(self):
        # given
        P0 = ProcessorI()
        collector = Spy()

        A = M6( 1 ,2 ,3 ,4 ,5 ,6  	
		,7 ,8 ,9 ,10 ,11 ,12  
		,13 ,14 ,15 ,16 ,17 ,18  
		,19 ,20 ,21 ,22 ,23 ,24  
		,25 ,26 ,27 ,28 ,29 ,30  
		,31 ,32 ,33 ,34 ,35,36 )
        
        B = M6(36 ,35 ,34 ,33 ,32 ,31  	
		,30 ,29 ,28 ,27 ,26 ,25  
		,24 ,23 ,22 ,21 ,20 ,19  
		,18 ,17 ,16 ,15 ,14 ,13  
		,12 ,11 ,10 ,9 ,8 ,7  
		,6 ,5 ,4 ,3 ,2 ,1  )

        C = M6(336 ,315 ,294 ,273 ,252 ,231 	
		,1092 ,1035 ,978 ,921 ,864 ,807 
		,1848 ,1755 ,1662 ,1569 ,1476 ,1383 
		,2604 ,2475 ,2346 ,2217 ,2088 ,1959 
		,3360 ,3195 ,3030 ,2865 ,2700 ,2535 
		,4116 ,3915 ,3714 ,3513 ,3312 ,3111)

        # when
        P0.init(0, 1, None, None, collector)
        P0.injectA(A, 0)
        P0.injectB(B, 0)

        # then
        assert_that(collector.inject, called().with_args(0, C, ANY_ARG))
Esempio n. 14
0
def a_backend_with_messages(messages: List[Message]) -> MessagingBackend:
    backend = Spy(MessagingBackend)

    with backend:
        backend.get_queue(ANY_ARG).returns({})
        backend.retrieve_messages(ANY_ARG).returns(messages)
        backend.yield_messages(ANY_ARG).returns(messages)

    return cast(MessagingBackend, backend)
Esempio n. 15
0
 def test_check_the_sensor_once_per_second(self):
     sensor = Stub(Sensor)
     recorder = Spy(Recorder)
     controller = Controller(sensor, recorder)
     # medir aqui la hora
     controller.record_movement(3)
     # volver a medir aquí la hora
     assert_that(recorder.stop_recording, called().times(3))
Esempio n. 16
0
    def test_account_creation__report_message(self):
        with Stub(PasswordService) as password_service:
            password_service.generate().returns('some')

        store = Spy(AccountStore)
        service = AccountService(store, password_service)

        service.create_group('team', ['John', 'Alice'])
Esempio n. 17
0
 def datasets_api(self):
     with Spy(DatasetsApi) as api:
         api.get_dataset = lambda o, d: DatasetSummaryResponse(o, d)
         api.create_dataset_with_http_info = lambda o, b, **kwargs: (
             {}, 200, {
                 'Location': 'https://data.world/agentid/datasetid'
             })
         return api
Esempio n. 18
0
    def _prepare_store_spy(self, raises_exception=False):

        with Spy() as store:
            getUtility_spy = lambda _: {'mamba': store}
            if raises_exception is True:
                store.execute(ANY_ARG).raises(DisconnectionError)

        return getUtility_spy, store
Esempio n. 19
0
def test_configure():
    runner = CliRunner()
    config = Spy(Config)

    runner.invoke(cli.configure, input='token\n', obj={'config': config})

    assert_that(config, property_set('auth_token').to('token'))
    assert_that(config.save, called())
Esempio n. 20
0
    def test_asks_the_recorder_to_stop_recording_when_no_information_received_from_sensor(self):
        sensor = Stub(Sensor)
        recorder = Spy(Recorder)
        controller = Controller(sensor, recorder)

        controller.record_movement()

        assert_that(recorder.stop_recording, called())
Esempio n. 21
0
    def test_any_arg_matches_property(self):
        prop_stub = Spy(CollaboratorWithProperty)
        when(prop_stub).prop.returns(5)

        with Stub(Collaborator) as stub:
            stub.method_accepting_property(prop=anything()).returns(2)

        assert_that(stub.method_accepting_property(prop_stub.prop), is_(2))
        assert prop_stub.prop == 5
Esempio n. 22
0
    def test_wait_3_tries_ok(self):
        with Spy() as other_task:
            other_task.is_running().delegates([False, False, True])

        task = prego.Task()
        c = task.wait_that(other_task, prego.running(), delta=0.1, timeout=1)
        c.eval()

        assert_that(other_task.is_running, called().times(3))
Esempio n. 23
0
    def test_stops_the_recording_if_sensor_raises_an_exception(self):
        with Stub(Sensor) as sensor:
            sensor.is_detecting_movement().raises(ValueError)
        recorder = Spy(Recorder)
        controller = Controller(sensor, recorder)

        controller.record_movement()

        assert_that(recorder.stop_recording, called())
Esempio n. 24
0
    def get_request(self):

        with Spy() as request:
            request.registerProducer(ANY_ARG)
            request.unregisterProducer()
            request.write(ANY_ARG)
            request.setResponseCode(ANY_ARG)
            request.setHeader(ANY_ARG)

        return request
Esempio n. 25
0
    def test_account_creation__free_stub(self):
        with Stub() as password_service:
            password_service.generate().returns('some')

        store = Spy(AccountStore)
        service = AccountService(store, password_service)

        service.create_group('team', ['John', 'Peter', 'Alice'])

        assert_that(store.save, called())
Esempio n. 26
0
    def test_account_creation__restricted_stub(self):
        with Stub(PasswordService) as password_service:
            password_service.generate().returns('some')

        store = Spy(AccountStore)
        service = AccountService(store, password_service)

        service.create_user('John')

        assert_that(store.save, called())
Esempio n. 27
0
    def test_processors_rings(self):
        # given
        P0 = ProcessorI()
        P1 = Spy()
        P2 = Spy()
        collector = Stub()

        A0 = M1(1)
        B0 = M1(5)

        # when
        P0.init(1, 1, P2, P1, 2, collector)
        P0.injectFirst(A0, 0)
        P0.injectSecond(B0, 0)

        # then
        assert_that(P1.injectFirst,
                    called(). async (1).with_args(A0, 1, ANY_ARG))
        assert_that(P2.injectSecond,
                    called(). async (1).with_args(B0, 1, ANY_ARG))
Esempio n. 28
0
    def test_wait_fail(self):
        with Spy() as cmd:
            cmd.is_running().delegates([False, False, False])

        task = prego.Task()
        c = task.wait_that(cmd, prego.running(), delta=0.1, timeout=0.3)

        with self.assertRaises(prego.PregoAssertionFailed):
            c.eval()

        assert_that(cmd.is_running, called().times(3))
Esempio n. 29
0
    def test_account_creation__3_accounts(self):
        with Stub(PasswordService) as password_service:
            password_service.generate().returns('some')

        store = Spy(AccountStore)
        service = AccountService(store, password_service)

        service.create_group('team', ['John', 'Peter', 'Alice'])

        assert_that(store.save, called().times(3))
        assert_that(store.save, called().times(greater_than(2)))
Esempio n. 30
0
 def insights_api(self):
     with Spy(InsightsApi) as api:
         api.get_insight = lambda o, d, i: InsightSummaryResponse(
                             id=i,
                             title='Insights',
                             body={},
                             author=o,
                             created='2018-02-01T01:03:26.879Z',
                             updated='2018-02-01T01:03:28.211Z')
         api.create_insight_with_http_info = lambda o, d, **kwargs: (
             {}, 200, {'Location': 'https://data.world/agentid/projectid'})
         return api
Esempio n. 31
0
    def test_inline_spy(self):
        #Spy()创建free spy
        spy_inline_free = Spy()
        #使用when()设置方法参数和返回值
        when(spy_inline_free).foo().returns("I am inline foo")
        #调用方法
        spy_inline_free.foo()
        #验证调用情况
        assert_that(spy_inline_free.foo(), is_("I am inline foo"))
        assert_that(spy_inline_free.foo, called())

        #Spy()创建spy
        spy_inline = Spy(ss.salaryService)
        #使用when()设置方法参数
        when(spy_inline).set_salary(ANY_ARG)
        #调用方法
        spy_inline.set_salary("12m")
        #验证调用情况
        assert_that(spy_inline.set_salary, called().with_args("12m"))
Esempio n. 32
0
        module = tempfile.mkdtemp()

        suite = get_spec_suite(module)
        expect(suite).to(be(None))

        spec_dir = os.path.join(module, 'spec')
        os.mkdir(spec_dir)
        suite = get_spec_suite(module)
        expect(suite).to(be_a(BaseRunner))

    with it('has to run the tests found in spec directory'):
        module = tempfile.mkdtemp()
        spec_dir = os.path.join(module, 'spec')
        os.mkdir(spec_dir)
        suite = get_spec_suite(module)
        suite = Spy(suite)
        suite.run = method_returning(True)
        result = run_spec_suite(suite)
        expect(result).to(be_a(Reporter))
        expect(suite.run).to(have_been_called)


with description('When running tests'):
    with it('must be reload report.interface'):
        import sys

        class Mock(object):
            pass

        fake_report = Mock()
        fake_report.interface = Mock()