Best Python code snippet using tempest_python
autoimporttest.py
Source: autoimporttest.py
...13 testutils.remove_project(self.project)14 super(AutoImportTest, self).tearDown()15 def test_simple_case(self):16 self.assertEquals([], self.importer.import_assist('A'))17 def test_update_resource(self):18 self.mod1.write('myvar = None\n')19 self.importer.update_resource(self.mod1)20 self.assertEquals([('myvar', 'mod1')],21 self.importer.import_assist('myva'))22 def test_update_module(self):23 self.mod1.write('myvar = None')24 self.importer.update_module('mod1')25 self.assertEquals([('myvar', 'mod1')],26 self.importer.import_assist('myva'))27 def test_update_non_existent_module(self):28 self.importer.update_module('does_not_exists_this')29 self.assertEquals([], self.importer.import_assist('myva'))30 def test_module_with_syntax_errors(self):31 self.mod1.write('this is a syntax error\n')32 self.importer.update_resource(self.mod1)33 self.assertEquals([], self.importer.import_assist('myva'))34 def test_excluding_imported_names(self):35 self.mod1.write('import pkg\n')36 self.importer.update_resource(self.mod1)37 self.assertEquals([], self.importer.import_assist('pkg'))38 def test_get_modules(self):39 self.mod1.write('myvar = None\n')40 self.importer.update_resource(self.mod1)41 self.assertEquals(['mod1'], self.importer.get_modules('myvar'))42 def test_get_modules_inside_packages(self):43 self.mod1.write('myvar = None\n')44 self.mod2.write('myvar = None\n')45 self.importer.update_resource(self.mod1)46 self.importer.update_resource(self.mod2)47 self.assertEquals(set(['mod1', 'pkg.mod2']),48 set(self.importer.get_modules('myvar')))49 def test_trivial_insertion_line(self):50 result = self.importer.find_insertion_line('')51 self.assertEquals(1, result)52 def test_insertion_line(self):53 result = self.importer.find_insertion_line('import mod\n')54 self.assertEquals(2, result)55 def test_insertion_line_with_pydocs(self):56 result = self.importer.find_insertion_line(57 '"""docs\n\ndocs"""\nimport mod\n')58 self.assertEquals(5, result)59 def test_insertion_line_with_multiple_imports(self):60 result = self.importer.find_insertion_line(61 'import mod1\n\nimport mod2\n')62 self.assertEquals(4, result)63 def test_insertion_line_with_blank_lines(self):64 result = self.importer.find_insertion_line(65 'import mod1\n\n# comment\n')66 self.assertEquals(2, result)67 def test_empty_cache(self):68 self.mod1.write('myvar = None\n')69 self.importer.update_resource(self.mod1)70 self.assertEquals(['mod1'], self.importer.get_modules('myvar'))71 self.importer.clear_cache()72 self.assertEquals([], self.importer.get_modules('myvar'))73 def test_not_caching_underlined_names(self):74 self.mod1.write('_myvar = None\n')75 self.importer.update_resource(self.mod1, underlined=False)76 self.assertEquals([], self.importer.get_modules('_myvar'))77 self.importer.update_resource(self.mod1, underlined=True)78 self.assertEquals(['mod1'], self.importer.get_modules('_myvar'))79 def test_caching_underlined_names_passing_to_the_constructor(self):80 importer = autoimport.AutoImport(self.project, False, True)81 self.mod1.write('_myvar = None\n')82 importer.update_resource(self.mod1)83 self.assertEquals(['mod1'], importer.get_modules('_myvar'))84 def test_name_locations(self):85 self.mod1.write('myvar = None\n')86 self.importer.update_resource(self.mod1)87 self.assertEquals([(self.mod1, 1)],88 self.importer.get_name_locations('myvar'))89 def test_name_locations_with_multiple_occurrences(self):90 self.mod1.write('myvar = None\n')91 self.mod2.write('\nmyvar = None\n')92 self.importer.update_resource(self.mod1)93 self.importer.update_resource(self.mod2)94 self.assertEquals(set([(self.mod1, 1), (self.mod2, 2)]),95 set(self.importer.get_name_locations('myvar')))96 def test_handling_builtin_modules(self):97 self.importer.update_module('sys')98 self.assertTrue('sys' in self.importer.get_modules('exit'))99 def test_submodules(self):100 self.assertEquals(set([self.mod1]),101 autoimport.submodules(self.mod1))102 self.assertEquals(set([self.mod2, self.pkg]),103 autoimport.submodules(self.pkg))104class AutoImportObservingTest(unittest.TestCase):105 def setUp(self):106 super(AutoImportObservingTest, self).setUp()107 self.project = testutils.sample_project()...
resource_method_unittest.py
Source: resource_method_unittest.py
1#! /usr/bin/python2# Copyright 2014 The Chromium OS Authors. All rights reserved.3# Use of this source code is governed by a BSD-style license that can be4# found in the LICENSE file.5"""Unit tests for resource_method.py."""6import mox7import unittest8import common9from fake_device_server import common_util10from fake_device_server import resource_method11from fake_device_server import resource_delegate12from fake_device_server import server_errors13class ResourceMethodTest(mox.MoxTestBase):14 """Tests for the ResourceMethod class."""15 def setUp(self):16 """Sets up resource_method object and dict of resources."""17 mox.MoxTestBase.setUp(self)18 self.resources = {}19 self.resource_method = resource_method.ResourceMethod(20 resource_delegate.ResourceDelegate(self.resources))21 def testPatch(self):22 """Tests that we correctly patch a resource."""23 expected_resource = dict(id=1234, blah='hi')24 update_resource = dict(blah='hi')25 self.resources[(1234, None)] = dict(id=1234)26 self.mox.StubOutWithMock(common_util, 'parse_serialized_json')27 common_util.parse_serialized_json().AndReturn(update_resource)28 self.mox.ReplayAll()29 returned_json = self.resource_method.PATCH(1234)30 self.assertEquals(expected_resource, returned_json)31 self.mox.VerifyAll()32 def testPut(self):33 """Tests that we correctly replace a resource."""34 update_resource = dict(id=12345, blah='hi')35 self.resources[(12345, None)] = dict(id=12345)36 self.mox.StubOutWithMock(common_util, 'parse_serialized_json')37 common_util.parse_serialized_json().AndReturn(update_resource)38 self.mox.ReplayAll()39 returned_json = self.resource_method.PUT(12345)40 self.assertEquals(update_resource, returned_json)41 self.mox.VerifyAll()42 self.mox.ResetAll()43 # Ticket id doesn't match.44 update_resource = dict(id=12346, blah='hi')45 common_util.parse_serialized_json().AndReturn(update_resource)46 self.mox.ReplayAll()47 self.assertRaises(server_errors.HTTPError,48 self.resource_method.PUT, 12345)49 self.mox.VerifyAll()50if __name__ == '__main__':...
Check out the latest blogs from LambdaTest on this topic:
These days, development teams depend heavily on feedback from automated tests to evaluate the quality of the system they are working on.
I think that probably most development teams describe themselves as being “agile” and probably most development teams have standups, and meetings called retrospectives.There is also a lot of discussion about “agile”, much written about “agile”, and there are many presentations about “agile”. A question that is often asked is what comes after “agile”? Many testers work in “agile” teams so this question matters to us.
I routinely come across test strategy documents when working with customers. They are lengthy—100 pages or more—and packed with monotonous text that is routinely reused from one project to another. Yawn once more— the test halt and resume circumstances, the defect management procedure, entrance and exit criteria, unnecessary generic risks, and in fact, one often-used model replicates the requirements of textbook testing, from stress to systems integration.
To understand the agile testing mindset, we first need to determine what makes a team “agile.” To me, an agile team continually focuses on becoming self-organized and cross-functional to be able to complete any challenge they may face during a project.
When working on web automation with Selenium, I encountered scenarios where I needed to refresh pages from time to time. When does this happen? One scenario is that I needed to refresh the page to check that the data I expected to see was still available even after refreshing. Another possibility is to clear form data without going through each input individually.
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!!