How to use the_providers_are_working method in Sure

Best Python code snippet using sure_python

test_old_api.py

Source:test_old_api.py Github

copy

Full Screen

...603 def the_context_has_variables():604 context.var1 = 123605 context.foobar = "qwerty"606 @scenario(with_setup)607 def the_providers_are_working(Then):608 Then.the_context_has_variables()609 assert hasattr(Then, 'var1')610 assert hasattr(Then, 'foobar')611 assert hasattr(Then, '__sure_providers_of__')612 providers = Then.__sure_providers_of__613 action = Then.the_context_has_variables.__name__614 providers_of_var1 = [p.__name__ for p in providers['var1']]615 assert that(providers_of_var1).contains(action)616 providers_of_foobar = [p.__name__ for p in providers['foobar']]617 assert that(providers_of_foobar).contains(action)618 return True619 assert the_providers_are_working()620def test_fails_when_action_doesnt_fulfill_the_agreement_of_provides():621 "it fails when an action doesn't fulfill its agreements"622 from sure import action_for, scenario623 error = 'the action "bad_action" was supposed to provide the ' \624 'attribute "two" into the context, but it did not. Please ' \625 'double check its implementation'626 def with_setup(context):627 @action_for(context, provides=['one', 'two'])628 def bad_action():629 context.one = 123630 @scenario(with_setup)631 def the_providers_are_working(the):632 assert that(the.bad_action).raises(AssertionError, error)633 return True634 assert the_providers_are_working()635def test_depends_on_failing_due_nothing_found():636 "it fails when an action depends on some attribute that is not " \637 "provided by any other previous action"638 import os639 from sure import action_for, scenario640 fullpath = os.path.abspath(__file__).replace('.pyc', '.py')641 error = 'the action "lonely_action" defined at %s:900 ' \642 'depends on the attribute "something" to be available in the' \643 ' context. It turns out that there are no actions providing ' \644 'that. Please double-check the implementation' % fullpath645 def with_setup(context):646 @action_for(context, depends_on=['something'])647 def lonely_action():648 pass649 @scenario(with_setup)650 def depends_on_fails(the):651 assert that(the.lonely_action).raises(AssertionError, error)652 return True653 assert depends_on_fails()654def test_depends_on_failing_due_not_calling_a_previous_action():655 "it fails when an action depends on some attribute that is being " \656 "provided by other actions"657 import os658 from sure import action_for, scenario659 fullpath = os.path.abspath(__file__).replace('.pyc', '.py')660 error = 'the action "my_action" defined at {0}:930 ' \661 'depends on the attribute "some_attr" to be available in the context.'\662 ' You need to call one of the following actions beforehand:\n' \663 ' -> dependency_action at {0}:926'.replace('{0}', fullpath)664 def with_setup(context):665 @action_for(context, provides=['some_attr'])666 def dependency_action():667 context.some_attr = True668 @action_for(context, depends_on=['some_attr'])669 def my_action():670 pass671 @scenario(with_setup)672 def depends_on_fails(the):673 assert that(the.my_action).raises(AssertionError, error)674 return True675 assert depends_on_fails()676def test_that_contains_dictionary_keys():677 "that(dict(name='foobar')).contains('name')"678 data = dict(name='foobar')679 assert 'name' in data680 assert 'name' in data.keys()681 assert that(data).contains('name')682def test_that_contains_list():683 "that(['foobar', '123']).contains('foobar')"684 data = ['foobar', '123']685 assert 'foobar' in data686 assert that(data).contains('foobar')687def test_that_contains_set():688 "that(set(['foobar', '123']).contains('foobar')"689 data = set(['foobar', '123'])690 assert 'foobar' in data691 assert that(data).contains('foobar')692def test_that_contains_tuple():693 "that(('foobar', '123')).contains('foobar')"694 data = ('foobar', '123')695 assert 'foobar' in data696 assert that(data).contains('foobar')697def test_variables_bag_provides_meaningful_error_on_nonexisting_attribute():698 "VariablesBag() provides a meaningful error when attr does not exist"699 context = VariablesBag()700 context.name = "John"701 context.foo = "bar"702 assert that(context.name).equals("John")703 assert that(context.foo).equals("bar")704 def access_nonexisting_attr():705 assert context.bleh == 'crash :('706 assert that(access_nonexisting_attr).raises(707 AssertionError,708 'you have tried to access the attribute \'bleh\' from the context ' \709 '(aka VariablesBag), but there is no such attribute assigned to it. ' \710 'Maybe you misspelled it ? Well, here are the options: ' \711 '[\'name\', \'foo\']',712 )713def test_actions_providing_dinamically_named_variables():714 "the actions should be able to declare the variables they provide"715 from sure import action_for, scenario716 def with_setup(context):717 @action_for(context, provides=['var1', '{0}'])718 def the_context_has_variables(first_arg):719 context.var1 = 123720 context[first_arg] = "qwerty"721 @scenario(with_setup)722 def the_providers_are_working(Then):723 Then.the_context_has_variables('JohnDoe')724 assert hasattr(Then, 'var1')725 assert 'JohnDoe' in Then726 assert hasattr(Then, '__sure_providers_of__')727 providers = Then.__sure_providers_of__728 action = Then.the_context_has_variables.__name__729 providers_of_var1 = [p.__name__ for p in providers['var1']]730 assert that(providers_of_var1).contains(action)731 providers_of_JohnDoe = [p.__name__ for p in providers['JohnDoe']]732 assert that(providers_of_JohnDoe).contains(action)733 return True734 assert the_providers_are_working()735def test_deep_equals_dict_level1_success():736 "that() deep_equals(dict) succeeding on level 1"737 something = {738 'one': 'yeah',739 }740 assert that(something).deep_equals({741 'one': 'yeah',742 })743def test_deep_equals_dict_level1_fail():744 "that() deep_equals(dict) failing on level 1"745 something = {746 'one': 'yeah',747 }748 def assertions():...

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