How to use get_modules method in refurb

Best Python code snippet using refurb_python

autoimporttest.py

Source:autoimporttest.py Github

copy

Full Screen

...37 def test_excluding_imported_names(self):38 self.mod1.write('import pkg\n')39 self.importer.update_resource(self.mod1)40 self.assertEqual([], self.importer.import_assist('pkg'))41 def test_get_modules(self):42 self.mod1.write('myvar = None\n')43 self.importer.update_resource(self.mod1)44 self.assertEqual(['mod1'], self.importer.get_modules('myvar'))45 def test_get_modules_inside_packages(self):46 self.mod1.write('myvar = None\n')47 self.mod2.write('myvar = None\n')48 self.importer.update_resource(self.mod1)49 self.importer.update_resource(self.mod2)50 self.assertEqual(set(['mod1', 'pkg.mod2']),51 set(self.importer.get_modules('myvar')))52 def test_trivial_insertion_line(self):53 result = self.importer.find_insertion_line('')54 self.assertEqual(1, result)55 def test_insertion_line(self):56 result = self.importer.find_insertion_line('import mod\n')57 self.assertEqual(2, result)58 def test_insertion_line_with_pydocs(self):59 result = self.importer.find_insertion_line(60 '"""docs\n\ndocs"""\nimport mod\n')61 self.assertEqual(5, result)62 def test_insertion_line_with_multiple_imports(self):63 result = self.importer.find_insertion_line(64 'import mod1\n\nimport mod2\n')65 self.assertEqual(4, result)66 def test_insertion_line_with_blank_lines(self):67 result = self.importer.find_insertion_line(68 'import mod1\n\n# comment\n')69 self.assertEqual(2, result)70 def test_empty_cache(self):71 self.mod1.write('myvar = None\n')72 self.importer.update_resource(self.mod1)73 self.assertEqual(['mod1'], self.importer.get_modules('myvar'))74 self.importer.clear_cache()75 self.assertEqual([], self.importer.get_modules('myvar'))76 def test_not_caching_underlined_names(self):77 self.mod1.write('_myvar = None\n')78 self.importer.update_resource(self.mod1, underlined=False)79 self.assertEqual([], self.importer.get_modules('_myvar'))80 self.importer.update_resource(self.mod1, underlined=True)81 self.assertEqual(['mod1'], self.importer.get_modules('_myvar'))82 def test_caching_underlined_names_passing_to_the_constructor(self):83 importer = autoimport.AutoImport(self.project, False, True)84 self.mod1.write('_myvar = None\n')85 importer.update_resource(self.mod1)86 self.assertEqual(['mod1'], importer.get_modules('_myvar'))87 def test_name_locations(self):88 self.mod1.write('myvar = None\n')89 self.importer.update_resource(self.mod1)90 self.assertEqual([(self.mod1, 1)],91 self.importer.get_name_locations('myvar'))92 def test_name_locations_with_multiple_occurrences(self):93 self.mod1.write('myvar = None\n')94 self.mod2.write('\nmyvar = None\n')95 self.importer.update_resource(self.mod1)96 self.importer.update_resource(self.mod2)97 self.assertEqual(set([(self.mod1, 1), (self.mod2, 2)]),98 set(self.importer.get_name_locations('myvar')))99 def test_handling_builtin_modules(self):100 self.importer.update_module('sys')101 self.assertTrue('sys' in self.importer.get_modules('exit'))102 def test_submodules(self):103 self.assertEqual(set([self.mod1]),104 autoimport.submodules(self.mod1))105 self.assertEqual(set([self.mod2, self.pkg]),106 autoimport.submodules(self.pkg))107class AutoImportObservingTest(unittest.TestCase):108 def setUp(self):109 super(AutoImportObservingTest, self).setUp()110 self.project = testutils.sample_project()111 self.mod1 = testutils.create_module(self.project, 'mod1')112 self.pkg = testutils.create_package(self.project, 'pkg')113 self.mod2 = testutils.create_module(self.project, 'mod2', self.pkg)114 self.importer = autoimport.AutoImport(self.project, observe=True)115 def tearDown(self):116 testutils.remove_project(self.project)117 super(AutoImportObservingTest, self).tearDown()118 def test_writing_files(self):119 self.mod1.write('myvar = None\n')120 self.assertEqual(['mod1'], self.importer.get_modules('myvar'))121 def test_moving_files(self):122 self.mod1.write('myvar = None\n')123 self.mod1.move('mod3.py')124 self.assertEqual(['mod3'], self.importer.get_modules('myvar'))125 def test_removing_files(self):126 self.mod1.write('myvar = None\n')127 self.mod1.remove()128 self.assertEqual([], self.importer.get_modules('myvar'))129def suite():130 result = unittest.TestSuite()131 result.addTests(unittest.makeSuite(AutoImportTest))132 result.addTests(unittest.makeSuite(AutoImportObservingTest))133 return result134if __name__ == '__main__':...

Full Screen

Full Screen

coreboottest.py

Source:coreboottest.py Github

copy

Full Screen

...11from common import InteractiveTest12START_CPU_DRIVER = "Barrelfish CPU driver starting"13class CoreCtrlTest(InteractiveTest):14 '''Framework for coreboot test'''15 def get_modules(self, build, machine):16 modules = super(CoreCtrlTest, self).get_modules(build, machine)17 if machine.get_ncores() > 2:18 self.core = 219 else:20 self.core = 121 return modules22@tests.add_test23class StopCoreTest(CoreCtrlTest):24 '''Stop a core.'''25 name = 'stop_core'26 def get_modules(self, build, machine):27 modules = super(StopCoreTest, self).get_modules(build, machine)28 modules.add_module("periodicprint", args=["core=%d" % self.core ])29 return modules30 def interact(self):31 self.wait_for_fish()32 # wait for app33 self.console.expect("On core %s" % self.core)34 debug.verbose("Stopping core %s." % self.core)35 self.console.sendline("corectrl stop %s" % self.core)36 # Stop core37 debug.verbose("Wait until core is down.")38 self.console.expect("Core %s stopped." % self.core)39 # cannot wait for prompt here, as new cleanup routine will wait for40 # answer from monitor on stopped core.41 #self.wait_for_prompt()42 # Make sure app is no longer running43 i = self.console.expect(["On core %s" % self.core, pexpect.TIMEOUT], timeout=10)44 if i == 0:45 raise Exception("periodicprint still running, did we not shut-down the core?")46@tests.add_test47class UpdateKernelTest(CoreCtrlTest):48 '''Update a kernel on a core.'''49 name = 'update_kernel'50 def get_modules(self, build, machine):51 modules = super(UpdateKernelTest, self).get_modules(build, machine)52 modules.add_module("periodicprint", args=["core=%d" % self.core])53 return modules54 def interact(self):55 self.wait_for_fish()56 # wait for app57 self.console.expect("On core %s" % self.core)58 # Reboot core59 self.console.sendline("corectrl update %s" % self.core)60 self.console.expect(START_CPU_DRIVER)61 self.wait_for_prompt()62 # Make sure app is still running63 self.console.expect("On core %s" % self.core)64@tests.add_test65class ParkOSNodeTest(CoreCtrlTest):66 '''Park an OSNode on a core.'''67 name = 'park_osnode'68 def get_modules(self, build, machine):69 modules = super(ParkOSNodeTest, self).get_modules(build, machine)70 if machine.get_ncores() > 3:71 self.target_core = 372 else:73 self.target_core = 074 modules.add_module("periodicprint", args=["core=%d" % self.core])75 return modules76 def interact(self):77 self.wait_for_fish()78 self.console.expect("On core %s" % self.core)79 # Park80 debug.verbose("Park OSNode from %s on %s." % (self.core, self.target_core))81 self.console.sendline("corectrl park %s %s" % (self.core, self.target_core))82 self.wait_for_prompt()83 self.console.expect("On core %s" % self.target_core)84@tests.add_test85class ListKCBTest(CoreCtrlTest):86 '''List all KCBs.'''87 name = 'list_kcb_cores'88 def interact(self):89 self.wait_for_fish()90 self.console.sendline("corectrl lskcb")91 self.console.expect("KCB 1:")92 self.wait_for_prompt()93 self.console.sendline("corectrl lscpu")94 self.console.expect("CPU 0:")95 self.wait_for_prompt()96@tests.add_test97class ParkRebootTest(CoreCtrlTest):98 '''Park OSNode and move it back.'''99 name = 'park_boot'100 def get_modules(self, build, machine):101 modules = super(ParkRebootTest, self).get_modules(build, machine)102 self.core = 1103 if machine.get_ncores() <= 2:104 self.parking_core = 0105 else:106 self.parking_core = 2107 modules.add_module("periodicprint", args=["core=%d" % self.core])108 return modules109 def interact(self):110 self.wait_for_fish()111 self.console.expect("On core %s" % self.core)112 self.console.expect("On core %s" % self.core)113 # Park114 debug.verbose("Park KCB %s on core %s." % (self.core, self.parking_core))115 self.console.sendline("corectrl park %s %s" % (self.core, self.parking_core))...

Full Screen

Full Screen

Reader_test.py

Source:Reader_test.py Github

copy

Full Screen

...10 uncommented = self.loadCFG('simple_commented')11 self.assertEqual(next(commented), next(uncommented))12 def test_create_one_module(self):13 simple = self.loadCFG('simple')14 modules = simple.get_modules()15 self.assertEqual(len(modules), 1)16 self.assertIsInstance(modules[0], Module)17 def test_create_multiple_modules(self):18 multiple = self.loadCFG('multiple')19 modules = multiple.get_modules()20 self.assertEqual(len(modules), 3)21 for module in modules:22 self.assertIsInstance(module, Module)23 def test_create_one_module_nested(self):24 nested = self.loadCFG('nested')25 modules = nested.get_modules()26 self.assertEqual(len(modules), 1)27 self.assertIsInstance(modules[0], Module)28 def test_create_multiple_modules_nested(self):29 multiple = self.loadCFG('multiple_nested')30 modules = multiple.get_modules()31 self.assertEqual(len(modules), 3)32 for module in modules:33 self.assertIsInstance(module, Module)34 def test_create_one_module_nested_without_spacing(self):35 nested = self.loadCFG('nested_without_spacing')36 modules = nested.get_modules()37 self.assertEqual(len(modules), 1)38 self.assertIsInstance(modules[0], Module)39 def test_create_one_module_nested_double(self):40 nested = self.loadCFG('nested_double')41 modules = nested.get_modules()42 self.assertEqual(len(modules), 1)43 self.assertIsInstance(modules[0], Module)44 def test_works_with_strings(self):45 simple = self.loadCFG('simple')46 modules = simple.get_modules()47 string = str(modules[0])48 new_reader = Reader(string)49 modules = new_reader.get_modules()50 self.assertEqual(len(modules), 1)51 self.assertIsInstance(modules[0], Module)52 def test_unbalanced_brackets(self):53 self.assertRaises(UnbalancedBracketsError,54 self.loadCFG, 'unbalanced_1')55 self.assertRaises(UnbalancedBracketsError,...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run refurb automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful