def test_hardware_module_get_projects(client): rv_login = login(client, 'test', '123456') data_login = rv_login.get_json(force=True) # successfully login check.equal(data_login['message'], 'success') # test get projecs info on hardware page rv_proj = get_projects(client) data_proj = rv_proj.get_json(force=True) check.equal(data_proj['message'], 'success') for i in range(len(data_proj)): check.is_in('testProj', data_proj['projects'][i]['name'])
def test_checkboxLegend_customHandler(): """Test legend with custom handler""" ax = plt.gca() line, = plt.plot([1, 2], [1, 2], color='r', lw=2) custom_handler = ExampleHandler() legend = plt.legend( [line], ["line"], handler_map={line: VisibilityHandler(handler=custom_handler)}) handler = legend.get_legend_handler(legend.get_legend_handler_map(), line).handler check.equal(custom_handler, handler)
def test_suppressed_return_error( self, yielded_errors: Tuple[str, NoneReturnSuppressionTestCase, Tuple[Error]] ) -> None: """Test that ANN200 level errors are suppressed if a function only returns None.""" failure_msg = f"Check failed for case '{yielded_errors[0]}'" yielded_ANN200 = any("ANN2" in error[2] for error in yielded_errors[2]) check.equal(yielded_errors[1].should_yield_ANN200, yielded_ANN200, msg=failure_msg)
def test_initialize_from_fits_with_data_in_different_extension(tmpdir): fake_img = np.arange(4).reshape(2, 2) hdu1 = fits.PrimaryHDU() hdu2 = fits.ImageHDU(fake_img) hdus = fits.HDUList([hdu1, hdu2]) filename = tmpdir.join('afile.fits').strpath hdus.writeto(filename) with catch_warnings(FITSFixedWarning) as w: ccd = FrameData.read_fits(filename, unit='adu') check.equal(len(w), 0) np.testing.assert_array_equal(ccd.data, fake_img)
def test_type_comment_arg_injection( self, yielded_errors: Tuple[str, TypeCommentArgInjectTestCase, Tuple[FORMATTED_ERROR]] ) -> None: """Test that ANN100 errors are yielded appropriately for type comment annotated defs.""" failure_msg = f"Check failed for case '{yielded_errors[0]}'" yielded_ANN100 = any("ANN1" in error[2] for error in yielded_errors[2]) check.equal(yielded_errors[1].should_yield_ANN100, yielded_ANN100, msg=failure_msg)
def test_suppressed_return_error( self, yielded_errors: Tuple[str, DummyArgSuppressionTestCase, Tuple[FORMATTED_ERROR]] ) -> None: """Test that ANN000 level errors are suppressed if an annotation is named '_'.""" failure_msg = f"Check failed for case '{yielded_errors[0]}'" yielded_ANN000 = any("ANN0" in error[2] for error in yielded_errors[2]) check.equal(yielded_errors[1].should_yield_ANN000, yielded_ANN000, msg=failure_msg)
def test_add_fuel_card(card_number, db, api): db.del_card_if_exist(card_number) # 环境准备 res = api.add_fuel_card(card_number) check.equal(200, res['code'], "响应code不为200") check.equal('添加卡成功', res['msg'], "响应msg非'添加卡成功'") check.is_false(res['success'], '响应success不为false') # bug check.is_true(db.check_card(card_number), f'数据库查询卡号{card_number}不存在') # 数据库断言 db.del_card_if_exist(card_number) # 环境清理
def test_conda_reqs(extras_from_setup): """Test conda requirements files match main file.""" main_reqs_file = Path(PKG_ROOT) / REQS_FILE conda_reqs_file = Path(PKG_ROOT) / "conda/conda-reqs.txt" conda_reqs_pip_file = Path(PKG_ROOT) / "conda/conda-reqs-pip.txt" main_reqs_dict = _get_reqs_from_file(main_reqs_file) # Add extras for item in [re.split(REQS_OP_RGX, line) for line in extras_from_setup]: main_reqs_dict[item[0].strip()] = item[1].strip() if len(item) > 1 else None conda_reqs_dict = _get_reqs_from_file(conda_reqs_file) conda_reqs_pip_dict = _get_reqs_from_file(conda_reqs_pip_file) for key, val in main_reqs_dict.items(): print(f"Checking {key} in conda-reqs.txt", bool(key in conda_reqs_dict)) print(f"Checking {key} in conda-reqs-pip.txt", bool(key in conda_reqs_pip_dict)) check.is_true( key in conda_reqs_dict or key in conda_reqs_pip_dict or key in CONDA_PKG_EXCEPTIONS, ) if not ( key in conda_reqs_dict or key in conda_reqs_pip_dict or key in CONDA_PKG_EXCEPTIONS, ): print("Test Error - no conda package equiv for {key}=={val}") if key in conda_reqs_dict: if conda_reqs_dict[key]: if val != conda_reqs_dict[key]: print( f"{key} version mismatch - setup: {val}: {conda_reqs_dict[key]}", "in conda-reqs.txt", ) check.equal(val, conda_reqs_dict[key], f"{key} in condas reqs") conda_reqs_dict.pop(key) if key in conda_reqs_pip_dict: if conda_reqs_pip_dict[key]: if val != conda_reqs_pip_dict[key]: print( f"{key} version mismatch - setup: {val}: {conda_reqs_pip_dict[key]}", "in conda-reqs-pip.txt", ) check.equal(val, conda_reqs_pip_dict[key], f"{key} in condas pip reqs") conda_reqs_pip_dict.pop(key) if conda_reqs_dict: print("Extra items found in conda-reqs.txt", conda_reqs_pip_dict) check.is_false(conda_reqs_dict, "no extra items in conda-reqs.txt") if conda_reqs_pip_dict: print("Extra items found in conda-reqs-pip.txt", conda_reqs_dict) check.is_false(conda_reqs_pip_dict, "no extra items in conda-reqs-pip.txt")
def test_builb_callback_no_logger(self): """ should work if logger is None. """ callbacks = [Callback(), Callback()] logger = None params = {'param123': 123} callbacklist = self.playground._build_callbacks( callbacks, logger, params) check.is_instance(callbacklist, CallbackList) for callback in callbacklist.callbacks: check.equal(callback.params, params) check.equal(callback.playground, self.playground)
def test_checkboxLegend_visibility_before(): """Test legend with visibility off before adding to the handler map""" rect = mpatches.Rectangle((0, 0), 0.5, 0.5) ax = plt.gca() ax.add_patch(rect) rect.set_visible(0) legend = plt.legend([rect], ["rect"], handler_map={rect: VisibilityHandler()}) handle = legend.get_legend_handler(legend.get_legend_handler_map(), rect) checked = handle.is_checked() check.equal(checked, False)
def test_pipeline_complete_flow(): global string_store string_store = [] m = TestManager() m.setup_pipeline() m.setup_products('first_product', 4) m.setup_products('secon_product', 8) m.show_products() m.run() m.run(index=0, target='sum') check.equal(string_store, [('c=3', 'a+b=3 b*d=16'), ('c=3', 'a+b=3 b*d=16')])
def test_set_playground(self, mocker): """ should update playground of all callbacks correctly. """ mocker.patch(self.callback_path + '.set_playground') callbacks = CallbackList(self.callbacks) expected_playground = "playground" callbacks.set_playground(expected_playground) check.equal(callbacks.playground, expected_playground) for callback in self.callbacks: args, _ = callback.set_playground.call_args check.equal(args[0], expected_playground)
def test_set_params(self, mocker): """ should update params of all callbacks correctly. """ mocker.patch(self.callback_path + '.set_params') callbacks = CallbackList(self.callbacks) expected_params = {"param": 1} callbacks.set_params(expected_params) check.equal(callbacks.params, expected_params) for callback in self.callbacks: args, _ = callback.set_params.call_args check.equal(args[0], expected_params)
def test_pd_run(test_df, capsys): """Test mp_pivot.run accessor.""" res_df = test_df.mp_pivot.run(_nop_df, test_col="test_val", verbose=True, debug=True) check.equal(len(res_df), len(test_df)) cap_out = capsys.readouterr().out check.is_in("rows returned from", cap_out) check.is_in("Columns in result", cap_out) check.is_in("Parameters:", cap_out) check.is_in("test_col", res_df.columns)
def test_add_fuel_card_3times(db, api, data): card_numbers = data['FREE_CARD_NUMBERS'][:3] [db.del_card_if_exist(card_number) for card_number in card_numbers] for card_number in card_numbers: res = api.add_fuel_card(card_number) check.equal(200, res['code'], "响应code不为200") check.equal('添加卡成功', res['msg'], "响应msg非'添加卡成功'") check.is_false(res['success'], '响应success不为false') check.is_true(db.check_card(card_number), f'数据库查询卡号{card_number}不存在') # 数据库断言 [db.del_card_if_exist(card_number) for card_number in card_numbers]
def test_render_not_done(self, mocker): """ should render at each step beginning if not done. """ render_mode = 'render_mode' self.playground._run_step(self.observation, self.previous, logs={}, render=True, render_mode=render_mode) check.equal(len(self.env.render.call_args_list), 1) render_args, _ = self.env.render.call_args check.equal(render_args[0], render_mode)
def test_extension_by_headers(): """should get correct extension""" check.equal(requests_util.extension_by_headers( 'multipart/related; type="application/dicom"'), (".dcm")) check.equal(requests_util.extension_by_headers( 'type="application/dicom"'), (".dcm")) check.equal(requests_util.extension_by_headers( 'type="image/jpeg"'), (".jpg")) check.equal(requests_util.extension_by_headers( 'multipart/related; type="image/png"'), (".png")) check.equal(requests_util.extension_by_headers( 'multipart/related; type="application/octet-stream"'), (".raw"))
def test_framedata_cration_array_mask(): a = _random_array.copy() b = np.zeros(_random_array.shape) meta = DEFAULT_HEADER.copy() unit = 'adu' f = FrameData(a, unit=unit, meta=meta, mask=b, m_dtype='bool') npt.assert_array_almost_equal(a, f.data) npt.assert_array_almost_equal(b, f.mask) check.is_true(f.unit is u.adu) check.is_true(np.issubdtype(f.mask.dtype, np.bool)) check.equal(f.meta['observer'], meta['observer']) check.equal(f.meta['very long key'], meta['very long key'])
def test_it_parses_correct_input_correctly(ors_client): # Setup correct_location_line = r'{"name": "Haus der Musik", "city": "Heiden", "postal_code": "46359", "street": "Am Sportzentrum", "housenumber": "7"}' subject = MeetingLocation(ors_client, correct_location_line) # Test check.equal(subject.name, "Haus der Musik") check.equal(subject.city, "Heiden") check.equal(subject.postal_code, "46359") check.equal(subject.street, "Am Sportzentrum") check.equal(subject.housenumber, "7")
def test_classify_frames(): frame_list1 = example_job2.classify_frames() frame_list = example_job1.classify_frames() check.equal(frame_list1[0][0], 0) check.less(frame_list1[0][1], 0.7) check.not_equal(frame_list1[1][0], 5) check.greater(frame_list1[1][1], 0.7) check.equal(frame_list[0][0], 0) check.less(frame_list[0][1], 0.7) check.not_equal(frame_list[1][0], 4) check.greater(frame_list[1][1], 0.7)
def test_bind_fuel_card(db, api, data): user_name, id_number = data['FREE_USER'] card_number = data['FREE_CARD'] # db.reset_card(card_number) res = api.bind_fuel_card(user_name, id_number, card_number) check.equal(5010, res['code']) check.equal('绑定成功', res['msg']) check.is_true(res['success']) db.reset_card(card_number)
def test_ANN301_classification( self, yielded_errors: Tuple[str, ParserTestCase, Tuple[FORMATTED_ERROR]] ) -> None: """Test for correct classification of mixed type comments & type annotations.""" failure_msg = f"Check failed for case '{yielded_errors[0]}'" yielded_ANN301 = any("ANN301" in error[2] for error in yielded_errors[2]) check.equal(yielded_errors[1].should_yield_ANN301, yielded_ANN301, msg=failure_msg)
def test_add_fuel_card_wrong_request_format(api, data): card_number = data['FREE_CARD_NUMBERS'][0] data = { "dataSourceId": "bHRz", "methodId": "00A", "CardInfo": { "cardNumber": card_number } } res = api.post(data=data).json() check.equal(301, res['code']) check.is_in('参数类型错误', res['msg'])
def test_bind_fuel_card_twice(db, api, data): user_name, id_number = data['FREE_USER'] card_numbers = (data['FREE_CARD'], data['FREE_CARD2']) db.reset_user(user_name) for card_number in card_numbers: res = api.bind_fuel_card(user_name, id_number, card_number) check.equal(5010, res['code']) check.equal('绑定成功', res['msg']) check.is_true(res['success']) db.reset_user(user_name)
def test_extract_header_nosip(): header = fits.Header.fromstring(_base_header + _wcs_no_sip, sep='\n') h, wcs = extract_header_wcs(header) check.is_instance(wcs, WCS) check.equal(wcs.wcs.ctype[0], 'RA---TAN') check.equal(wcs.wcs.ctype[1], 'DEC--TAN') check.is_instance(h, fits.Header) for i in _comon_wcs_keys: check.is_not_in(f'{i}1', h.keys()) check.is_not_in(f'{i}2', h.keys()) check.is_in('DATE-OBS', h.keys()) check.is_false(h is header) check.not_equal(h, header)
def test_add_fuel_card_data_source_id_blank(api, data): card_number = data['FREE_CARD_NUMBERS'][0] data = { "dataSourceId": "", "methodId": "00A", "CardInfo": { "cardNumber": card_number } } res = api.post(json=data).json() check.equal(301, res['code']) check.is_in('第三方平台ID不能为空', res['msg'])
def test_run_command_string(): com = "python -c \"print(__import__('sys').version)\"" stdout = [] stderr = [] res, out, err = run_command(com, stdout=stdout, stderr=stderr, stdout_loglevel='WARN') for o in out: check.is_in(o, stdout) for e in err: check.is_in(e, stderr) check.equal('\n'.join(stdout), sys.version)
def test_consume_fuel_card_norma3(api, data): """用户id(userId)为空""" request_data = data.get('test_consume_fuel_card_norma3') try: res_dict = api.request_all(request_data).json() print(f'响应数据{res_dict}') # 响应断言 ck.equal(301, res_dict.get("code")) ck.almost_equal("参数类型错误com.alibaba.fastjson.JSONException", res_dict.get("msg")) ck.is_false(res_dict.get('success')) except: pass
def test_lineno(parsed_errors: Tuple[Generator[ERROR_CODE, None, None], ParserTestCase]) -> None: """ Check for correct line number values. Emitted error codes are tuples of the form: (line number, column number, error string, checker class) Note: Line numbers are 1-indexed """ for should_error_idx, raised_error_code in zip_longest( parsed_errors[1].error_locations, parsed_errors[0] ): check.equal(should_error_idx[0], raised_error_code[0])
def test_bind_fuel_card_normal(api, data, db): """绑定不存在的加油卡""" request_data = data.get('test_bind_fuel_card_normal') card_number = request_data.get('json').get('CardInfo').get('cardNumber') #环境检查 if db.check_card(card_number): db.del_card(card_number) res_dict = api.request_all(request_data).json() print(f'响应数据{res_dict}') # 响应断言 ck.equal(5013, res_dict.get("code")) ck.equal("加油卡号不存在", res_dict.get("msg")) ck.is_false(res_dict.get('success'))