How to use schema_simple method in pandera

Best Python code snippet using pandera_python

test_disallow_unknown_properties.py

Source:test_disallow_unknown_properties.py Github

copy

Full Screen

1from unittest import TestCase2import validictory3class TestDisallowUnknownProperties(TestCase):4 def setUp(self):5 self.data_simple = {"name": "john doe", "age": 42}6 self.schema_simple = {7 "type": "object",8 "properties": {9 "name": {"type": "string"},10 "age": {"type": "integer"}11 },12 }13 self.data_complex = {14 "inv_number": "123",15 "rows": [16 {17 "sku": "ab-456",18 "desc": "a description",19 "price": 100.4520 },21 {22 "sku": "xy-123",23 "desc": "another description",24 "price": 999.0025 }26 ]27 }28 self.schema_complex = {29 "type": "object",30 "properties": {31 "inv_number": {"type": "string"},32 "rows": {33 "type": "array",34 "items": {35 "sku": {"type": "string"},36 "desc": {"type": "string"},37 "price": {"type": "number"}38 },39 }40 }41 }42 def test_disallow_unknown_properties_pass(self):43 try:44 validictory.validate(self.data_simple, self.schema_simple,45 disallow_unknown_properties=True)46 except ValueError as e:47 self.fail("Unexpected failure: %s" % e)48 def test_disallow_unknown_properties_fail(self):49 self.data_simple["sex"] = "male"50 self.assertRaises(validictory.SchemaError, validictory.validate,51 self.data_simple, self.schema_simple,52 disallow_unknown_properties=True)53 def test_disallow_unknown_properties_complex_pass(self):54 try:55 validictory.validate(self.data_complex, self.schema_complex,56 disallow_unknown_properties=True)57 except ValueError as e:58 self.fail("Unexpected failure: %s" % e)59 def test_disallow_unknown_properties_complex_fail(self):60 newrow = {"sku": "789", "desc": "catch me if you can", "price": 1,61 "rice": 666}62 self.data_complex["rows"].append(newrow)63 self.assertRaises(validictory.SchemaError, validictory.validate,64 self.data_complex, self.schema_complex,...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run pandera automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful