How to use test_mutation method in hypothesis

Best Python code snippet using hypothesis

test_gis_tests_utils.py

Source:test_gis_tests_utils.py Github

copy

Full Screen

1from django.db import connection, models2from django.db.models.expressions import Func3from django.test import SimpleTestCase4from .utils import FuncTestMixin5def test_mutation(raises=True):6 def wrapper(mutation_func):7 def test(test_case_instance, *args, **kwargs):8 class TestFunc(Func):9 output_field = models.IntegerField()10 def __init__(self):11 self.attribute = 'initial'12 super().__init__('initial', ['initial'])13 def as_sql(self, *args, **kwargs):14 mutation_func(self)15 return '', ()16 if raises:17 msg = 'TestFunc Func was mutated during compilation.'18 with test_case_instance.assertRaisesMessage(AssertionError, msg):19 getattr(TestFunc(), 'as_' + connection.vendor)(None, None)20 else:21 getattr(TestFunc(), 'as_' + connection.vendor)(None, None)22 return test23 return wrapper24class FuncTestMixinTests(FuncTestMixin, SimpleTestCase):25 @test_mutation()26 def test_mutated_attribute(func):27 func.attribute = 'mutated'28 @test_mutation()29 def test_mutated_expressions(func):30 func.source_expressions.clear()31 @test_mutation()32 def test_mutated_expression(func):33 func.source_expressions[0].name = 'mutated'34 @test_mutation()35 def test_mutated_expression_deep(func):36 func.source_expressions[1].value[0] = 'mutated'37 @test_mutation(raises=False)38 def test_not_mutated(func):...

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