Best Python code snippet using selene_python
cid_model_specs.py
Source:cid_model_specs.py
...3class CidModelSpecs(ModelSpecs):4 @spec('Script')5 def script_specs(self, script: SpecModelNode):6 script.should_have_filled('elements')7 script.should_have('imports')8 script.should_have('free_commands')9 script.should_have('free_parameters')10 @spec('Command')11 def command_specs(self, command: SpecModelNode):12 command.should_have_filled('id')13 command.should_have_filled('name')14 command.should_have_filled('title')15 command.should_have('description')16 command.should_have('help')17 command.should_have('parameters')18 command.should_have('sub_commands')19 command.should_have('constraints')20 command.should_have_filled('cli_command')21 command.should_have('help_params')22 command.should_have('no_help')23 command.should_have('long_help_params')24 command.should_have('no_long_help')25 command.should_have('usages')26 command.shouldnt_have('usage')27 command.should_have('gui')28 @spec('Parameter')29 def parameter_specs(self, parameter: SpecModelNode):30 parameter.should_have_filled('id')31 parameter.should_have_filled('type')32 parameter.should_have_filled('name')33 parameter.should_have_filled('title')34 parameter.should_have_filled('description')35 parameter.should_have('help')36 parameter.should_have('default')37 parameter.should_have('empty_str_allowed')38 parameter.should_have('cli')39 parameter.should_have('cli_aliases')40 if parameter.is_of_type('Bool'):41 parameter.should_have_filled('cli')42 parameter.should_have('constraints')43 parameter.should_have('nonpositional')44 if parameter.value.nonpositional:45 parameter\46 .should_have_filled('cli')\47 .should_have_filled('cli_pattern')\48 .should_have_filled('parent')49 parameter.should_have('all_patterns')50 for pattern in parameter.each('all_patterns'):51 if pattern.has_filled('vars'):52 pattern.should_have('count')53 parameter.should_have_filled('cli_pattern_vars')54 parameter.should_have('empty_str_disallowed')55 else:56 parameter.shouldnt_have('empty_str_disallowed')57 parameter.should_have('cli_pattern_count')58 parameter.should_have_filled('multiplicity')59 parameter.shouldnt_have('default_is_none')60 if parameter.is_of_type('Bool'):61 parameter.should_have('none_allowed')62 if parameter.is_of_type('Date'):63 parameter.should_have('date_format')64 if parameter.get('type').value == 'Choice':65 parameter.should_have_filled('choices')66 if parameter.get('type').value == 'Date':67 parameter.should_have_filled('date_format')68 @spec('ParameterCliValue')69 def parameter_cli_value_specs(self, parameter_cli_value: SpecModelNode):70 parameter_cli_value.should_have_filled('cli_pattern')71 @spec('StringParamPattern')72 def string_param_pattern_specs(self, string_param_pattern: SpecModelNode):73 string_param_pattern.should_have_filled('prefix')74 string_param_pattern.should_have('white_space')75 string_param_pattern.should_have('vars')76 string_param_pattern.should_have('count')77 string_param_pattern.should_have('count_many')78 string_param_pattern.should_have('separator')79 string_param_pattern.should_have('count_char')80 @spec('BoolWithPositivePattern')81 def bool_with_positive_pattern_specs(self, bool_with_positive_pattern: SpecModelNode):82 bool_with_positive_pattern.should_have_filled('positive')83 bool_with_positive_pattern.should_have('negative')84 @spec('BoolNegativeOnlyPattern')85 def bool_with_negative_only_pattern_specs(self, bool_with_negative_only_pattern: SpecModelNode):86 bool_with_negative_only_pattern.should_have_filled('negative')87 bool_with_negative_only_pattern.should_have_empty('positive')88 @spec('ParameterReference')89 def parameter_reference_specs(self, parameter_reference: SpecModelNode):90 parameter_reference.should_exist()91 @spec('CommandReference')92 def command_reference_specs(self, command_reference: SpecModelNode):93 command_reference.should_exist()94 @spec('CodeBlock')95 def code_block_specs(self, code_block: SpecModelNode):96 code_block.should_have_filled('code')97 # constraints:98 @spec('CommandConstraint')99 def command_constraint_specs(self, constraint: SpecModelNode):100 constraint.should_have_filled('code_block')101 constraint.should_have_filled('message')102 @spec('NumericValueConstraint')103 def numeric_value_constraint_specs(self, constraint: SpecModelNode):104 constraint.should_have_filled('type')105 constraint.should_have_filled('value')106 constraint.should_have_filled('message')107 @spec('DateConstraint')108 def date_constraint_specs(self, constraint: SpecModelNode):109 constraint.should_have_filled('type')110 constraint.should_have_filled('value')111 constraint.should_have_filled('message')112 @spec('LengthConstraint')113 def length_constraint_specs(self, constraint: SpecModelNode):114 constraint.should_have_filled('type')115 constraint.should_have_filled('value')116 constraint.should_have_filled('message')117 @spec('StringFlagConstraint')118 def string_flag_constraint_specs(self, constraint: SpecModelNode):119 constraint.should_have_filled('type')120 constraint.should_have_filled('message')121 @spec('NumberFlagConstraint')122 def number_flag_constraint_specs(self, constraint: SpecModelNode):123 constraint.should_have_filled('type')124 constraint.should_have_filled('message')125 @spec('FileFlagConstraint')126 def file_flag_constraint_specs(self, constraint: SpecModelNode):127 constraint.should_have_filled('type')128 constraint.should_have_filled('message')129 @spec('RegexConstraint')130 def regex_constraint_specs(self, constraint: SpecModelNode):131 constraint.should_have_filled('value')132 constraint.should_have_filled('message')133 @spec('CodeConstraint')134 def regex_constraint_specs(self, constraint: SpecModelNode):135 constraint.should_have_filled('value')136 constraint.should_have_filled('message')137 # cli structure:138 @spec('CliStructureMultiLine')139 def cli_structure_specs(self, cli_structure: SpecModelNode):140 cli_structure.shouldnt_exist()141 @spec('CliStructure')142 def cli_structure_specs(self, cli_structure: SpecModelNode):143 self.common_cli_element_specs(cli_structure)144 cli_structure.should_have('has_options')145 cli_structure.should_have('has_subcommand')146 @spec('CliGroup')147 def cli_group_specs(self, cli_group: SpecModelNode):148 self.common_cli_element_specs(cli_group)149 @spec('CliOptionalGroup')150 def cli_optional_group_specs(self, cli_optional_group: SpecModelNode):151 self.common_cli_element_specs(cli_optional_group)152 @spec('CliOrGroup')153 def cli_or_group_specs(self, cli_or_group: SpecModelNode):154 self.common_cli_element_specs(cli_or_group)155 cli_or_group.shouldnt_have('lhs')156 cli_or_group.shouldnt_have('rhs')157 def common_cli_element_specs(self, cli_element):158 self.common_structure_group_specs(cli_element)159 if any([element.is_of_type('CliSeparator') for element in cli_element.each('elements')]):160 cli_element.should_have_true('has_cli_separator')161 @spec('CliSeparator')162 def cli_separator_spec(self, cli_separator: SpecModelNode):163 cli_separator.should_have_filled('value')164 cli_separator.should_have_filled('usage_repr')165 cli_separator \166 .map(lambda sep: parent_command(sep), 'parent_command') \167 .should_have_filled('cli_separators')168 # gui structure:169 @spec('GuiStructure')170 def gui_structure_spec(self, gui_structure: SpecModelNode):171 self.common_structure_group_specs(gui_structure)172 @spec('GuiTabs')173 def gui_tabs_spec(self, gui_tabs: SpecModelNode):174 self.common_structure_group_specs(gui_tabs)175 @spec('GuiSectionGroup')176 def gui_section_group_spec(self, gui_section_group: SpecModelNode):177 self.common_structure_group_specs(gui_section_group)178 gui_section_group.should_have('exclusive')179 @spec('GuiSection')180 def gui_section_spec(self, gui_section: SpecModelNode):181 gui_section.should_have_filled('body')182 gui_section.should_have('expanded')183 gui_section.should_have('optional')184 @spec('GuiGrid')185 def gui_grid_spec(self, gui_grid: SpecModelNode):186 self.common_structure_group_specs(gui_grid)187 @spec('GuiTab')188 def gui_tab_spec(self, gui_tab: SpecModelNode):189 gui_tab.should_have_filled('body')190 @spec('GuiGridRow')191 def gui_grid_row_spec(self, gui_grid_row: SpecModelNode):192 self.common_structure_group_specs(gui_grid_row)193 @staticmethod194 def common_structure_group_specs(structure_element):195 structure_element.should_have('sub_elements')...
test_constants.py
Source:test_constants.py
1# Copyright (C) PyZMQ Developers2# Distributed under the terms of the Modified BSD License.3import json4from unittest import TestCase5import pytest6import zmq7from zmq.utils import constant_names8from zmq.sugar import constants as sugar_constants9from zmq.backend import constants as backend_constants10all_set = set(constant_names.all_names)11class TestConstants(TestCase):12 13 def _duplicate_test(self, namelist, listname):14 """test that a given list has no duplicates"""15 dupes = {}16 for name in set(namelist):17 cnt = namelist.count(name)18 if cnt > 1:19 dupes[name] = cnt20 if dupes:21 self.fail("The following names occur more than once in %s: %s" % (listname, json.dumps(dupes, indent=2)))22 23 def test_duplicate_all(self):24 return self._duplicate_test(constant_names.all_names, "all_names")25 26 def _change_key(self, change, version):27 """return changed-in key"""28 return "%s-in %d.%d.%d" % tuple([change] + list(version))29 def test_duplicate_changed(self):30 all_changed = []31 for change in ("new", "removed"):32 d = getattr(constant_names, change + "_in")33 for version, namelist in d.items():34 all_changed.extend(namelist)35 self._duplicate_test(namelist, self._change_key(change, version))36 37 self._duplicate_test(all_changed, "all-changed")38 39 def test_changed_in_all(self):40 missing = {}41 for change in ("new", "removed"):42 d = getattr(constant_names, change + "_in")43 for version, namelist in d.items():44 key = self._change_key(change, version)45 for name in namelist:46 if name not in all_set:47 if key not in missing:48 missing[key] = []49 missing[key].append(name)50 51 if missing:52 self.fail(53 "The following names are missing in `all_names`: %s" % json.dumps(missing, indent=2)54 )55 56 def test_no_negative_constants(self):57 for name in sugar_constants.__all__:58 self.assertNotEqual(getattr(zmq, name), sugar_constants._UNDEFINED)59 60 def test_undefined_constants(self):61 all_aliases = []62 for alias_group in sugar_constants.aliases:63 all_aliases.extend(alias_group)64 65 for name in all_set.difference(all_aliases):66 raw = getattr(backend_constants, name)67 if raw == sugar_constants._UNDEFINED:68 self.assertRaises(AttributeError, getattr, zmq, name)69 else:70 self.assertEqual(getattr(zmq, name), raw)71 72 def test_new(self):73 zmq_version = zmq.zmq_version_info()74 for version, new_names in constant_names.new_in.items():75 should_have = zmq_version >= version76 for name in new_names:77 try:78 value = getattr(zmq, name)79 except AttributeError:80 if should_have:81 self.fail("AttributeError: zmq.%s" % name)82 else:83 if not should_have:84 self.fail("Shouldn't have: zmq.%s=%s" % (name, value))85 @pytest.mark.skipif(not zmq.DRAFT_API, reason="Only test draft API if built with draft API")86 def test_draft(self):87 zmq_version = zmq.zmq_version_info()88 for version, new_names in constant_names.draft_in.items():89 should_have = zmq_version >= version90 for name in new_names:91 try:92 value = getattr(zmq, name)93 except AttributeError:94 if should_have:95 self.fail("AttributeError: zmq.%s" % name)96 else:97 if not should_have:98 self.fail("Shouldn't have: zmq.%s=%s" % (name, value))99 def test_removed(self):100 zmq_version = zmq.zmq_version_info()101 for version, new_names in constant_names.removed_in.items():102 should_have = zmq_version < version103 for name in new_names:104 try:105 value = getattr(zmq, name)106 except AttributeError:107 if should_have:108 self.fail("AttributeError: zmq.%s" % name)109 else:110 if not should_have:...
test_registration_form.py
Source:test_registration_form.py
...15 app.form.choose_state('NCR')16 app.form.choose_city('Delhi')17 app.form.submit()18 # THEN19 app.results.full_name.should_have('Vlad K')20 app.results.email.should_have('test@mail.qa')21 app.results.gender.should_have('Male')22 app.results.mobile.should_have('1234567890')23 app.results.date_of_birth.should_have('10 October,2000')24 app.results.subjects.should_have('Maths, Economics')25 app.results.hobbies.should_have('Sports')26 app.results.picture.should_have('test_image.png')27 app.results.address.should_have('Address street')...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!