def it_bounds_min(): test_s = s(s.is_list(min_len=2)) test_s.validate([1, 2]) with zest.raises(SchemaValidationFailed): test_s.validate([1]) with zest.raises(SchemaValidationFailed): test_s.validate([])
def it_raises_if_bounds_not_valid(): with zest.raises(SchemaInvalid): s._check_bounds_arg(bounds=4) with zest.raises(SchemaInvalid): s._check_bounds_arg(bounds=("a", "b")) with zest.raises(SchemaInvalid): s._check_bounds_arg(bounds=())
def it_validates_default_list_elems_int(): test_s = s(s.is_list(elems=s.is_int())) test_s.validate([1, 2, 3]) with zest.raises(SchemaValidationFailed): test_s.validate(1) with zest.raises(SchemaValidationFailed): test_s.validate([1, "str"])
def it_validates_float(): test_s = s(s.is_float()) test_s.validate(1.0) with zest.raises(SchemaValidationFailed): test_s.validate("a str") with zest.raises(SchemaValidationFailed): test_s.validate(1)
def it_exceptions_serially(): with zest.mock(pretend_unit_under_test.foo) as m_foo: m_foo.exceptions_serially([ValueError, TypeError]) with zest.raises(ValueError): pretend_unit_under_test.foo() with zest.raises(TypeError): pretend_unit_under_test.foo()
def it_validates_type(): test_s = s(s.is_type(TestType)) test_s.validate(TestType()) with zest.raises(SchemaValidationFailed): test_s.validate("a str") with zest.raises(SchemaValidationFailed): test_s.validate(1.0)
def it_fails_if_property_not_found(): # Tricky test -- using "with zest.raises()" to catch the # AssertionError that is raised when the inner MyException # does not contain the expected property with zest.raises(AssertionError) as outer_e: with zest.raises(MyException, in_foo="blah") as e: raise MyException(foo="bar") assert isinstance(e, TrappedException) and isinstance( e.exception, MyException) assert "exception to have" in str(outer_e.exception)
def it_raises_on_nans(): chcy_ims, calib = _setup(1.0) with zest.raises(ValueError, in_args="nan"): nan_chcy_ims = np.full_like(chcy_ims, np.nan) worker._regional_balance_chcy_ims(nan_chcy_ims, calib) with zest.raises(ValueError, in_args="nan"): calib[f"regional_bg_mean.instrument_channel[0]"][0][0] = np.nan worker._regional_balance_chcy_ims(chcy_ims, calib)
def it_checks_lists(): l = [1, 2, 3] check.list_t(l, int) l = [1, 2, 3, 4.0] with zest.raises(check.CheckError): check.list_t(l, int) t = (1, 2, 3) with zest.raises(check.CheckError): check.list_t(t, int)
def it_validates_recursively(): test_s = s( s.is_dict(elems=dict( a=s.is_int(), b=s.is_list(required=True, elems=s.is_str()), c=s.is_dict(required=True), ))) test_s.validate(dict(a=1, b=["a", "b"], c=dict())) with zest.raises(SchemaValidationFailed): test_s.validate(dict(a=1, b=[1], c=dict())) with zest.raises(SchemaValidationFailed): test_s.validate(dict(a=1, b=["a"], c=1))
def it_checks_lists_or_tuples(): l = [1, 2, 3] check.list_or_tuple_t(l, int) t = (1, 2, 3) check.list_or_tuple_t(t, int) l = [1, 2, 3.0] with zest.raises(check.CheckError): check.list_or_tuple_t(l, int) t = (1, 2, 3.0) with zest.raises(check.CheckError): check.list_or_tuple_t(t, int)
def it_raises_on_bad_fasta(): fasta_str = """ MKSGSGGGSPTSLWGLLFLSAALSLWPTSGEICGPGIDIRNDYQQLKRLENCTVIEGYLH """ with zest.raises(ValueError) as e: uniprot.fasta_split(fasta_str) assert "data before the header" in str(e.exception)
def it_raises_on_duplicate_sequences(): with zest.mock(_error) as m_error: with zest.raises(ValueError): pro_spec_df = pd.DataFrame( dict(name=["name1", "name2"], sequence=["ABC", "ABC"])) _step_1_check_for_uniqueness(pro_spec_df) assert m_error.called()
def _it_validates_noneable(schema_func): test_s = s(schema_func()) with zest.raises(SchemaValidationFailed): test_s.validate(None) test_s = s(schema_func(noneable=True)) test_s.validate(None)
def it_ignores_underscored_keys(): test_s = s( s.is_dict(elems=dict(a=s.is_int(), b=s.is_int()), no_extras=True)) with zest.raises(SchemaValidationFailed): test_s.validate(dict(a=1, b="str")) with zest.raises(SchemaValidationFailed): test_s.validate(dict(a=1, b=2, _c=[])) test_s = s( s.is_dict( elems=dict(a=s.is_int(), b=s.is_int()), no_extras=True, ignore_underscored_keys=True, )) test_s.validate(dict(a=1, b=2, _c=[]))
def it_raises_if_no_seq_nor_uniprot_ac(): csv_string = """ Name, Abundance A, 10 """ with zest.raises(ValueError) as e: helpers.protein_csv_df(csv_string) assert "missing either a Seq or a UniprotAC" in str(e.exception)
def it_raises_if_no_name_and_no_uniprot_ac(): csv_string = """ Seq, Abundance ABC, 10 """ with zest.raises(ValueError) as e: helpers.protein_csv_df(csv_string) assert "missing a Name column" in str(e.exception)
def it_raises_on_bad_argument_local(): with zest.raises(check.CheckError) as e: @check.args def myfunc(a: str, b): assert isinstance(a, str) myfunc(1, 2)
def it_raises_if_both_seq_and_uniprot_ac(): csv_string = """ Name, Seq, UniprotAC P1, A, P100 """ with zest.raises(ValueError) as e: helpers.protein_csv_df(csv_string) assert "both a Seq and a UniprotAC" in str(e.exception)
def it_raises_on_duplicate_seqs(): csv_string = """ Name, Seq P1, ABC P2, ABC """ with zest.raises(ValueError) as e: helpers.protein_csv_df(csv_string) assert "duplicate seqs" in str(e.exception)
def it_validates_allow_empty_string(): test_s = s(s.is_str(allow_empty_string=False)) test_s.validate("test") with zest.raises(SchemaValidationFailed): test_s.validate("") test_s = s(s.is_str()) test_s.validate("test") test_s.validate("")
def it_bubbles_exceptions(): with zest.mock(zap._show_work_order_exception) as m_ex: with zest.raises(ValueError): work_orders[0].fn = test2 zap.work_orders( work_orders, _process_mode=True, _trap_exceptions=False, ) assert m_ex.called_once()
def it_raises_if_not_a_df_return(): with zest.raises(TypeError): df = pd.DataFrame(dict(a=[1, 2], b=[3, 4])) zap.df_rows( test7, df, c=3, _batch_size=2, _debug_mode=True, )
def it_raises_on_incorrect_arguments(): bad_schemes = ["/C,M,Y", "a/b/c", "", "protease/"] for bad_scheme in bad_schemes: gen = gen_klass( n_edmans=1, label_set=[], protease=[], scheme=[bad_scheme], ) with zest.raises(): perms = list(gen.run_parameter_permutator())
def it_applies_defaults_recursively(): test = dict(a=1, c=dict(e=10)) with zest.raises(SchemaValidationFailed): test_s.validate(test) test_s.apply_defaults(dict(a=2, b=3, c=dict(d=4)), apply_to=test) assert test["a"] == 1 assert test["b"] == 3 assert test["c"]["d"] == 4 assert test["c"]["e"] == 10 test_s.validate(test)
def it_raises_on_begin(): # _begin is easily confused with "_before" so there's a special check for it with zest.raises(ValueError, in_args="_before"): def _begin(): # Should have been "_before" pass def test1(): pass zest()
def it_catches_non_sequential_dyt_iz_in_dyepeps(): _dyepeps = np.array( [ [1, 1, 10], [2, 1, 10], [1, 2, 30], ], dtype=np.uint64, ) radmat, true_dyt_iz, true_ks = synthetic_radmat_from_dyemat( dyemat, priors, n_channels=1, n_samples=5) with zest.raises(CException, in_args="Non sequential dyt_i"): _test(radmat, _dyepeps=_dyepeps)
def it_enforces_reverse_sort_on_count_per_dyt(): _dyepeps = np.array( [ [1, 1, 10], [1, 2, 30], ], dtype=np.uint64, ) radmat, true_dyt_iz, true_ks = synthetic_radmat_from_dyemat( dyemat, priors, n_channels=1, n_samples=5) with zest.raises(CException, in_args="must be reverse sorted by count per dyt"): _test(radmat, _dyepeps=_dyepeps)
def it_raises_if_not_symbol(): with zest.raises(ValueError): assets.validate_job_folder("foo bar")
def it_raises_on_out_of_range_count(): with zest.raises(ValueError): gen._label_str_permutate("A,B,CD: 4") with zest.raises(ValueError): gen._label_str_permutate("A,B,CD: -1")