Exemplo n.º 1
0
 def test_check_package_format(self):
     r2env = R2Env()
     assert_that(r2env._check_package_format("radare2@git"), equal_to(True))
     assert_that(r2env._check_package_format("[email protected]"), equal_to(True))
     assert_that(r2env._check_package_format("[email protected]"), equal_to(False))
     assert_that(r2env._check_package_format("[email protected]"), equal_to(False))
     assert_that(r2env._check_package_format("radare2git"), equal_to(False))
Exemplo n.º 2
0
    def test_load_dataset_existing_forced(self, api_client, dw, dataset_key):
        dataset = dw.load_dataset(dataset_key, force_update=True)

        assert_that(
            api_client.download_datapackage,
            called().times(1).with_args(equal_to(dataset_key), anything()))
        assert_that(dataset.raw_data, has_length(4))
Exemplo n.º 3
0
    def test_calls_spy(self):
        salary = "20m"
        year = 2017
        #创建spy
        with Spy(ss.salaryService) as ss_spy:
            ss_spy.set_salary(salary)
        #调用方法
        ss_spy.set_salary(salary)
        ss_spy.set_salary("22m")
        #使用calls取得调用传入的参数
        #多次调用可以多次取得,calls是一个数组
        assert_that(ss_spy.set_salary.calls[0].args, is_((salary, )))
        assert_that(ss_spy.set_salary.calls[1].args, is_(("22m", )))

        #创建spy
        with Spy(bs.bodyService) as bs_spy:
            bs_spy.get_height().returns("190cm")
            bs_spy.illnessHistory(year).returns("no injury")
        #调用方法
        bs_spy.get_height()
        bs_spy.illnessHistory(year)
        #使用calls取得调用传入的参数和返回值
        assert_that(bs_spy.get_height.calls[0].retval, is_("190cm"))
        assert_that(bs_spy.illnessHistory.calls[0].args, is_((year, )))
        assert_that(bs_spy.illnessHistory.calls[0].retval, is_("no injury"))
Exemplo n.º 4
0
 def test_update_dataset(self, api_client, datasets_api, dataset_key):
     patch_request = {'tags': ['tag1', 'tag2']}
     api_client.update_dataset(dataset_key, **patch_request)
     assert_that(datasets_api.patch_dataset,
                 called().times(1).with_args(equal_to('agentid'),
                                             equal_to('datasetid'),
                                             has_properties(patch_request)))
 def test_dataframe_types(self, simpsons_dataset):
     df = simpsons_dataset.dataframes['simpsons_episodes']
     assert_that(df['id'].dtype, equal_to('int64'))
     assert_that(df['title'].dtype, equal_to('object'))
     assert_that(df['original_air_date'].dtype, equal_to('datetime64[ns]'))
     assert_that(df['original_air_year'].dtype, equal_to('int64'))
     assert_that(df['imdb_rating'].dtype, equal_to('float64'))
Exemplo n.º 6
0
 def test_upload_files(self, api_client, uploads_api, dataset_key):
     files = ['filename.ext']
     api_client.upload_files(dataset_key, files)
     assert_that(uploads_api.upload_files,
                 called().times(1).with_args(equal_to('agentid'),
                                             equal_to('datasetid'),
                                             equal_to(files)))
Exemplo n.º 7
0
 def test_dataframe_broken_schema(self, simpsons_broken_dataset):
     assert_that(
         calling(simpsons_broken_dataset.dataframes.get).with_args(
             'simpsons_episodes'), not_(raises(Exception)))
     assert_that(
         simpsons_broken_dataset.dataframes.get('simpsons_episodes'),
         not_none())
Exemplo n.º 8
0
 def test_delete_files(self, api_client, datasets_api, dataset_key):
     files = ['filename.ext']
     api_client.delete_files(dataset_key, files)
     assert_that(datasets_api.delete_files_and_sync_sources,
                 called().times(1).with_args(equal_to('agentid'),
                                             equal_to('datasetid'),
                                             equal_to(files)))
Exemplo n.º 9
0
 def test_get_insight_for_project(self, api_client, insights_api,
                                  project_key):
     api_client.get_insights_for_project(project_key)
     assert_that(
         insights_api.get_insights_for_project,
         called().times(1).with_args(equal_to('agentid'),
                                     equal_to('projectid')))
Exemplo n.º 10
0
 async def test_process_new_version(self, target, api_client,
                                    test_files_path):
     with open(path.join(test_files_path,
                         'fixerio-new-version.jsonl')) as file:
         async for _ in target.process_lines(file):  # noqa: F841
             pass
         assert_that(api_client.truncate_stream_records, called().times(1))
Exemplo n.º 11
0
 async def test_process_lines_multiple_streams(self, target, api_client,
                                               test_files_path):
     with open(path.join(test_files_path,
                         'fixerio-multistream.jsonl')) as file:
         async for _ in target.process_lines(file):  # noqa: F841
             pass
         assert_that(api_client.append_stream_chunked, called().times(2))
Exemplo n.º 12
0
    def test_create_column_metadata(self):
        cols = [{'pos': 1, 'name': 'col1', 'type': 'int2', 'nullable': 'NO'},
                {'pos': 2, 'name': 'col2', 'type': 'float8',
                 'nullable': 'YES'},
                {'pos': 3, 'name': 'col3', 'type': 'timestamptz',
                 'nullable': 'NO'}]
        db_name = 'test-db'
        table_name = 'test_table'
        key_properties = ['col1']
        is_view = False
        expected_mdata = metadata.new()
        metadata.write(expected_mdata, (), 'selected-by-default', False)
        metadata.write(expected_mdata, (), 'valid-replication-keys', ['col3'])
        metadata.write(expected_mdata, (),
                       'table-key-properties', key_properties)
        metadata.write(expected_mdata, (), 'is-view', is_view)
        metadata.write(expected_mdata, (), 'schema-name', table_name)
        metadata.write(expected_mdata, (), 'database-name', db_name)
        for col in cols:
            schema = tap_redshift.schema_for_column(col)
            metadata.write(expected_mdata, (
                'properties', col['name']), 'selected-by-default', True)
            metadata.write(expected_mdata, (
                'properties', col['name']), 'sql-datatype', col['type'])
            metadata.write(expected_mdata, (
                'properties', col['name']), 'inclusion', schema.inclusion)

        actual_mdata = tap_redshift.create_column_metadata(
            db_name, cols, is_view, table_name, key_properties)
        assert_that(actual_mdata, equal_to(metadata.to_list(expected_mdata)))
Exemplo 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))
Exemplo n.º 14
0
 def test_delete_files(self, api_client, datasets_api, dataset_key):
     files = ['filename.ext']
     api_client.delete_files(dataset_key, files)
     assert_that(datasets_api.delete_files_and_sync_sources,
                 called().times(1).with_args(equal_to('agentid'),
                                             equal_to('datasetid'),
                                             equal_to(files)))
Exemplo n.º 15
0
 def test_save_overwrite(self, config_file_path):
     config = FileConfig(config_file_path=config_file_path)
     assert_that(config_file_path, is_not(equal_to('newtoken')))
     config.auth_token = 'newtoken'
     config.save()
     config_reloaded = FileConfig(config_file_path=config_file_path)
     assert_that(config_reloaded.auth_token, equal_to('newtoken'))
Exemplo n.º 16
0
 def test_upload_file(self, api_client, uploads_api, dataset_key):
     name = 'filename.ext'
     api_client.upload_file(dataset_key, name)
     assert_that(uploads_api.upload_file,
                 called().times(1).with_args(equal_to('agentid'),
                                             equal_to('datasetid'),
                                             equal_to(name)))
Exemplo n.º 17
0
 def test_download_datapackage_existing_dest_dir(
         self, config, api_client, dataset_key):
     os.mkdir(config.cache_dir)
     assert_that(
         calling(api_client.download_datapackage).with_args(
             dataset_key, config.cache_dir),
         raises(ValueError))
Exemplo n.º 18
0
 def test_dataframe_types(self, simpsons_dataset):
     df = simpsons_dataset.dataframes['simpsons_episodes']
     assert_that(df['id'].dtype, equal_to('int64'))
     assert_that(df['title'].dtype, equal_to('object'))
     assert_that(df['original_air_date'].dtype, equal_to('datetime64[ns]'))
     assert_that(df['original_air_year'].dtype, equal_to('int64'))
     assert_that(df['imdb_rating'].dtype, equal_to('float64'))
Exemplo n.º 19
0
 def test_update_dataset(self, api_client, datasets_api, dataset_key):
     patch_request = {'tags': ['tag1', 'tag2']}
     api_client.update_dataset(dataset_key, **patch_request)
     assert_that(datasets_api.patch_dataset,
                 called().times(1).with_args(equal_to('agentid'),
                                             equal_to('datasetid'),
                                             has_properties(patch_request)))
Exemplo n.º 20
0
 def test_observer_stub(self):
     def bar():
         print("I am attached")
     with Stub() as stub:
         stub.foo().returns("I am foo")
         stub.foo.attach(bar)
     assert_that(stub.foo(), is_("I am foo"))
Exemplo n.º 21
0
 def test_download_datapackage_existing_dest_dir(
         self, config, api_client, dataset_key):
     os.mkdir(config.cache_dir)
     assert_that(
         calling(api_client.download_datapackage).with_args(
             dataset_key, config.cache_dir),
         raises(ValueError))
Exemplo n.º 22
0
    def test_append_stream(self, client, records_generator):
        with responses.RequestsMock() as rsps:
            all_records = list(records_generator())
            call_count = 0

            def verify_body_and_count(req):
                nonlocal call_count, all_records

                assert_that(
                    req.body.decode('utf-8'),
                    equal_to(to_jsonlines(all_records)))

                call_count += 1
                return 200, {}, None

            rsps.add_callback(
                'POST',
                '{}/streams/owner/dataset/stream'.format(
                    client._api_url),
                callback=verify_body_and_count)

            client.append_stream(
                'owner', 'dataset', 'stream', records_generator())

            assert_that(call_count, equal_to(1))
Exemplo n.º 23
0
 def test_delete_insight(self, api_client, insights_api, project_key,
                         insight_id='insightid'):
     api_client.delete_insight(project_key, insight_id)
     assert_that(insights_api.delete_insight,
                 called().times(1).with_args(equal_to('agentid'),
                                             equal_to('projectid'),
                                             equal_to(insight_id)))
Exemplo n.º 24
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'
Exemplo n.º 25
0
    def test_prompt_renders_all_questions(self):
        question1 = dbx.Stub()
        question1.name = 'foo'
        result1 = object()

        question2 = dbx.Stub()
        question2.name = 'bar'
        result2 = object()

        result = object()
        with dbx.Spy() as render:
            render.reset()
            render.render(question1, {}).returns(result1)
            render.render(question2, {'foo': result1}).returns(result2)

        result = prompt([question1, question2], render=render)

        self.assertEquals({'foo': result1, 'bar': result2}, result)
        dbx.assert_that(
            render.render,
            dbx.called().with_args(question1, dbx.ANY_ARG))

        dbx.assert_that(
            render.render,
            dbx.called().with_args(question2,
                                   dbx.ANY_ARG))
Exemplo n.º 26
0
 def request_callback(request):
     for value in expected:
         assert_that(request.url,
                     contains_string(value),
                     reason="Expected [[\n{}\n]] to contain "
                     "[[\n{}\n]]".format(request.url, expected))
     return (200, {}, json.dumps(query_response_json))
Exemplo n.º 27
0
 def test_save_overwrite(self, config_file_path):
     config = FileConfig(config_file_path=config_file_path)
     assert_that(config_file_path, is_not(equal_to('newtoken')))
     config.auth_token = 'newtoken'
     config.save()
     config_reloaded = FileConfig(config_file_path=config_file_path)
     assert_that(config_reloaded.auth_token, equal_to('newtoken'))
Exemplo n.º 28
0
 def test_upload_files(self, api_client, uploads_api, dataset_key):
     files = ['filename.ext']
     api_client.upload_files(dataset_key, files)
     assert_that(uploads_api.upload_files,
                 called().times(1).with_args(equal_to('agentid'),
                                             equal_to('datasetid'),
                                             equal_to(files)))
Exemplo n.º 29
0
 def test_get_disturl_success(self, mock_getpkg):
     target_pkg = "radare2-5.3.1-w64.zip"
     version = "5.2.0"
     mock_getpkg.return_value = target_pkg
     dist_url = self.package_manager._get_disturl("mock_profile", version, "mock_cos")
     expected_url = "/".join([self.package_manager.DOWNLOAD_URL, version, target_pkg])
     assert_that(dist_url, equal_to(expected_url))
Exemplo n.º 30
0
 def test_replace_insight(self, api_client, insights_api, project_key,
                          insight_id='insightid'):
     replace_request = {'title': 'Replace Insight',
                        'image_url': 'https://image.com/'}
     api_client.replace_insight(project_key, insight_id,
                                **replace_request)
     assert_that(insights_api.replace_insight,
                 called().times(1))
Exemplo n.º 31
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())
Exemplo n.º 32
0
    def test_chain_default_behavior(self):
        stub = doublex.Stub()

        doublex.set_default_behavior(stub, doublex.Spy)
        chained_spy = stub.foo()
        chained_spy.bar()

        doublex.assert_that(chained_spy.bar, doublex.called())
Exemplo n.º 33
0
 def test_remove_linked_dataset(self, api_client, projects_api, project_key,
                                dataset_key):
     api_client.remove_linked_dataset(project_key, dataset_key)
     assert_that(projects_api.remove_linked_dataset,
                 called().times(1).with_args(equal_to('agentid'),
                                             equal_to('projectid'),
                                             equal_to('agentid'),
                                             equal_to('datasetid')))
Exemplo n.º 34
0
def test_configure():
    runner = CliRunner()
    config = Spy(FileConfig)

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

    assert_that(config, property_set('auth_token').to('token'))
    assert_that(config.save, called())
Exemplo n.º 35
0
 def test_sparql(self, api_client, dataset_key, sparql_api):
     api_client.sparql(dataset_key, 'query', sparql_api_mock=sparql_api)
     assert_that(
         sparql_api.sparql_post,
         called().times(1).with_args('agentid',
                                     'datasetid',
                                     'query',
                                     sparql_api_mock=sparql_api))
Exemplo n.º 36
0
 def test_replace_dataset(self, api_client, datasets_api, dataset_key):
     replace_request = {'visibility': 'OPEN'}
     api_client.replace_dataset(dataset_key, **replace_request)
     assert_that(
         datasets_api.replace_dataset,
         called().times(1).with_args(equal_to('agentid'),
                                     equal_to('datasetid'),
                                     has_properties(replace_request)))
Exemplo n.º 37
0
    def test_get_dataset(self, client):
        expected_resp = {'title': 'Dataset'}
        responses.add(
            'GET', '{}/datasets/owner/dataset'.format(client._api_url),
            json=expected_resp, status=200)

        resp = client.get_dataset('owner', 'dataset')
        assert_that(resp, equal_to(expected_resp))
Exemplo n.º 38
0
    def test_memoized(self, free_spy):
        @memoized(key_mapper=lambda first_arg, _: first_arg)
        def invoke_spy(first_arg, second_arg):
            return free_spy.method(first_arg, second_arg)

        assert_that(invoke_spy('test', 'not_in_key'),
                    equal_to(invoke_spy('test', 'should_not_matter')))
        assert_that(free_spy.method, called().times(1))
Exemplo n.º 39
0
 def test_replace_dataset(self, api_client, datasets_api, dataset_key):
     replace_request = {'visibility': 'OPEN'}
     api_client.replace_dataset(dataset_key, **replace_request)
     assert_that(datasets_api.replace_dataset,
                 called().times(1).with_args(equal_to('agentid'),
                                             equal_to('datasetid'),
                                             has_properties(
                                                 replace_request)))
Exemplo n.º 40
0
 def test_get_dataset(self, api_client, dataset_key):
     dataset = api_client.get_dataset(dataset_key)
     assert_that(
         dataset,
         has_entries({
             'owner': equal_to('agentid'),
             'id': equal_to('datasetid')
         }))
Exemplo n.º 41
0
 def test_adhoc_stub(self):
     bodyservice = bs.bodyService()
     #method_returning()直接在实例上建立stub,并设定返回值
     bodyservice.get_height = method_returning("210cm")
     assert_that(bodyservice.get_height(), is_("210cm"))
     #method_raising()直接在实例上建立stub,并抛出异常
     bodyservice.get_weight = method_raising(Exception)
     with self.assertRaises(Exception):
         bodyservice.get_weight()
Exemplo n.º 42
0
 def test_dataframe(self, query_result_example, query_results):
     metadata_names = [c['name'] for c in query_result_example['metadata']]
     df = query_results.dataframe
     assert_that(df['st.station_id'].dtype, equal_to('int64'))
     assert_that(df['st.name'].dtype, equal_to('object'))
     assert_that(df['st.lat'].dtype, equal_to('float64'))
     assert_that(df['st.datetime'].dtype, equal_to('datetime64[ns]'))
     assert_that(df.shape,
                 equal_to((len(query_result_example['results']['bindings']),
                           len(metadata_names))))
Exemplo n.º 43
0
    def test_get_by_name(self):
        with Stub(TopicModel) as stub_model:
            stub_model.name = 'ingeniería de software'

        with Stub(SearchTopicsController) as stub_contoller:
            stub_contoller.get_by_name(ANY_ARG).returns(stub_model)

        topic = stub_contoller.get_by_name('ingeniería de sofware')

        assert_that(topic.name, is_('ingeniería de software'))
Exemplo n.º 44
0
    def test_prepare_headers_works(self):

        request = self.get_request()
        self.c.prepare_headers(request, 200, {'content-type': 'x-test'})

        assert_that(request.setResponseCode, called().with_args(200).times(1))
        assert_that(
            request.setHeader,
            called().with_args('content-type', 'x-test').times(1)
        )
Exemplo n.º 45
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())
Exemplo n.º 46
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())
Exemplo n.º 47
0
    def test_get_by_title(self):
        with Stub(BookModel) as stub_model:
            stub_model.title = 'clean code'

        with Stub(SearchBooksController) as stub_contoller:
            stub_contoller.get_by_title(ANY_ARG).returns(stub_model)

        book = stub_contoller.get_by_title(title='clean code')

        assert_that(book.title, is_('clean code'))
Exemplo n.º 48
0
    def test_search_by_name(self):
        with Stub(Query) as stub_query:
            stub_query.count().returns(3)

        with Stub(SearchTopicsController) as stub_controller:
            stub_controller.filter_by_name('ingeniería').returns(stub_query)

        topics = stub_controller.filter_by_name('ingeniería')

        assert_that(topics.count(), is_(3))
Exemplo n.º 49
0
 def test_inline_stub(self):
     #Stub()创建free stub
     inline_stub_free = Stub()
     #使用when()设置方法参数和返回值
     when(inline_stub_free).foo(1).returns("I am inline free stub")
     assert_that(inline_stub_free.foo(1), is_("I am inline free stub"))
     #Stub(Collaborator)创建stub
     inline_stub = Stub(bs.bodyService)
     # 使用when()设置方法参数和返回值
     when(inline_stub).get_height().returns("188cm")
     assert_that(inline_stub.get_height(), is_("188cm"))
Exemplo n.º 50
0
    def test_reads_a_line_and_prints_it(self):
        line = 'foo'
        stdin = FakeIO(line)
        with doublex.Mock() as log:
            log.log(line)

        sut = colorize.Printer(stdin, {}, log.log)

        sut.process()

        doublex.assert_that(log, doublex.verify())
Exemplo n.º 51
0
    def test_prompt_renders_a_questions(self):
        question1 = dbx.Stub()
        question1.name = 'foo'
        result1 = object()
        with dbx.Mock() as render:
            render.render(question1, dbx.ANY_ARG).returns(result1)

        result = prompt([question1], render=render)

        self.assertEquals({'foo': result1}, result)
        dbx.assert_that(render, dbx.verify())
Exemplo n.º 52
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)))
Exemplo n.º 53
0
    def test_reads_two_lines_and_prints_them(self):
        line = '1\n2'
        stdin = FakeIO(line)
        with doublex.Mock() as log:
            log.log('1')
            log.log('2')

        sut = colorize.Printer(stdin, {}, log.log)

        sut.process()

        doublex.assert_that(log, doublex.verify())
Exemplo n.º 54
0
    def test_controller_render_delegates_on_routing(self):

        c = DummyController()

        router = ProxySpy(Router())
        c._router = router
        # request = self.get_request()
        request = ControllerRequest(['/test'], {})
        r = yield self._render(c, request)

        assert_that(router.dispatch, called().times(1))
        self.assertEqual(r.written[0], 'ERROR 404: /dummy/test not found')
Exemplo n.º 55
0
 def test_raw_data(self, simpsons_dataset, simpsons_datapackage,
                   simpsons_descriptor_path):
     for r in simpsons_datapackage.resources:
         resource = Resource(r.descriptor, default_base_path=path.dirname(
             simpsons_descriptor_path))
         once = simpsons_dataset.raw_data[r.descriptor['name']]
         twice = simpsons_dataset.raw_data[r.descriptor['name']]
         assert_that(once, equal_to(resource.data))
         # Not a generator
         for _ in once:
             pass  # Consume iterable
         assert_that(once, equal_to(twice))
Exemplo n.º 56
0
    def test_add_files_via_url(self, api_client, datasets_api, dataset_key):
        file_update_request = {'filename.ext': 'https://acme.inc/filename.ext'}
        file_update_object = FileBatchUpdateRequest(
            files=[FileCreateOrUpdateRequest(
                name='filename.ext',
                source=FileSourceCreateOrUpdateRequest(
                    url='https://acme.inc/filename.ext'))])

        api_client.add_files_via_url(dataset_key, file_update_request)
        assert_that(datasets_api.add_files_by_source,
                    called().times(1).with_args(equal_to('agentid'),
                                                equal_to('datasetid'),
                                                equal_to(file_update_object)))