Best Python code snippet using green
test_testsuite.py
Source:test_testsuite.py
...22FunctionFixture = try_import('fixtures.FunctionFixture')23class Sample(TestCase):24 def __hash__(self):25 return id(self)26 def test_method1(self):27 pass28 def test_method2(self):29 pass30class TestConcurrentTestSuiteRun(TestCase):31 def test_broken_test(self):32 log = []33 def on_test(test, status, start_time, stop_time, tags, details):34 log.append((test.id(), status, set(details.keys())))35 class BrokenTest(object):36 # Simple break - no result parameter to run()37 def __call__(self):38 pass39 run = __call__40 original_suite = unittest.TestSuite([BrokenTest()])...
extract_google_test_list_test.py
Source:extract_google_test_list_test.py
1# Copyright 2014 The Chromium Authors. All rights reserved.2# Use of this source code is governed by a BSD-style license that can be3# found in the LICENSE file.4import StringIO5import unittest6from src.build.util.test import extract_google_test_list7class TestExtractGoogleTestList(unittest.TestCase):8 def _parse_cpp_test_list(self, content):9 """Simple wrapper of _parse_test_list for C++ testing."""10 return extract_google_test_list._parse_test_list(11 StringIO.StringIO(content),12 extract_google_test_list._CPP_TEST_METHOD_PATTERN)13 def test_parser_cpp_test_list(self):14 # Simple cases for TEST_F.15 self.assertEquals(16 ['Fixture1#test_method1',17 'Fixture1#test_method2',18 'Fixture2#test_method1',19 'Fixture2#test_method2'],20 self._parse_cpp_test_list('\n'.join([21 'TEST_F(Fixture1, test_method1) {',22 ' // test body',23 '}',24 '',25 'TEST_F(Fixture1, test_method2) {',26 ' // test body',27 '}',28 '',29 'TEST_F(Fixture2, test_method1) {',30 ' // test body',31 '}',32 '',33 'TEST_F(Fixture2, test_method2) {',34 ' // test body',35 '}'])))36 # Simple cases for TEST.37 self.assertEquals(38 ['Fixture1#test_method1',39 'Fixture1#test_method2',40 'Fixture2#test_method1',41 'Fixture2#test_method2'],42 self._parse_cpp_test_list('\n'.join([43 'TEST(Fixture1, test_method1) {',44 ' // test body',45 '}',46 '',47 'TEST(Fixture1, test_method2) {',48 ' // test body',49 '}',50 '',51 'TEST(Fixture2, test_method1) {',52 ' // test body',53 '}',54 '',55 'TEST(Fixture2, test_method2) {',56 ' // test body',57 '}'])))58 # Line breaks around fixture and test name.59 self.assertEquals(60 ['Fixture1#test_method1',61 'Fixture1#test_method2',62 'Fixture1#test_method3'],63 self._parse_cpp_test_list('\n'.join([64 'TEST_F(Fixture1,'65 ' test_method1) {',66 ' // test body',67 '}',68 '',69 'TEST_F('70 ' Fixture1, test_method2) {',71 ' // test body',72 '}',73 '',74 'TEST_F('75 ' Fixture1,'76 ' test_method3) {',77 ' // test body',78 '}'])))79 def _parse_javascript_test_list(self, content):80 """Simple wrapper of _parse_test_list for JavaScript testing."""81 return extract_google_test_list._parse_test_list(82 StringIO.StringIO(content),83 extract_google_test_list._JAVASCRIPT_TEST_METHOD_PATTERN)84 def test_parse_javascript_test_list(self):85 # Simple cases.86 self.assertEquals(87 ['Fixture1#test_method1',88 'Fixture1#test_method2',89 'Fixture2#test_method1',90 'Fixture2#test_method2'],91 self._parse_javascript_test_list('\n'.join([92 'TEST_F(Fixture1, "test_method1", function() {',93 ' // Some test body code;',94 '});',95 '',96 'TEST_F(Fixture1, "test_method2", function() {',97 ' // Some test body code;',98 '});',99 '',100 'TEST_F(Fixture2, "test_method1", function() {',101 ' // Some test body code;',102 '});',103 '',104 'TEST_F(Fixture2, "test_method2", function() {',105 ' // Some test body code;',106 '});',107 ''])))108 # Some line breaks around the parameters.109 self.assertEquals(110 ['Fixture1#test_method1',111 'Fixture1#test_method2',112 'Fixture1#test_method3',113 'Fixture1#test_method4'],114 self._parse_javascript_test_list('\n'.join([115 'TEST_F(Fixture1, "test_method1",',116 ' function() {',117 ' // Some test body code;',118 '});',119 '',120 'TEST_F(Fixture1,',121 ' "test_method2", function() {',122 ' // Some test body code;',123 '});',124 '',125 'TEST_F(',126 ' Fixture1, "test_method3", function() {',127 ' // Some test body code;',128 '});',129 '',130 'TEST_F(',131 ' Fixture1,',132 ' "test_method4",',133 ' function() {',134 ' // Some test body code;',135 '});',136 ''])))137 # The definition of TEST_F should not be included.138 self.assertEquals(139 [],140 self._parse_javascript_test_list('\n'.join([141 'function TEST_F(fixtureClass, testName, '142 'testFunc, opt_caseName) {',143 ' // The definition code line 1.',144 ' // The definition code line 2.',145 ' // The definition code line 3.',146 '}'])))147if __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!!