How to use test_to_yaml method in pandera

Best Python code snippet using pandera_python

test_base.py

Source:test_base.py Github

copy

Full Screen

...51 with self.assertWarns(RuntimeWarning):52 error = base.ErrorValue(1.0, "resolution", "FWHM", "undefined")53 with self.assertRaises(NotImplementedError):54 error.sigma55 def test_to_yaml(self):56 """57 Transform to yaml.58 """59 error = base.ErrorValue(1.0)60 assert error.to_yaml() == "{error_value: 1.0}\n"61 def test_no_value_to_yaml(self):62 """63 Transform to yaml with a non-optional ORSO item.64 """65 error = base.ErrorValue(None)66 assert error.to_yaml() == "{error_value: null}\n"67 def test_optionals_to_yaml(self):68 """69 Transform to yaml.70 """71 error = base.ErrorValue(1.0)72 assert error.to_yaml() == "{error_value: 1.0}\n"73 def test_user_data(self):74 error = base.ErrorValue(13.4, my_attr="hallo ORSO")75 assert error.user_data == {"my_attr": "hallo ORSO"}76class TestValue(unittest.TestCase):77 """78 Testing the Value class.79 """80 def test_single_value(self):81 """82 Creation of an object with a magnitude and unit.83 """84 value = base.Value(1.0, "m")85 assert value.magnitude == 1.086 assert value.unit == "m"87 def test_list_warning(self):88 """89 Creation of an object with a a list of values and a unit.90 """91 with self.assertWarns(RuntimeWarning):92 base.Value([1, 2, 3], "m")93 def test_bad_unit(self):94 """95 Rejection of non-ASCII units.96 """97 with self.assertRaises(ValueError):98 _ = base.Value(1.0, "Å")99 def test_to_yaml(self):100 """101 Transform to yaml.102 """103 value = base.Value(1.0, "m")104 assert value.to_yaml() == "{magnitude: 1.0, unit: m}\n"105 def test_no_magnitude_to_yaml(self):106 """107 Transform to yaml with a non-optional ORSO item.108 """109 value = base.Value(None)110 assert value.to_yaml() == "{magnitude: null}\n"111 def test_user_data(self):112 value = base.Value(13.4, my_attr="hallo ORSO")113 assert value.user_data == {"my_attr": "hallo ORSO"}114 def test_unit_conversion(self):115 value = base.Value(1.0, "mm")116 assert value.as_unit("m") == 1.0e-3117 value = base.Value(1.0, "1/nm^3")118 assert value.as_unit("1/angstrom^3") == 1.0e-3119 with self.assertRaises(pint.DimensionalityError):120 value = base.Value(1.0, "1/nm^3")121 value.as_unit("m")122class TestComplexValue(unittest.TestCase):123 """124 Testing the Value class.125 """126 def test_single_value(self):127 """128 Creation of an object with a magnitude and unit.129 """130 value = base.ComplexValue(1.0, 2.0, "m")131 assert value.real == 1.0132 assert value.imag == 2.0133 assert value.unit == "m"134 def test_list_warning(self):135 """136 Creation of an object with a a list of values and a unit.137 """138 with self.assertWarns(RuntimeWarning):139 base.ComplexValue([1, 2, 3], [1, 2, 3], "m")140 def test_bad_unit(self):141 """142 Rejection of non-ASCII units.143 """144 with self.assertRaises(ValueError):145 _ = base.ComplexValue(1.0, 2.0, "Å")146 def test_to_yaml(self):147 """148 Transform to yaml.149 """150 value = base.ComplexValue(1.0, 2.0, "m")151 assert value.to_yaml() == "{real: 1.0, imag: 2.0, unit: m}\n"152 def test_no_magnitude_to_yaml(self):153 """154 Transform to yaml with a non-optional ORSO item.155 """156 value = base.ComplexValue(None)157 assert value.to_yaml() == "{real: null}\n"158 def test_unit_conversion(self):159 value = base.ComplexValue(1.0, 2.0, "mm")160 assert value.as_unit("m") == 1.0e-3 + 2.0e-3j161 value = base.ComplexValue(1.0, 2.0, "1/nm^3")162 assert value.as_unit("1/angstrom^3") == 1.0e-3 + 2.0e-3j163 with self.assertRaises(pint.DimensionalityError):164 value = base.ComplexValue(1.0, 2.0, "1/nm^3")165 value.as_unit("m")166class TestValueVector(unittest.TestCase):167 """168 Testing the ValueVector class169 """170 def test_single_value(self):171 """172 Creation of an object with three dimensions and unit.173 """174 value = base.ValueVector(1, 2, 3, "m")175 assert value.x == 1176 assert value.y == 2177 assert value.z == 3178 assert value.unit == "m"179 def test_list_warns(self):180 """181 Creation of an object with three dimensions of lists and unit.182 """183 with self.assertWarns(RuntimeWarning):184 base.ValueVector([1, 2], [2, 3], [3, 4], "m")185 def test_bad_unit(self):186 """187 Rejection of non-ASCII unit.188 """189 with self.assertRaises(ValueError):190 _ = base.ValueVector(1, 2, 3, "Å")191 def test_to_yaml(self):192 """193 Transform to yaml.194 """195 value = base.ValueVector(1.0, 2.0, 3.0, "m")196 assert value.to_yaml() == "{x: 1.0, y: 2.0, z: 3.0, unit: m}\n"197 def test_two_dimensional_to_yaml(self):198 """199 Transform to yaml with only two dimensions.200 """201 value = base.ValueVector(1.0, 2.0, None, "m")202 assert value.to_yaml() == "{x: 1.0, y: 2.0, z: null, unit: m}\n"203 def test_unit_conversion(self):204 value = base.ValueVector(1.0, 2.0, 3.0, "mm")205 assert value.as_unit("m") == (1.0e-3, 2.0e-3, 3.0e-3)206 value = base.ValueVector(1.0, 2.0, 3.0, "1/nm^3")207 assert value.as_unit("1/angstrom^3") == (1.0e-3, 2.0e-3, 3.0e-3)208 with self.assertRaises(pint.DimensionalityError):209 value = base.ValueVector(1.0, 2.0, 3.0, "1/m")210 value.as_unit("m")211class TestValueRange(unittest.TestCase):212 """213 Testing the ValueRange class214 """215 def test_single_value(self):216 """217 Creation of an object with a max, min and unit.218 """219 value = base.ValueRange(1.0, 2.0, "m")220 assert value.min == 1221 assert value.max == 2222 assert value.unit == "m"223 def test_list_warns(self):224 """225 Creation of an object of a list of max and list of min and a unit.226 """227 with self.assertWarns(RuntimeWarning):228 base.ValueRange([1, 2, 3], [2, 3, 4], "m")229 def test_bad_unit(self):230 """231 Rejection of non-ASCII unit.232 """233 with self.assertRaises(ValueError):234 _ = base.ValueRange(1.0, 2.0, "Å")235 def test_to_yaml(self):236 """237 Transform to yaml.238 """239 value = base.ValueRange(1.0, 2.0, "m")240 assert value.to_yaml() == "{min: 1.0, max: 2.0, unit: m}\n"241 def test_no_upper_to_yaml(self):242 """243 Transform to yaml with no max.244 """245 value = base.ValueRange(1.0, None)246 assert value.to_yaml() == "{min: 1.0, max: null}\n"247 def test_no_lower_to_yaml(self):248 """249 Transform to yaml with no min.250 """251 value = base.ValueRange(None, 1.0)252 assert value.to_yaml() == "{min: null, max: 1.0}\n"253 def test_unit_conversion(self):254 value = base.ValueRange(1.0, 2.0, "mm")255 assert value.as_unit("m") == (1.0e-3, 2.0e-3)256 value = base.ValueRange(1.0, 2.0, "1/nm^3")257 assert value.as_unit("1/angstrom^3") == (1.0e-3, 2.0e-3)258 with self.assertRaises(pint.DimensionalityError):259 value = base.ValueRange(1.0, 2.0, "1/m")260 value.as_unit("m")261class TestPerson(unittest.TestCase):262 """263 Testing the Person class264 """265 def test_creation(self):266 """267 Creation with no email.268 """269 value = base.Person("Joe A. User", "Ivy League University")270 assert value.name == "Joe A. User"271 assert value.affiliation == "Ivy League University"272 def test_creation_with_contact(self):273 """274 Creation with an email.275 """276 value = base.Person("Joe A. User", "Ivy League University", "jauser@ivy.edu")277 assert value.name == "Joe A. User"278 assert value.affiliation == "Ivy League University"279 assert value.contact == "jauser@ivy.edu"280 def test_creation_with_multiline(self):281 value = base.Person("Joe A. User", "\n".join(["Ivy League University", "Great Neutron Factory"]))282 assert value.name == "Joe A. User"283 assert value.affiliation == "\n".join(["Ivy League University", "Great Neutron Factory"])284 def test_to_yaml(self):285 """286 Transform to yaml with no email.287 """288 value = base.Person("Joe A. User", "Ivy League University")289 assert value.to_yaml() == "name: Joe A. User\naffiliation: Ivy League University\n"290 def test_no_affiliation_to_yaml(self):291 """292 Transform to yaml without affiliation.293 """294 value = base.Person("Joe A. User", None)295 assert value.to_yaml() == "name: Joe A. User\naffiliation: null\n"296 def test_no_name_to_yaml(self):297 """298 Transform to yaml without name.299 """300 value = base.Person(None, "A University")301 assert value.to_yaml() == "name: null\naffiliation: A University\n"302 def test_email_to_yaml(self):303 """304 Transform to yaml with an email.305 """306 value = base.Person("Joe A. User", "Ivy League University", "jauser@ivy.edu")307 assert (308 value.to_yaml() == "name: Joe A. User\naffiliation: Ivy League University" + "\ncontact: jauser@ivy.edu\n"309 )310class TestColumn(unittest.TestCase):311 """312 Testing the Column class313 """314 def test_creation(self):315 """316 Creation of a column.317 """318 value = base.Column("q", "1/angstrom", "qz vector")319 assert value.physical_quantity == "qz vector"320 assert value.name == "q"321 assert value.unit == "1/angstrom"322 def test_bad_unit(self):323 """324 Rejection of non-ASCII unit.325 """326 with self.assertRaises(ValueError):327 _ = base.Column("q", "Å", "qz vector")328 def test_to_yaml(self):329 """330 Transformation to yaml.331 """332 value = base.Column("q", "1/angstrom", "qz vector")333 assert value.to_yaml() == "{name: q, unit: 1/angstrom, physical_quantity: qz vector}\n"334 def test_no_description_to_yaml(self):335 """336 Transformation to yaml.337 """338 value = base.Column("q", "1/angstrom")339 assert value.to_yaml() == "{name: q, unit: 1/angstrom}\n"340class TestErrorColumn(unittest.TestCase):341 """342 Testing the Column class343 """344 def test_creation(self):345 """346 Creation of a column.347 """348 value = base.ErrorColumn("q", "uncertainty", "FWHM", "triangular")349 assert value.error_of == "q"350 assert value.error_type == "uncertainty"351 assert value.distribution == "triangular"352 assert value.value_is == "FWHM"353 value = base.ErrorColumn("q", "resolution", "sigma", "gaussian")354 assert value.error_of == "q"355 assert value.error_type == "resolution"356 assert value.distribution == "gaussian"357 assert value.value_is == "sigma"358 assert value.name == "sq"359 def test_bad_type(self):360 """361 Rejection of non-ASCII unit.362 """363 with self.assertWarns(RuntimeWarning):364 _ = base.ErrorColumn("q", "nm")365 def test_bad_distribution(self):366 """367 Rejection of non-ASCII unit.368 """369 with self.assertWarns(RuntimeWarning):370 _ = base.ErrorColumn("q", "uncertainty", "FWHM", "undefined")371 with self.assertWarns(RuntimeWarning):372 _ = base.ErrorColumn("q", "uncertainty", "HWHM", "triangular")373 with self.assertWarns(RuntimeWarning):374 _ = base.ErrorColumn("q", "uncertainty", "wrong")375 def test_to_yaml(self):376 """377 Transformation to yaml.378 """379 value = base.ErrorColumn("q", "uncertainty", "FWHM", "triangular")380 assert value.to_yaml() == "{error_of: q, error_type: uncertainty, value_is: FWHM, distribution: triangular}\n"381 def test_minimal_to_yaml(self):382 """383 Transformation to yaml.384 """385 value = base.ErrorColumn("q")386 assert value.to_yaml() == "{error_of: q}\n"387 def test_sigma_conversion(self):388 with self.subTest("gauss"):389 value = base.ErrorColumn("q", "uncertainty", "FWHM", "gaussian")...

Full Screen

Full Screen

test_testplan.py

Source:test_testplan.py Github

copy

Full Screen

...37 name="timeout1",38 timeout_units=Timeout.UNITS_MINUTES,39 timeout_value=140 )41 def test_to_yaml(self):42 reference_dict = {43 "timeout1": {Timeout.UNITS_MINUTES: 1}44 }45 self.assertEqual(self.timeout1.to_yaml(), reference_dict)46class TestJobMetadataTest(TestCase):47 def setUp(self):48 self.metadata1 = TestJobMetadata(49 name = "metadata1",50 metadata = "key1: value1"51 )52 def test_to_yaml(self):53 reference_dict = {54 "key1": "value1"55 }56 self.assertEqual(self.metadata1.to_yaml(), reference_dict)57class TestJobContextTest(TestCase):58 def setUp(self):59 self.context1 = TestJobContext(60 name = "context1",61 context = "key1: value1"62 )63 def test_to_yaml(self):64 reference_dict = {65 "key1": "value1"66 }67 self.assertEqual(self.context1.to_yaml(), reference_dict)68class DeployPostprocessTest(TestCase):69 def setUp(self):70 self.deploy1 = DeployPostprocess(71 name = "deploy1",72 image = "image_url",73 steps = "- step1\n- step2"74 )75 def test_to_yaml(self):76 reference_dict = {77 "docker": {78 "image": "image_url",79 "steps": ["step1", "step2"]80 }81 }82 self.assertEqual(self.deploy1.to_yaml(), reference_dict)83class DeploymentTest(TestCase):84 def setUp(self):85 self.downloadImage1 = DownloadImage(86 name="downloadimage1",87 url="https://example.com/image1",88 compression="gz",89 headers="HEADER1: VALUE1"90 )91 self.downloadImage1.save()92 self.downloadImage2 = DownloadImage(93 name="downloadimage2",94 url="https://example.com/image2",95 compression="gz",96 headers="HEADER1: VALUE1"97 )98 self.downloadImage2.save()99 self.deployPostprocess1 = DeployPostprocess(100 name = "deploypostprocess1",101 image = "image_url",102 steps = "- step1\n- step2"103 )104 self.deployPostprocess1.save()105 self.deployment1 = Deployment(106 deploy_to=Deployment.DEPLOY_DOWNLOADS,107 name="deploy1",108 postprocess=self.deployPostprocess1,109 action_type="deploy"110 )111 self.deployment1.save()112 self.deployment1.images.add(self.downloadImage1)113 self.deployment1.images.add(self.downloadImage2)114 def test_to_yaml(self):115 reference_dict = {116 "deploy": {117 "to": "downloads",118 "images": {119 "downloadimage1": {120 "url": "https://example.com/image1",121 "compression": "gz",122 "headers": {123 "HEADER1": "VALUE1"124 }125 },126 "downloadimage2": {127 "url": "https://example.com/image2",128 "compression": "gz",129 "headers": {130 "HEADER1": "VALUE1"131 }132 }133 },134 "postprocess": {135 "docker": {136 "image": "image_url",137 "steps": ["step1", "step2"]138 }139 },140 }141 }142 self.assertEqual(self.deployment1.to_yaml(), reference_dict)143 #ToDo: cover more deployment options144class AutoLoginTest(TestCase):145 def setUp(self):146 self.autoLogin1 = AutoLogin(147 login_prompt="login:",148 password_prompt="Password",149 username="user",150 password="secret",151 login_commands="- sudo su\n- secret",152 name="autologin1"153 )154 def test_to_yaml(self):155 reference_dict = {156 "login_prompt": "login:",157 "username": "user",158 "password_prompt": "Password",159 "password": "secret",160 "login_commands": ["sudo su", "secret"]161 }162 self.assertEqual(self.autoLogin1.to_yaml(), reference_dict)163class BootTest(TestCase):164 def setUp(self):165 self.maxDiff = None166 self.autoLogin1 = AutoLogin(167 login_prompt="login:",168 password_prompt="Password",169 username="user",170 password="secret",171 login_commands="- sudo su\n- secret",172 name="autologin1",173 )174 self.boot1 = Boot(175 name="boot1",176 method=Boot.METHOD_MINIMAL,177 transfer_overlay=True,178 transfer_overlay_download="cd /home ; wget",179 transfer_overlay_unpack="tar -C /home/fio -xzf",180 auto_login=self.autoLogin1,181 prompts="- \"Password:\"\n- root@imx8mmevk",182 action_type="boot"183 )184 def test_to_yaml(self):185 reference_dict = {186 "boot": {187 "prompts": ["Password:", "root@imx8mmevk"],188 "method": "minimal",189 "auto_login": {190 "login_prompt": "login:",191 "username": "user",192 "password_prompt": "Password",193 "password": "secret",194 "login_commands": ["sudo su", "secret"]195 },196 "transfer_overlay": {197 "download_command": "cd /home ; wget",198 "unpack_command": "tar -C /home/fio -xzf"199 }200 }201 }202 self.assertEqual(self.boot1.to_yaml(), reference_dict)203class TestDefinitionTests(TestCase):204 def setUp(self):205 self.testDefinition1 = TestDefinition(206 testtype=TestDefinition.TYPE_GIT,207 name="definition1",208 device_type="dev_type1",209 path="example/path",210 repository="https://example.com/git"211 )212 def test_to_yaml(self):213 reference_dict = {214 "repository": "https://example.com/git",215 "from": "git",216 "path": "example/path",217 "name": "definition1"218 }219 self.assertEqual(self.testDefinition1.to_yaml(), reference_dict)220 # ToDo: cover more cases: interactive, parameters221class TestActionTests(TestCase):222 def setUp(self):223 self.testDefinition1 = TestDefinition(224 testtype=TestDefinition.TYPE_GIT,225 name="definition1",226 device_type="dev_type1",227 path="example/path",228 repository="https://example.com/git",229 )230 self.testDefinition1.save()231 self.testDefinition2 = TestDefinition(232 testtype=TestDefinition.TYPE_GIT,233 name="definition2",234 device_type="dev_type1",235 path="example/path2",236 repository="https://example.com/git"237 )238 self.testDefinition2.save()239 self.timeout1 = Timeout(240 name="timeout1",241 timeout_units=Timeout.UNITS_MINUTES,242 timeout_value=1243 )244 self.timeout1.save()245 self.testAction1 = TestAction(246 name="testaction1",247 timeout=self.timeout1,248 action_type="test"249 )250 self.testAction1.save()251 self.testAction1.definitions.add(self.testDefinition1)252 self.testAction1.definitions.add(self.testDefinition2)253 self.testAction1.save()254 def test_to_yaml(self):255 reference_dict = {256 "test": {257 "definitions": 258 [{"from": "git",259 "name": "definition1",260 "path": "example/path",261 "repository": "https://example.com/git"},262 {"from": "git",263 "name": "definition2",264 "path": "example/path2",265 "repository": "https://example.com/git"}],266 "timeout": {"minutes": 1}267 }268 }...

Full Screen

Full Screen

test_yaml.py

Source:test_yaml.py Github

copy

Full Screen

1from dataclasses import dataclass2from typing import List3import yaml4from mashumaro.mixins.yaml import DataClassYAMLMixin5def test_to_yaml():6 @dataclass7 class DataClass(DataClassYAMLMixin):8 x: List[int]9 dumped = yaml.dump({"x": [1, 2, 3]})10 assert DataClass([1, 2, 3]).to_yaml() == dumped11def test_from_yaml():12 @dataclass13 class DataClass(DataClassYAMLMixin):14 x: List[int]15 dumped = yaml.dump({"x": [1, 2, 3]})...

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