Best Python code snippet using autotest_python
test_treecontroller.py
Source:test_treecontroller.py  
...99        self._tsc = TestSelectionController()100    def test_test_selection_is_empty_by_default(self):101        self.assertTrue(self._tsc.is_empty())102    def test_test_selection_is_not_empty_when_it_contains_a_test(self):103        self._tsc.select(self._create_test())104        self.assertFalse(self._tsc.is_empty())105    def test_test_selection_is_empty_after_removing_same_test_from_there_even_when_it_is_not_the_same_object(self):106        self._tsc.select(self._create_test())107        self._tsc.select(self._create_test(), False)108        self.assertTrue(self._tsc.is_empty())109    def test_adding_tag_to_selected_tests(self):110        tests = [self._create_test('test%d' % i) for i in range(10)]111        for t in tests:112            self._tsc.select(t)113        self._tsc.add_tag('foo')114        for t in tests:115            self.assertEqual([tag.name for tag in t.tags], ['foo'])116    def test_adding_a_tag_to_test_with_a_default_tag(self):117        test = self._create_test()118        test.datafile_controller.default_tags.execute(ChangeTag(Tag(None), 'default'))119        assert_equals([t.name for t in test.tags], ['default'])120        self._tsc.select(test)121        self._tsc.add_tag('custom')122        self.assertEqual([t.name for t in test.tags], ['default', 'custom'])123    def _create_test(self, name='test'):124        suite = TestCaseFile(source='suite')125        suite_controller = TestCaseFileController(suite)126        parent = TestCaseTableController(suite_controller, suite.testcase_table)127        test = TestCase(parent=lambda:0, name=name)128        return TestCaseController(parent, test)129if __name__ == '__main__':...wscript
Source:wscript  
...94            includes = 'deps/cmocka/include',95            export_includes = 'deps/cmocka/include',96            source = 'deps/cmocka/src/cmocka.c',97        )98        _create_test(ctx, 'tj_array')99        _create_test(ctx, 'tj_buffer')100        _create_test(ctx, 'tj_error')101        _create_test(ctx, 'tj_heap')102        _create_test(ctx, 'tj_log')103        _create_test(ctx, 'tj_searchpathlist')104        if ctx.env.LIB_DL:105            _create_test(ctx, 'tj_solibrary')106        _create_test(ctx, 'tj_template')107        _create_test(ctx, 'tj_util', ['calloc', 'strdup', 'strndup'])108def _create_test(ctx, src, wrappers=None):109    if wrappers is None:110        wrappers = []111    ctx.program(112        features = 'test',113        target = 'test-' + src,114        # Execute test from root project directory, for data files.115        ut_cwd = ctx.top_dir,116        use = ['tj-tools', 'cmocka'],117        source = 'test/test-{}.c'.format(src),118        linkflags = ['-Wl,--wrap=' + symbol for symbol in wrappers],...test_views.py
Source:test_views.py  
...7from kitsune.wiki.tests import LocaleFactory8class TestCreateLocaleAnnouncement(TestCase):9    def setUp(self):10        self.locale = LocaleFactory(locale="es")11    def _create_test(self, status, count):12        """Login, or other setup, then call this."""13        url = reverse("announcements.create_for_locale", locale="es")14        resp = self.client.post(15            url,16            {17                "content": "Look at me!",18                "show_after": "2012-01-01",19            },20        )21        self.assertEqual(resp.status_code, status)22        self.assertEqual(Announcement.objects.count(), count)23    def test_create(self):24        u = UserFactory(is_superuser=1)25        self.client.login(username=u.username, password="testpass")26        self._create_test(200, 1)27    def test_leader(self):28        u = UserFactory()29        self.locale.leaders.add(u)30        self.locale.save()31        self.client.login(username=u.username, password="testpass")32        self._create_test(200, 1)33    def test_has_permission(self):34        u = UserFactory()35        add_permission(u, Announcement, "add_announcement")36        self.client.login(username=u.username, password="testpass")37        self._create_test(200, 1)38    def test_no_perms(self):39        u = UserFactory()40        self.client.login(username=u.username, password="testpass")41        self._create_test(403, 0)42    def test_anon(self):43        self._create_test(302, 0)44class TestDeleteAnnouncement(TestCase):45    def setUp(self):46        self.locale = LocaleFactory(locale="es")47        self.u = UserFactory()48        self.locale.leaders.add(self.u)49        self.locale.save()50        self.announcement = AnnouncementFactory(51            creator=self.u,52            locale=self.locale,53            content="Look at me!",54            show_after=datetime(2012, 1, 1, 0, 0, 0),55        )56    def _delete_test(self, id, status, count):57        """Login, or other setup, then call this."""...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!!
