Ejemplo n.º 1
0
 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([])
Ejemplo n.º 2
0
 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=())
Ejemplo n.º 3
0
 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"])
Ejemplo n.º 4
0
 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)
Ejemplo n.º 5
0
 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()
Ejemplo n.º 6
0
 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)
Ejemplo n.º 7
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)
Ejemplo n.º 8
0
    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)
Ejemplo n.º 9
0
    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)
Ejemplo n.º 10
0
 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))
Ejemplo n.º 11
0
    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)
Ejemplo n.º 12
0
 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)
Ejemplo n.º 13
0
 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()
Ejemplo n.º 14
0
    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)
Ejemplo n.º 15
0
            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=[]))
Ejemplo n.º 16
0
 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)
Ejemplo n.º 17
0
 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)
Ejemplo n.º 18
0
    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)
Ejemplo n.º 19
0
 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)
Ejemplo n.º 20
0
 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)
Ejemplo n.º 21
0
            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("")
Ejemplo n.º 22
0
 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()
Ejemplo n.º 23
0
 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,
         )
Ejemplo n.º 24
0
 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())
Ejemplo n.º 25
0
        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)
Ejemplo n.º 26
0
    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()
Ejemplo n.º 27
0
 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)
Ejemplo n.º 28
0
 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)
Ejemplo n.º 29
0
 def it_raises_if_not_symbol():
     with zest.raises(ValueError):
         assets.validate_job_folder("foo bar")
Ejemplo n.º 30
0
 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")