How to use invalid_test method in hypothesis

Best Python code snippet using hypothesis

test_serializers.py

Source: test_serializers.py Github

copy

Full Screen

...11 """12 user = None13 serializer_class = Serializer14 data_dicts = {"invalid": [], "valid": []}15 def invalid_test(self):16 """An invalid serializer should raise ``ValidationError``.17 """18 for invalid_dict in self.data_dicts["invalid"]:19 if self.user:20 if issubclass(self.serializer_class, ModelSerializer):21 serializer = self.serializer_class(22 self.user, data=invalid_dict["data"]23 )24 else:25 serializer = self.serializer_class(26 user=self.user, data=invalid_dict["data"]27 )28 else:29 serializer = self.serializer_class(data=invalid_dict["data"])30 self.assertFalse(serializer.is_valid())31 self.assertEqual(32 serializer.errors[invalid_dict["error"][0]],33 invalid_dict["error"][1],34 )35 def valid_test(self):36 """A valid serializer should return ``True``.37 """38 for valid_dict in self.data_dicts["valid"]:39 if self.user:40 if issubclass(self.serializer_class, ModelSerializer):41 serializer = self.serializer_class(42 self.user, data=valid_dict43 )44 else:45 serializer = self.serializer_class(46 user=self.user, data=valid_dict47 )48 else:49 serializer = self.serializer_class(data=valid_dict)50 self.assertTrue(serializer.is_valid())51class LoginSerializerTests(SerializerTestCase):52 """Tests for :class:`LoginSerializer53 <manifest.serializers.LoginSerializer>`.54 """55 serializer_class = serializers.LoginSerializer56 data_dicts = data_dicts.LOGIN_SERIALIZER57 def test_invalid_serializer(self):58 self.invalid_test()59 def test_valid_serializer(self):60 self.valid_test()61class RegisterSerializerTests(SerializerTestCase):62 """Tests for :class:`RegisterSerializer63 <manifest.serializers.RegisterSerializer>`.64 """65 serializer_class = serializers.RegisterSerializer66 data_dicts = data_dicts.REGISTER_SERIALIZER67 def test_invalid_serializer(self):68 self.invalid_test()69 def test_valid_serializer(self):70 self.valid_test()71class PasswordResetSerializerTests(SerializerTestCase):72 """Tests for :class:`PasswordResetSerializer73 <manifest.serializers.PasswordResetSerializer>`.74 """75 serializer_class = serializers.PasswordResetSerializer76 data_dicts = data_dicts.PASSWORD_RESET_SERIALIZER77 def test_invalid_serializer(self):78 self.invalid_test()79 def test_valid_serializer(self):80 self.valid_test()81class PasswordChangeSerializerTests(SerializerTestCase):82 """Tests for :class:`PasswordChangeSerializer83 <manifest.serializers.PasswordChangeSerializer>`.84 """85 serializer_class = serializers.PasswordChangeSerializer86 data_dicts = data_dicts.PASSWORD_CHANGE_SERIALIZER87 def setUp(self):88 self.user = get_user_model().objects.get(pk=1)89 super(PasswordChangeSerializerTests, self).setUp()90 def test_invalid_serializer(self):91 self.invalid_test()92 def test_valid_serializer(self):93 self.valid_test()94class EmailChangeSerializerTests(SerializerTestCase):95 """Tests for :class:`EmailChangeSerializer96 <manifest.serializers.EmailChangeSerializer>`.97 """98 serializer_class = serializers.EmailChangeSerializer99 data_dicts = data_dicts.EMAIL_CHANGE_SERIALIZER100 def setUp(self):101 self.user = get_user_model().objects.get(pk=1)102 super(EmailChangeSerializerTests, self).setUp()103 def test_invalid_serializer(self):104 self.invalid_test()105 def test_valid_serializer(self):106 self.valid_test()107class ProfileUpdateSerializerTests(SerializerTestCase):108 """Tests for :class:`ProfileUpdateSerializer109 <manifest.serializers.ProfileUpdateSerializer>`.110 """111 serializer_class = serializers.ProfileUpdateSerializer112 data_dicts = data_dicts.PROFILE_UPDATE_SERIALIZER113 def setUp(self):114 self.user = get_user_model().objects.get(pk=1)115 super(ProfileUpdateSerializerTests, self).setUp()116 def test_invalid_serializer(self):117 self.invalid_test()118 def test_valid_serializer(self):119 self.valid_test()120class RegionUpdateSerializerTests(SerializerTestCase):121 """Tests for :class:`RegionUpdateSerializer122 <manifest.serializers.RegionUpdateSerializer>`.123 """124 serializer_class = serializers.RegionUpdateSerializer125 data_dicts = data_dicts.REGION_UPDATE_SERIALIZER126 def setUp(self):127 self.user = get_user_model().objects.get(pk=1)128 super().setUp()129 def test_invalid_serializer(self):130 self.invalid_test()131 def test_valid_serializer(self):132 self.valid_test()133# pylint: disable=too-many-ancestors134class PictureUploadSerializerTests(SerializerTestCase, ManifestUploadTestCase):135 """Tests for :class:`PictureUploadSerializer136 <manifest.serializers.PictureUploadSerializer>`.137 """138 serializer_class = serializers.PictureUploadSerializer139 data_dicts = None140 def setUp(self):141 self.user = get_user_model().objects.get(pk=1)142 super().setUp()143 self.data_dicts = data_dicts.picture_upload_serializer(self)144 def test_invalid_serializer(self):145 self.invalid_test()146 def test_valid_serializer(self):147 self.valid_test()148 def test_file_size(self):149 with self.upload_limit():150 serializer = self.serializer_class(151 self.user, data=self.data_dicts["invalid_file_size"]["data"]152 )153 serializer.is_valid()154 self.assertEqual(155 serializer.errors[156 self.data_dicts["invalid_file_size"]["error"][0]157 ],158 self.data_dicts["invalid_file_size"]["error"][1],159 )...

Full Screen

Full Screen

test_config.py

Source: test_config.py Github

copy

Full Screen

1import os2import sys3import unittest4from ray_release.config import (5 read_and_validate_release_test_collection,6 Test,7 validate_release_test_collection,8)9from ray_release.exception import ReleaseTestConfigError10class ConfigTest(unittest.TestCase):11 def setUp(self) -> None:12 self.test_collection_file = os.path.join(13 os.path.dirname(__file__), "..", "..", "release_tests.yaml"14 )15 self.valid_test = Test(16 **{17 "name": "validation_test",18 "group": "validation_group",19 "working_dir": "validation_dir",20 "legacy": {21 "test_name": "validation_test",22 "test_suite": "validation_suite",23 },24 "python": "3.7",25 "frequency": "nightly",26 "team": "release",27 "cluster": {28 "cluster_env": "app_config.yaml",29 "cluster_compute": "tpl_cpu_small.yaml",30 "autosuspend_mins": 10,31 },32 "run": {33 "timeout": 100,34 "script": "python validate.py",35 "wait_for_nodes": {"num_nodes": 2, "timeout": 100},36 "type": "client",37 },38 "smoke_test": {"run": {"timeout": 20}, "frequency": "multi"},39 "alert": "default",40 }41 )42 def testSchemaValidation(self):43 test = self.valid_test.copy()44 validate_release_test_collection([test])45 # Remove some optional arguments46 del test["alert"]47 del test["python"]48 del test["run"]["wait_for_nodes"]49 del test["cluster"]["autosuspend_mins"]50 validate_release_test_collection([test])51 # Add some faulty arguments52 # Faulty frequency53 invalid_test = test.copy()54 invalid_test["frequency"] = "invalid"55 with self.assertRaises(ReleaseTestConfigError):56 validate_release_test_collection([invalid_test])57 # Faulty job type58 invalid_test = test.copy()59 invalid_test["run"]["type"] = "invalid"60 with self.assertRaises(ReleaseTestConfigError):61 validate_release_test_collection([invalid_test])62 # Faulty file manager type63 invalid_test = test.copy()64 invalid_test["run"]["file_manager"] = "invalid"65 with self.assertRaises(ReleaseTestConfigError):66 validate_release_test_collection([invalid_test])67 # Faulty smoke test68 invalid_test = test.copy()69 del invalid_test["smoke_test"]["frequency"]70 with self.assertRaises(ReleaseTestConfigError):71 validate_release_test_collection([invalid_test])72 # Faulty Python version73 invalid_test = test.copy()74 invalid_test["python"] = "invalid"75 with self.assertRaises(ReleaseTestConfigError):76 validate_release_test_collection([invalid_test])77 def testLoadAndValidateTestCollectionFile(self):78 read_and_validate_release_test_collection(self.test_collection_file)79if __name__ == "__main__":80 import pytest...

Full Screen

Full Screen

test_modify_inner_test.py

Source: test_modify_inner_test.py Github

copy

Full Screen

...38test_can_replace_when_parametrized.hypothesis.inner_test = always_passes39def test_can_replace_when_original_is_invalid():40 # Invalid: @given with too many positional arguments41 @given(st.integers(), st.integers())42 def invalid_test(x):43 raise AssertionError44 invalid_test.hypothesis.inner_test = always_passes45 # Even after replacing the inner test, calling the wrapper should still46 # fail.47 with pytest.raises(InvalidArgument, match="Too many positional arguments"):48 invalid_test()49def test_inner_is_original_even_when_invalid():50 def invalid_test(x):51 raise AssertionError52 original = invalid_test53 # Invalid: @given with no arguments54 invalid_test = given()(invalid_test)55 # Verify that the test is actually invalid56 with pytest.raises(57 InvalidArgument,58 match="given must be called with at least one argument",59 ):60 invalid_test()61 assert invalid_test.hypothesis.inner_test == original62def test_invokes_inner_function_with_args_by_name():63 # Regression test for https:/​/​github.com/​HypothesisWorks/​hypothesis/​issues/​324564 @given(st.integers())65 def test(x):66 pass67 f = test.hypothesis.inner_test68 test.hypothesis.inner_test = wraps(f)(lambda **kw: f(**kw))...

Full Screen

Full Screen

Blogs

Check out the latest blogs from LambdaTest on this topic:

Joomla Testing Guide: How To Test Joomla Websites

Before we discuss the Joomla testing, let us understand the fundamentals of Joomla and how this content management system allows you to create and maintain web-based applications or websites without having to write and implement complex coding requirements.

Now Log Bugs Using LambdaTest and DevRev

In today’s world, an organization’s most valuable resource is its customers. However, acquiring new customers in an increasingly competitive marketplace can be challenging while maintaining a strong bond with existing clients. Implementing a customer relationship management (CRM) system will allow your organization to keep track of important customer information. This will enable you to market your services and products to these customers better.

Why Agile Teams Have to Understand How to Analyze and Make adjustments

How do we acquire knowledge? This is one of the seemingly basic but critical questions you and your team members must ask and consider. We are experts; therefore, we understand why we study and what we should learn. However, many of us do not give enough thought to how we learn.

27 Best Website Testing Tools In 2022

Testing is a critical step in any web application development process. However, it can be an overwhelming task if you don’t have the right tools and expertise. A large percentage of websites still launch with errors that frustrate users and negatively affect the overall success of the site. When a website faces failure after launch, it costs time and money to fix.

11 Best Mobile Automation Testing Tools In 2022

Mobile application development is on the rise like never before, and it proportionally invites the need to perform thorough testing with the right mobile testing strategies. The strategies majorly involve the usage of various mobile automation testing tools. Mobile testing tools help businesses automate their application testing and cut down the extra cost, time, and chances of human error.

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 hypothesis 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