Best Python code snippet using dbt-osmosis_python
test_refactor.py
Source:test_refactor.py
...97 r = refactor.Refactor(self.project_root, filename)98 self.assertFalse(r._is_on_symbol(offset))99@unittest.skipIf(not refactor.ROPE_AVAILABLE, "Requires Rope")100class TestFromsToImports(RefactorTestCase):101 def test_should_refactor(self):102 filename, offset = self.create_file(103 "foo.py",104 "_|_from datetime import datetime\n"105 "\n"106 "d = datetime(2013, 4, 7)\n")107 ref = refactor.Refactor(self.project_root, filename)108 (change,) = ref.get_changes("refactor_froms_to_imports", offset)109 self.assertEqual(change['action'], 'change')110 self.assertEqual(change['file'], filename)111 self.assertEqual(change['contents'],112 "import datetime\n"113 "\n"114 "d = datetime.datetime(2013, 4, 7)\n")115@unittest.skipIf(not refactor.ROPE_AVAILABLE, "Requires Rope")116class TestOrganizeImports(RefactorTestCase):117 def test_should_refactor(self):118 filename, offset = self.create_file(119 "foo.py",120 "import unittest, base64\n"121 "import datetime, json\n"122 "\n"123 "obj = json.dumps(23)\n"124 "unittest.TestCase()\n")125 ref = refactor.Refactor(self.project_root, filename)126 (change,) = ref.get_changes("refactor_organize_imports")127 self.assertEqual(change['action'], 'change')128 self.assertEqual(change['file'], filename)129 self.assertEqual(change['contents'],130 "import json\n"131 "import unittest\n"132 "\n"133 "\n"134 "obj = json.dumps(23)\n"135 "unittest.TestCase()\n")136@unittest.skipIf(not refactor.ROPE_AVAILABLE, "Requires Rope")137class TestModuleToPackage(RefactorTestCase):138 def test_should_refactor(self):139 filename, offset = self.create_file(140 "foo.py",141 "_|_import os\n")142 ref = refactor.Refactor(self.project_root, filename)143 changes = ref.refactor_module_to_package()144 a, b, c = changes145 # Not sure why the a change is there. It's a CHANGE that146 # changes nothing...147 self.assertEqual(a['diff'], '')148 self.assertEqual(b['action'], 'create')149 self.assertEqual(b['type'], 'directory')150 self.assertEqual(b['path'], os.path.join(self.project_root, "foo"))151 self.assertEqual(c['action'], 'move')152 self.assertEqual(c['type'], 'file')153 self.assertEqual(c['source'], os.path.join(self.project_root,154 "foo.py"))155 self.assertEqual(c['destination'], os.path.join(self.project_root,156 "foo/__init__.py"))157@unittest.skipIf(not refactor.ROPE_AVAILABLE, "Requires Rope")158class TestRenameAtPoint(RefactorTestCase):159 def test_should_refactor(self):160 filename, offset = self.create_file(161 "foo.py",162 "class Foo(object):\n"163 " def _|_foo(self):\n"164 " return 5\n"165 "\n"166 " def bar(self):\n"167 " return self.foo()\n")168 file2, offset2 = self.create_file(169 "bar.py",170 "import foo\n"171 "\n"172 "\n"173 "x = foo.Foo()\n"174 "x.foo()")175 ref = refactor.Refactor(self.project_root, filename)176 first, second = ref.refactor_rename_at_point(offset, "frob")177 if first['file'] == filename:178 a, b = first, second179 else:180 a, b = second, first181 self.assertEqual(a['action'], 'change')182 self.assertEqual(a['file'], filename)183 self.assertEqual(a['contents'],184 "class Foo(object):\n"185 " def frob(self):\n"186 " return 5\n"187 "\n"188 " def bar(self):\n"189 " return self.frob()\n")190 self.assertEqual(b['action'], 'change')191 self.assertEqual(b['file'], file2)192 self.assertEqual(b['contents'],193 "import foo\n"194 "\n"195 "\n"196 "x = foo.Foo()\n"197 "x.frob()")198@unittest.skipIf(not refactor.ROPE_AVAILABLE, "Requires Rope")199class TestRenameCurrentModule(RefactorTestCase):200 def test_should_refactor(self):201 filename, offset = self.create_file(202 "foo.py",203 "_|_import os\n")204 file2, offset = self.create_file(205 "bar.py",206 "_|_import foo\n"207 "foo.os\n")208 dest = os.path.join(self.project_root, "frob.py")209 ref = refactor.Refactor(self.project_root, filename)210 a, b = ref.refactor_rename_current_module("frob")211 self.assertEqual(a['action'], 'change')212 self.assertEqual(a['file'], file2)213 self.assertEqual(a['contents'],214 "import frob\n"215 "frob.os\n")216 self.assertEqual(b['action'], 'move')217 self.assertEqual(b['type'], 'file')218 self.assertEqual(b['source'], filename)219 self.assertEqual(b['destination'], dest)220@unittest.skipIf(not refactor.ROPE_AVAILABLE, "Requires Rope")221class TestMoveModule(RefactorTestCase):222 def test_should_refactor(self):223 filename, offset = self.create_file(224 "foo.py",225 "_|_import os\n")226 file2, offset = self.create_file(227 "bar.py",228 "_|_import foo\n"229 "foo.os\n")230 dest = os.path.join(self.project_root, "frob")231 os.mkdir(dest)232 with open(os.path.join(dest, "__init__.py"), "w") as f:233 f.write("")234 ref = refactor.Refactor(self.project_root, filename)235 a, b = ref.refactor_move_module(dest)236 self.assertEqual(a['action'], 'change')237 self.assertEqual(a['file'], file2)238 self.assertEqual(a['contents'],239 "import frob.foo\n"240 "frob.foo.os\n")241 self.assertEqual(b['action'], 'move')242 self.assertEqual(b['type'], 'file')243 self.assertEqual(b['source'], filename)244 self.assertEqual(b['destination'],245 os.path.join(dest, "foo.py"))246@unittest.skipIf(not refactor.ROPE_AVAILABLE, "Requires Rope")247class TestCreateInline(RefactorTestCase):248 def setUp(self):249 super(TestCreateInline, self).setUp()250 self.filename, self.offset = self.create_file(251 "foo.py",252 "def add(a, b):\n"253 " return a + b\n"254 "\n"255 "x = _|_add(2, 3)\n"256 "y = add(17, 4)\n")257 def test_should_refactor_single_occurrenc(self):258 ref = refactor.Refactor(self.project_root, self.filename)259 (change,) = ref.refactor_create_inline(self.offset, True)260 self.assertEqual(change['action'], 'change')261 self.assertEqual(change['file'], self.filename)262 self.assertEqual(change['contents'],263 "def add(a, b):\n"264 " return a + b\n"265 "\n"266 "x = 2 + 3\n"267 "y = add(17, 4)\n")268 def test_should_refactor_all_occurrencs(self):269 ref = refactor.Refactor(self.project_root, self.filename)270 (change,) = ref.refactor_create_inline(self.offset, False)271 self.assertEqual(change['action'], 'change')272 self.assertEqual(change['file'], self.filename)273 self.assertEqual(change['contents'],274 "x = 2 + 3\n"275 "y = 17 + 4\n")276@unittest.skipIf(not refactor.ROPE_AVAILABLE, "Requires Rope")277class TestExtractMethod(RefactorTestCase):278 def setUp(self):279 super(TestExtractMethod, self).setUp()280 self.filename, self.offset = self.create_file(281 "foo.py",282 "class Foo(object):\n"283 " def spaghetti(self, a, b):\n"284 " _|_x = a + 5\n"285 " y = b + 23\n"286 " return y\n")287 def test_should_refactor_local(self):288 ref = refactor.Refactor(self.project_root, self.filename)289 (change,) = ref.refactor_extract_method(self.offset, 104,290 "calc", False)291 self.assertEqual(change['action'], 'change')292 self.assertEqual(change['file'], self.filename)293 expected = ("class Foo(object):\n"294 " def spaghetti(self, a, b):\n"295 " return self.calc(a, b)\n"296 "\n"297 " def calc(self, a, b):\n"298 " x = a + 5\n"299 " y = b + 23\n"300 " return y\n")301 expected2 = expected.replace("return self.calc(a, b)",302 "return self.calc(b, a)")303 expected2 = expected2.replace("def calc(self, a, b)",304 "def calc(self, b, a)")305 if change['contents'] == expected2:306 self.assertEqual(change['contents'], expected2)307 else:308 self.assertEqual(change['contents'], expected)309 def test_should_refactor_global(self):310 ref = refactor.Refactor(self.project_root, self.filename)311 (change,) = ref.refactor_extract_method(self.offset, 104,312 "calc", True)313 self.assertEqual(change['action'], 'change')314 self.assertEqual(change['file'], self.filename)315 expected = ("class Foo(object):\n"316 " def spaghetti(self, a, b):\n"317 " return calc(a, b)\n"318 "\n"319 "def calc(a, b):\n"320 " x = a + 5\n"321 " y = b + 23\n"322 " return y\n")323 expected2 = expected.replace("return calc(a, b)",324 "return calc(b, a)")325 expected2 = expected2.replace("def calc(a, b)",326 "def calc(b, a)")327 if change['contents'] == expected2:328 self.assertEqual(change['contents'], expected2)329 else:330 self.assertEqual(change['contents'], expected)331@unittest.skipIf(not refactor.ROPE_AVAILABLE, "Requires Rope")332class TestUseFunction(RefactorTestCase):333 def test_should_refactor(self):334 filename, offset = self.create_file(335 "foo.py",336 "def _|_add_and_multiply(a, b, c):\n"337 " temp = a + b\n"338 " return temp * c\n"339 "\n"340 "f = 1 + 2\n"341 "g = f * 3\n")342 ref = refactor.Refactor(self.project_root, filename)343 (change,) = ref.refactor_use_function(offset)344 self.assertEqual(change['action'], 'change')345 self.assertEqual(change['file'], filename)346 self.assertEqual(change['contents'],347 "def add_and_multiply(a, b, c):\n"...
__init__.py
Source:__init__.py
1from .refactor import JavascriptEnhancementsRefactorCommand2from .refactor_preview import RefactorPreview3from .safe_move import JavascriptEnhancementsRefactorSafeMoveCommand4from .safe_delete import JavascriptEnhancementsRefactorSafeDeleteCommand5from .safe_copy import JavascriptEnhancementsRefactorSafeCopyCommand6from .extract_variable import JavascriptEnhancementsRefactorExtractVariableCommand7from .extract_parameter import JavascriptEnhancementsRefactorExtractParameterCommand8from .extract_method import JavascriptEnhancementsRefactorExtractMethodCommand9from .extract_field import JavascriptEnhancementsRefactorExtractFieldCommand10from .export import JavascriptEnhancementsRefactorExportCommand11from .convert_to_arrow_function import JavascriptEnhancementsRefactorConvertToArrowFunctionCommand12__all__ = [13 "JavascriptEnhancementsRefactorCommand",14 "RefactorPreview",15 "JavascriptEnhancementsRefactorSafeMoveCommand",16 "JavascriptEnhancementsRefactorSafeDeleteCommand",17 "JavascriptEnhancementsRefactorSafeCopyCommand",18 "JavascriptEnhancementsRefactorExtractVariableCommand",19 "JavascriptEnhancementsRefactorExtractParameterCommand",20 "JavascriptEnhancementsRefactorExtractMethodCommand",21 "JavascriptEnhancementsRefactorExtractFieldCommand",22 "JavascriptEnhancementsRefactorExportCommand",23 "JavascriptEnhancementsRefactorConvertToArrowFunctionCommand"...
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!!