Best Python code snippet using pandera_python
test_decorators.py
Source: test_decorators.py
...443def test_check_types_error_output() -> None:444 """Test that check_types raises an error when the output is not correct."""445 df = pd.DataFrame({"a": [1]}, index=["1"])446 @check_types447 def transform_derived(448 df: DataFrame[InSchema],449 ) -> DataFrame[DerivedOutSchema]:450 return df451 with pytest.raises(452 errors.SchemaError, match="column 'b' not in dataframe"453 ):454 transform_derived(df)455 try:456 transform_derived(df)457 except errors.SchemaError as exc:458 assert exc.schema == DerivedOutSchema.to_schema()459 assert exc.data.equals(df)460 df = pd.DataFrame({"a": [1]}, index=["1"])461 @check_types462 def transform(df: DataFrame[InSchema]) -> DataFrame[OutSchema]:463 return df464 with pytest.raises(465 errors.SchemaError, match="column 'b' not in dataframe"466 ):467 transform(df)468 try:469 transform(df)470 except errors.SchemaError as exc:471 assert exc.schema == OutSchema.to_schema()472 assert exc.data.equals(df)473def test_check_types_optional_out() -> None:474 """Test the check_types behaviour when the output schema is Optional."""475 @check_types476 def optional_derived_out(477 df: DataFrame[InSchema], # pylint: disable=unused-argument478 ) -> typing.Optional[DataFrame[DerivedOutSchema]]:479 return None480 df = pd.DataFrame({"a": [1]}, index=["1"])481 assert optional_derived_out(df) is None482 @check_types483 def optional_out(484 df: DataFrame[InSchema], # pylint: disable=unused-argument485 ) -> typing.Optional[DataFrame[OutSchema]]:486 return None487 df = pd.DataFrame({"a": [1]}, index=["1"])488 assert optional_out(df) is None489def test_check_types_optional_in() -> None:490 """Test the check_types behaviour when the input schema is Optional."""491 @check_types492 def optional_in(493 # pylint: disable=unused-argument494 df: typing.Optional[DataFrame[InSchema]],495 ) -> None:496 return None497 assert optional_in(None) is None498def test_check_types_optional_in_out() -> None:499 """500 Test the check_types behaviour when both input and outputs schemas are501 Optional.502 """503 @check_types504 def transform_derived(505 # pylint: disable=unused-argument506 df: typing.Optional[DataFrame[InSchema]],507 ) -> typing.Optional[DataFrame[DerivedOutSchema]]:508 return None509 assert transform_derived(None) is None510 @check_types511 def transform(512 # pylint: disable=unused-argument513 df: typing.Optional[DataFrame[InSchema]],514 ) -> typing.Optional[DataFrame[OutSchema]]:515 return None516 assert transform(None) is None517def test_check_types_coerce() -> None:518 """Test that check_types return the result of validate."""519 @check_types()520 def transform_in(df: DataFrame[InSchema]):521 return df522 df = transform_in(pd.DataFrame({"a": ["1"]}, index=["1"]))523 expected = InSchema.to_schema().columns["a"].dtype...
Check out the latest blogs from LambdaTest on this topic:
I routinely come across test strategy documents when working with customers. They are lengthy—100 pages or more—and packed with monotonous text that is routinely reused from one project to another. Yawn once more— the test halt and resume circumstances, the defect management procedure, entrance and exit criteria, unnecessary generic risks, and in fact, one often-used model replicates the requirements of textbook testing, from stress to systems integration.
When I started writing tests with Cypress, I was always going to use the user interface to interact and change the application’s state when running tests.
Pair testing can help you complete your testing tasks faster and with higher quality. But who can do pair testing, and when should it be done? And what form of pair testing is best for your circumstance? Check out this blog for more information on how to conduct pair testing to optimize its benefits.
People love to watch, read and interact with quality content — especially video content. Whether it is sports, news, TV shows, or videos captured on smartphones, people crave digital content. The emergence of OTT platforms has already shaped the way people consume content. Viewers can now enjoy their favorite shows whenever they want rather than at pre-set times. Thus, the OTT platform’s concept of viewing anything, anytime, anywhere has hit the right chord.
Have you ever visited a website that only has plain text and images? Most probably, no. It’s because such websites do not exist now. But there was a time when websites only had plain text and images with almost no styling. For the longest time, websites did not focus on user experience. For instance, this is how eBay’s homepage looked in 1999.
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!!