Best Python code snippet using autotest_python
csv_encoder_unittest.py
Source:csv_encoder_unittest.py
...14 incomplete_count=0):15 return dict(header_indices=header_indices, pass_count=pass_count,16 complete_count=complete_count,17 incomplete_count=incomplete_count)18 def _encode_and_check_result(self, request, result, *expected_csv_rows):19 encoder = csv_encoder.encoder(request, result)20 response = encoder.encode()21 csv_result = response.content22 expected_csv = '\r\n'.join(expected_csv_rows) + '\r\n'23 self.assertEquals(csv_result, expected_csv)24 def test_spreadsheet_encoder(self):25 request = self._make_request('get_status_counts')26 response = {'header_values' :27 [[('row1',), ('row2',), ('comma,header',)],28 [('col1', 'sub1'), ('col1', 'sub2'),29 ('col2', 'sub1')]],30 'groups' : [self._make_group((0, 0), 1, 2),31 self._make_group((1, 2), 3, 4, 5)]}32 self._encode_and_check_result(request, response,33 ',col1/sub1,col1/sub2,col2/sub1',34 'row1,1 / 2,,',35 'row2,,,3 / 4 (5 incomplete)',36 '"comma,header",,,')37 def test_table_encoder(self):38 request = self._make_request('get_test_views', [['col1', 'Column 1'],39 ['col2', 'Column 2']])40 response = [{'col1' : 'foo', 'col2' : 'bar'},41 {'col1' : 'baz', 'col2' : 'asdf'}]42 self._encode_and_check_result(request, response,43 'Column 1,Column 2',44 'foo,bar',45 'baz,asdf')46 def test_grouped_table_encoder(self):47 request = self._make_request('get_group_counts',48 [['col1', 'Column 1'],49 ['group_count', 'Count in group']])50 response = {'header_values' : 'unused',51 'groups' : [{'col1' : 'foo', 'group_count' : 1},52 {'col1' : 'baz', 'group_count' : 3}]}53 self._encode_and_check_result(request, response,54 'Column 1,Count in group',55 'foo,1',56 'baz,3')57 def _status_count_dict(self, col1_value, pass_count, complete_count,58 incomplete_count):59 return dict(col1=col1_value, pass_count=pass_count,60 complete_count=complete_count,61 incomplete_count=incomplete_count)62 def test_status_count_table_encoder(self):63 request = self._make_request('get_status_counts',64 [['col1', 'Column 1'],65 ['_unused_', 'Test pass rate']])66 response = {'header_values' : 'unused',67 'groups' : [self._status_count_dict('foo', 1, 2, 0),68 self._status_count_dict('baz', 4, 5, 6)]}69 self._encode_and_check_result(request, response,70 'Column 1,Test pass rate',71 'foo,1 / 2',72 'baz,4 / 5 (6 incomplete)')73 def test_extra_info_spreadsheet_encoder(self):74 request = self._make_request('get_latest_tests')75 group1 = self._make_group((0, 0), 1, 1)76 group2 = self._make_group((1, 0), 1, 1)77 group1['extra_info'] = ['info1', 'info2']78 group2['extra_info'] = ['', 'info3']79 response = {'header_values' :80 [[('row1',), ('row2',)],81 [('col1',), ('col2',)]],82 'groups' : [group1, group2]}83 self._encode_and_check_result(request, response,84 ',col1,col2',85 'row1,"1 / 1\ninfo1\ninfo2",',86 'row2,"1 / 1\n\ninfo3",')87 def test_unhandled_method(self):88 request = self._make_request('foo')89 self._encode_and_check_result(request, None,90 'Unhandled method foo (this indicates a '91 'bug)')92if __name__ == '__main__':...
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!!