Best Python code snippet using localstack_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__':...
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!!