Best Python code snippet using pandera_python
models_courses.py
Source:models_courses.py
...59 formatted_errors = []60 for error in expected:61 formatted_errors.append('%s%s' % (ERROR_HEADER, error))62 self.assertEqual(formatted_errors, actual)63 def to_yaml(self, adict):64 """Convert a dict to YAML."""65 return yaml.safe_dump(adict)66 def test_empty_string(self):67 """Validation should fail on an empty string."""68 workflow = Workflow('')69 workflow.validate(self.errors)70 self.assert_matching_errors(['missing key: grader.'], self.errors)71 def test_invalid_string(self):72 """Validation should fail for invalid YAML strings."""73 workflow = Workflow('(')74 workflow.validate(self.errors)75 self.assertTrue(self.errors)76 def test_not_dict(self):77 """Validation should fail for non-dict YAML strings."""78 yaml_strs = ['- first\n- second', 'grader']79 for yaml_str in yaml_strs:80 self.errors = []81 workflow = Workflow(yaml_str)82 workflow.validate(self.errors)83 self.assert_matching_errors(84 ['expected the YAML representation of a dict'], self.errors)85 def test_missing_grader_key(self):86 """Validation should fail for missing grader key."""87 workflow = Workflow(self.to_yaml({'not_grader': 'human'}))88 workflow.validate(self.errors)89 self.assert_matching_errors(['missing key: grader.'], self.errors)90 def test_auto_grader(self):91 """Validation should pass for an auto-graded assessment."""92 workflow = Workflow(self.to_yaml({'grader': 'auto'}))93 workflow.validate(self.errors)94 self.assertFalse(self.errors)95 def test_empty_submission_date_in_grader(self):96 """Validation should pass for empty submission date."""97 workflow = Workflow(self.to_yaml(98 {'grader': 'auto', 'submission_due_date': ''}))99 workflow.validate(self.errors)100 self.assertFalse(self.errors)101 def test_invalid_human_grader(self):102 """Validation should fail for invalid human grading specifications."""103 workflow = Workflow(self.to_yaml({'grader': 'human'}))104 workflow.validate(self.errors)105 self.assert_matching_errors([106 '%s matcher, review_min_count, review_window_mins, '107 'submission_due_date, review_due_date.' %108 MISSING_KEYS_PREFIX], self.errors)109 self.errors = []110 workflow = Workflow(self.to_yaml(111 {'grader': 'human', 'matcher': 'peer'}112 ))113 workflow.validate(self.errors)114 self.assert_matching_errors([115 '%s review_min_count, review_window_mins, submission_due_date, '116 'review_due_date.' % MISSING_KEYS_PREFIX], self.errors)117 def test_invalid_review_min_count(self):118 """Validation should fail for bad review_min_count values."""119 workflow_dict = self.valid_human_review_workflow_dict120 workflow_dict['review_min_count'] = 'test_string'121 workflow = Workflow(self.to_yaml(workflow_dict))122 workflow.validate(self.errors)123 self.assert_matching_errors(124 ['review_min_count should be an integer.'], self.errors)125 self.errors = []126 workflow_dict['review_min_count'] = -1127 workflow = Workflow(self.to_yaml(workflow_dict))128 workflow.validate(self.errors)129 self.assert_matching_errors(130 ['review_min_count should be a non-negative integer.'], self.errors)131 self.errors = []132 workflow_dict['review_min_count'] = 0133 workflow = Workflow(self.to_yaml(workflow_dict))134 workflow.validate(self.errors)135 self.assertFalse(self.errors)136 def test_invalid_review_window_mins(self):137 """Validation should fail for bad review_window_mins values."""138 workflow_dict = self.valid_human_review_workflow_dict139 workflow_dict['review_window_mins'] = 'test_string'140 workflow = Workflow(self.to_yaml(workflow_dict))141 workflow.validate(self.errors)142 self.assert_matching_errors(143 ['review_window_mins should be an integer.'], self.errors)144 self.errors = []145 workflow_dict['review_window_mins'] = -1146 workflow = Workflow(self.to_yaml(workflow_dict))147 workflow.validate(self.errors)148 self.assert_matching_errors(149 ['review_window_mins should be a non-negative integer.'],150 self.errors)151 self.errors = []152 workflow_dict['review_window_mins'] = 0153 workflow = Workflow(self.to_yaml(workflow_dict))154 workflow.validate(self.errors)155 self.assertFalse(self.errors)156 def test_invalid_date(self):157 """Validation should fail for invalid dates."""158 workflow_dict = self.valid_human_review_workflow_dict159 workflow_dict['submission_due_date'] = 'test_string'160 workflow = Workflow(self.to_yaml(workflow_dict))161 workflow.validate(self.errors)162 self.assert_matching_errors([DATE_FORMAT_ERROR], self.errors)163 self.errors = []164 workflow_dict = self.valid_human_review_workflow_dict165 workflow_dict['review_due_date'] = 'test_string'166 workflow = Workflow(self.to_yaml(workflow_dict))167 workflow.validate(self.errors)168 self.assert_matching_errors([DATE_FORMAT_ERROR], self.errors)169 def test_submission_date_after_review_date_fails(self):170 """Validation should fail if review date precedes submission date."""171 workflow_dict = self.valid_human_review_workflow_dict172 workflow_dict['submission_due_date'] = '2013-03-14 12:00'173 workflow_dict['review_due_date'] = '2013-03-13 12:00'174 workflow = Workflow(self.to_yaml(workflow_dict))175 workflow.validate(self.errors)176 self.assert_matching_errors(177 ['submission due date should be earlier than review due date.'],178 self.errors)179 def test_multiple_errors(self):180 """Validation should fail with multiple errors when appropriate."""181 workflow_dict = self.valid_human_review_workflow_dict182 workflow_dict['submission_due_date'] = '2013-03-14 12:00'183 workflow_dict['review_due_date'] = '2013-03-13 12:00'184 workflow_dict['review_window_mins'] = 'hello'185 workflow = Workflow(self.to_yaml(workflow_dict))186 workflow.validate(self.errors)187 self.assert_matching_errors(188 ['review_window_mins should be an integer; submission due date '189 'should be earlier than review due date.'],190 self.errors)191 def test_valid_human_grader(self):192 """Validation should pass for valid human grading specifications."""193 workflow_dict = self.valid_human_review_workflow_dict194 workflow = Workflow(self.to_yaml(workflow_dict))195 workflow.validate(self.errors)...
basics.py
Source:basics.py
...34 try:35 return isinstance(obj, basestring)36 except NameError:37 return isinstance(obj, str)38def to_yaml(obj):39 """ Simplify yaml representation for pretty printing """40 # Is there a better way to do this by adding a representation with yaml.Dumper?41 # Ordered dict: http://pyyaml.org/ticket/29#comment:1142 if obj is None or isstring(obj):43 out = str(obj)44 elif type(obj) in [int, float, bool]:45 return obj46 elif hasattr(obj, 'to_yaml'):47 out = obj.to_yaml()48 elif isinstance(obj, etree._Element):49 out = etree.tostring(obj, pretty_print = True)50 elif type(obj) == dict:51 out = {}52 for (var, value) in obj.items():53 out[str(var)] = to_yaml(value)54 elif hasattr(obj, 'tolist'):55 # For numpy objects56 out = to_yaml(obj.tolist())57 elif isinstance(obj, collections.Iterable):58 out = [to_yaml(item) for item in obj]59 else:60 out = str(obj)61 return out62class SelectiveReflection(object):63 def get_refl_vars(self):64 return list(vars(self).keys())65class YamlReflection(SelectiveReflection):66 def to_yaml(self):67 raw = dict((var, getattr(self, var)) for var in self.get_refl_vars())68 return to_yaml(raw)69 70 def __str__(self):...
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!!