Best Python code snippet using pandera_python
test_decorators.py
Source:test_decorators.py  
...172    in_schema = DataFrameSchema({"column1": Column(int, coerce=True)})173    out_schema = DataFrameSchema({"column2": Column(float, coerce=True)})174    @check_input(in_schema)175    @check_output(out_schema)176    def test_func_io(df):177        return df.assign(column2=10)178    @check_input(in_schema)179    @check_output(out_schema, obj_getter=1)180    def test_func_out_tuple_obj_getter(df):181        return None, df.assign(column2=10)182    @check_input(in_schema)183    @check_output(out_schema, obj_getter=1)184    def test_func_out_list_obj_getter(df):185        return None, df.assign(column2=10)186    @check_input(in_schema)187    @check_output(out_schema, obj_getter="key")188    def test_func_out_dict_obj_getter(df):189        return {"key": df.assign(column2=10)}190    cases: typing.Iterable[...manualtest.py
Source:manualtest.py  
...18        return None19    except Exception as e:20        raise AssertionError(f"Value raised was '{e}' (not private error)")21    raise AssertionError("No value was raised")22def test_func_io(func: Callable[[T], O], arg: T, expect: O) -> None:23    assert func(arg) == expect, f"func({arg=})={func(arg)} != {expect=}"24def try_or_return(func: Callable[[], Optional[Iterable[Exception]]]) -> Callable[[], Optional[Iterable[Exception]]]:25    def wrapped() -> Optional[Iterable[Exception]]:26        try:27            return func()28        except Exception as e:29            return [e]30    return wrapped31@try_or_return32def test_parse_duration() -> Optional[Iterable[Exception]]:33    from lib_goparsers import ParseDurationSuper34    WEEK: Final = 7 * 24 * 60 * 6035    DAY: Final = 24 * 60 * 6036    HOUR: Final = 60 * 6037    MINUTE: Final = 6038    SECOND: Final = 139    tests = (40        [41            # "Real user" tests, general correctness42            ("123", 123),43            ("5minutes", 5 * MINUTE),44            ("45s", 45),45            ("s", 1),46            # Various rejection paths47            ("5monite", None),48            ("sfgdsgf", None),49            ("minutes5", None),50            ("5seconds4", None),51            ("seconds5m", None),52            ("", None),53            ("josh", None),54            ("seconds5seconds", None),55            ("1w1wday", None),56            ("1day2weeks7dam", None),57            # Test all unit names have correct outputs58            ("1w1week1weeks", 3 * WEEK),59            ("1d1day1days", 3 * DAY),60            ("1h1hour1hours", 3 * HOUR),61            ("1m1minute1minutes", 3 * MINUTE),62            ("1s1second1seconds", 3 * SECOND),63            # Test all single unit cases64            ("week", WEEK),65            ("w", WEEK),66            ("day", DAY),67            ("d", DAY),68            ("hour", HOUR),69            ("h", HOUR),70            ("minute", MINUTE),71            ("m", MINUTE),72            ("second", SECOND),73            ("s", SECOND),74            # Test for floating point accuracy75            (f"{(1<<54)+1}m1s", ((1 << 54) + 1) * 60 + 1),76            ("4.5h", 4 * HOUR + 30 * MINUTE),77            ("4.7h", 4 * HOUR + (7 * HOUR // 10)),78            ("3.5d7.3m", 3 * DAY + 12 * HOUR + 7 * MINUTE + (3 * MINUTE // 10)),79            # Test for fp parse rejection80            ("5.6.34seconds", None),81            # Test fractions82            ("3/6days", 12 * HOUR),83            ("1/0", None),84            ("0/0", None),85            ("17/60m", 17 * SECOND),86            ("13/24d1/0w", None),87            (f"{(1<<54)+2}/2d", (((1 << 54) + 2) * DAY) // 2),88            ]89        )90    out = []91    for i in tests:92        try:93            test_func_io(ParseDurationSuper, i[0], i[1])94        except AssertionError as e:95            out.append(e)96    if out: return out97    else:98        return None99@try_or_return100def test_ramfs() -> Optional[Iterable[Exception]]:101    from contextlib import redirect_stdout, redirect_stderr102    sink = io.StringIO()103    # Reroute stderr and stdout to ignore import warnings from main104    with redirect_stdout(sink):105        with redirect_stderr(sink):106            from main import ram_filesystem  # pylint: disable=E0401107    testfs = ram_filesystem()...main.py
Source:main.py  
...16    17### Each of these routines is a test to verify some aspect of the code18#test_func_scaler()19#test_func_pca()20#test_func_io()21#test_func_holistic(10)22#test_func_regressor(31)23### This is an example of a full run of the program:24# - First, we generate a number of datasets with a random distribution25#   of starting points but which use the same reaction rate26number_of_datasets = 10027input_data = test_func_create_dataset_simple_2(number_of_datasets)28# - Next, we select the number of principle components we wish to retain29#   (currently, must be equal to number of species, i.e. no reduction)30n_comp = 331# - Finally, we run the regression example...Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
