Best Python code snippet using autotest_python
extracttest.py
Source:extracttest.py
...52 def test_simple_extract_function_with_parameter(self):53 code = "def a_func():\n a_var = 10\n print(a_var)\n"54 start, end = self._convert_line_range_to_offset(code, 3, 3)55 refactored = self.do_extract_method(code, start, end, 'new_func')56 expected = "def a_func():\n a_var = 10\n new_func(a_var)\n\n" \57 "def new_func(a_var):\n print(a_var)\n"58 self.assertEquals(expected, refactored)59 def test_not_unread_variables_as_parameter(self):60 code = "def a_func():\n a_var = 10\n print('hey')\n"61 start, end = self._convert_line_range_to_offset(code, 3, 3)62 refactored = self.do_extract_method(code, start, end, 'new_func')63 expected = "def a_func():\n a_var = 10\n new_func()\n\n" \64 "def new_func():\n print('hey')\n"65 self.assertEquals(expected, refactored)66 def test_simple_extract_function_with_two_parameter(self):67 code = 'def a_func():\n a_var = 10\n another_var = 20\n' \68 ' third_var = a_var + another_var\n'69 start, end = self._convert_line_range_to_offset(code, 4, 4)70 refactored = self.do_extract_method(code, start, end, 'new_func')71 expected = 'def a_func():\n a_var = 10\n another_var = 20\n' \72 ' new_func(a_var, another_var)\n\n' \73 'def new_func(a_var, another_var):\n' \74 ' third_var = a_var + another_var\n'75 self.assertEquals(expected, refactored)76 def test_simple_extract_function_with_return_value(self):77 code = 'def a_func():\n a_var = 10\n print(a_var)\n'78 start, end = self._convert_line_range_to_offset(code, 2, 2)79 refactored = self.do_extract_method(code, start, end, 'new_func')80 expected = 'def a_func():\n a_var = new_func()\n print(a_var)\n\n' \81 'def new_func():\n a_var = 10\n return a_var\n'82 self.assertEquals(expected, refactored)83 def test_extract_function_with_multiple_return_values(self):84 code = 'def a_func():\n a_var = 10\n another_var = 20\n' \85 ' third_var = a_var + another_var\n'86 start, end = self._convert_line_range_to_offset(code, 2, 3)87 refactored = self.do_extract_method(code, start, end, 'new_func')88 expected = 'def a_func():\n a_var, another_var = new_func()\n' \89 ' third_var = a_var + another_var\n\n' \90 'def new_func():\n a_var = 10\n another_var = 20\n' \91 ' return a_var, another_var\n'92 self.assertEquals(expected, refactored)93 def test_simple_extract_method(self):94 code = 'class AClass(object):\n\n' \95 ' def a_func(self):\n print(1)\n print(2)\n'96 start, end = self._convert_line_range_to_offset(code, 4, 4)97 refactored = self.do_extract_method(code, start, end, 'new_func')98 expected = 'class AClass(object):\n\n' \99 ' def a_func(self):\n' \100 ' self.new_func()\n' \101 ' print(2)\n\n' \102 ' def new_func(self):\n print(1)\n'103 self.assertEquals(expected, refactored)104 def test_extract_method_with_args_and_returns(self):105 code = 'class AClass(object):\n' \106 ' def a_func(self):\n' \107 ' a_var = 10\n' \108 ' another_var = a_var * 3\n' \109 ' third_var = a_var + another_var\n'110 start, end = self._convert_line_range_to_offset(code, 4, 4)111 refactored = self.do_extract_method(code, start, end, 'new_func')112 expected = 'class AClass(object):\n' \113 ' def a_func(self):\n' \114 ' a_var = 10\n' \115 ' another_var = self.new_func(a_var)\n' \116 ' third_var = a_var + another_var\n\n' \117 ' def new_func(self, a_var):\n' \118 ' another_var = a_var * 3\n' \119 ' return another_var\n'120 self.assertEquals(expected, refactored)121 def test_extract_method_with_self_as_argument(self):122 code = 'class AClass(object):\n' \123 ' def a_func(self):\n' \124 ' print(self)\n'125 start, end = self._convert_line_range_to_offset(code, 3, 3)126 refactored = self.do_extract_method(code, start, end, 'new_func')127 expected = 'class AClass(object):\n' \128 ' def a_func(self):\n' \129 ' self.new_func()\n\n' \130 ' def new_func(self):\n' \131 ' print(self)\n'132 self.assertEquals(expected, refactored)133 @testutils.assert_raises(rope.base.exceptions.RefactoringError)134 def test_extract_method_with_no_self_as_argument(self):135 code = 'class AClass(object):\n' \136 ' def a_func():\n' \137 ' print(1)\n'138 start, end = self._convert_line_range_to_offset(code, 3, 3)139 refactored = self.do_extract_method(code, start, end, 'new_func')140 def test_extract_method_with_multiple_methods(self):141 code = 'class AClass(object):\n' \142 ' def a_func(self):\n' \143 ' print(self)\n\n' \144 ' def another_func(self):\n' \145 ' pass\n'146 start, end = self._convert_line_range_to_offset(code, 3, 3)147 refactored = self.do_extract_method(code, start, end, 'new_func')148 expected = 'class AClass(object):\n' \149 ' def a_func(self):\n' \150 ' self.new_func()\n\n' \151 ' def new_func(self):\n' \152 ' print(self)\n\n' \153 ' def another_func(self):\n' \154 ' pass\n'155 self.assertEquals(expected, refactored)156 def test_extract_function_with_function_returns(self):157 code = 'def a_func():\n def inner_func():\n pass\n' \158 ' inner_func()\n'159 start, end = self._convert_line_range_to_offset(code, 2, 3)160 refactored = self.do_extract_method(code, start, end, 'new_func')161 expected = 'def a_func():\n' \162 ' inner_func = new_func()\n inner_func()\n\n' \163 'def new_func():\n' \164 ' def inner_func():\n pass\n' \165 ' return inner_func\n'166 self.assertEquals(expected, refactored)167 def test_simple_extract_global_function(self):168 code = "print('one')\nprint('two')\nprint('three')\n"169 start, end = self._convert_line_range_to_offset(code, 2, 2)170 refactored = self.do_extract_method(code, start, end, 'new_func')171 expected = "print('one')\n\ndef new_func():\n print('two')\n" \172 "\nnew_func()\nprint('three')\n"173 self.assertEquals(expected, refactored)174 def test_extract_global_function_inside_ifs(self):175 code = 'if True:\n a = 10\n'176 start, end = self._convert_line_range_to_offset(code, 2, 2)177 refactored = self.do_extract_method(code, start, end, 'new_func')178 expected = '\ndef new_func():\n a = 10\n\nif True:\n' \179 ' new_func()\n'180 self.assertEquals(expected, refactored)181 def test_extract_function_while_inner_function_reads(self):182 code = 'def a_func():\n a_var = 10\n' \183 ' def inner_func():\n print(a_var)\n' \184 ' return inner_func\n'185 start, end = self._convert_line_range_to_offset(code, 3, 4)186 refactored = self.do_extract_method(code, start, end, 'new_func')187 expected = 'def a_func():\n a_var = 10\n' \188 ' inner_func = new_func(a_var)\n return inner_func\n\n' \189 'def new_func(a_var):\n' \190 ' def inner_func():\n print(a_var)\n' \191 ' return inner_func\n'192 self.assertEquals(expected, refactored)193 @testutils.assert_raises(rope.base.exceptions.RefactoringError)194 def test_extract_method_bad_range(self):195 code = "def a_func():\n pass\na_var = 10\n"196 start, end = self._convert_line_range_to_offset(code, 2, 3)197 self.do_extract_method(code, start, end, 'new_func')198 @testutils.assert_raises(rope.base.exceptions.RefactoringError)199 def test_extract_method_bad_range2(self):200 code = "class AClass(object):\n pass\n"201 start, end = self._convert_line_range_to_offset(code, 1, 1)202 self.do_extract_method(code, start, end, 'new_func')203 @testutils.assert_raises(rope.base.exceptions.RefactoringError)204 def test_extract_method_containing_return(self):205 code = 'def a_func(arg):\n if arg:\n return arg * 2\n return 1'206 start, end = self._convert_line_range_to_offset(code, 2, 4)207 self.do_extract_method(code, start, end, 'new_func')208 @testutils.assert_raises(rope.base.exceptions.RefactoringError)209 def test_extract_method_containing_yield(self):210 code = "def a_func(arg):\n yield arg * 2\n"211 start, end = self._convert_line_range_to_offset(code, 2, 2)212 self.do_extract_method(code, start, end, 'new_func')213 @testutils.assert_raises(rope.base.exceptions.RefactoringError)214 def test_extract_method_containing_uncomplete_lines(self):215 code = 'a_var = 20\nanother_var = 30\n'216 start = code.index('20')217 end = code.index('30') + 2218 self.do_extract_method(code, start, end, 'new_func')219 @testutils.assert_raises(rope.base.exceptions.RefactoringError)220 def test_extract_method_containing_uncomplete_lines2(self):221 code = 'a_var = 20\nanother_var = 30\n'222 start = code.index('20')223 end = code.index('another') + 5224 self.do_extract_method(code, start, end, 'new_func')225 def test_extract_function_and_argument_as_paramenter(self):226 code = 'def a_func(arg):\n print(arg)\n'227 start, end = self._convert_line_range_to_offset(code, 2, 2)228 refactored = self.do_extract_method(code, start, end, 'new_func')229 expected = 'def a_func(arg):\n new_func(arg)\n\n' \230 'def new_func(arg):\n print(arg)\n'231 self.assertEquals(expected, refactored)232 def test_extract_function_and_end_as_the_start_of_a_line(self):233 code = 'print("hey")\nif True:\n pass\n'234 start = 0235 end = code.index('\n') + 1236 refactored = self.do_extract_method(code, start, end, 'new_func')237 expected = '\ndef new_func():\n print("hey")\n\n' \238 'new_func()\nif True:\n pass\n'239 self.assertEquals(expected, refactored)240 def test_extract_function_and_indented_blocks(self):241 code = 'def a_func(arg):\n if True:\n' \242 ' if True:\n print(arg)\n'243 start, end = self._convert_line_range_to_offset(code, 3, 4)244 refactored = self.do_extract_method(code, start, end, 'new_func')245 expected = 'def a_func(arg):\n if True:\n new_func(arg)\n\n' \246 'def new_func(arg):\n if True:\n print(arg)\n'247 self.assertEquals(expected, refactored)248 def test_extract_method_and_multi_line_headers(self):249 code = 'def a_func(\n arg):\n print(arg)\n'250 start, end = self._convert_line_range_to_offset(code, 3, 3)251 refactored = self.do_extract_method(code, start, end, 'new_func')252 expected = 'def a_func(\n arg):\n new_func(arg)\n\n' \253 'def new_func(arg):\n print(arg)\n'254 self.assertEquals(expected, refactored)255 def test_single_line_extract_function(self):256 code = 'a_var = 10 + 20\n'257 start = code.index('10')258 end = code.index('20') + 2259 refactored = self.do_extract_method(code, start, end, 'new_func')260 expected = "\ndef new_func():\n return 10 + 20\n\na_var = new_func()\n"261 self.assertEquals(expected, refactored)262 def test_single_line_extract_function2(self):263 code = 'def a_func():\n a = 10\n b = a * 20\n'264 start = code.rindex('a')265 end = code.index('20') + 2266 refactored = self.do_extract_method(code, start, end, 'new_func')267 expected = 'def a_func():\n a = 10\n b = new_func(a)\n' \268 '\ndef new_func(a):\n return a * 20\n'269 self.assertEquals(expected, refactored)270 def test_single_line_extract_method_and_logical_lines(self):271 code = 'a_var = 10 +\\\n 20\n'272 start = code.index('10')273 end = code.index('20') + 2274 refactored = self.do_extract_method(code, start, end, 'new_func')275 expected = '\ndef new_func():\n return 10 + 20\n\na_var = new_func()\n'276 self.assertEquals(expected, refactored)277 def test_single_line_extract_method_and_logical_lines2(self):278 code = 'a_var = (10,\\\n 20)\n'279 start = code.index('10') - 1280 end = code.index('20') + 3281 refactored = self.do_extract_method(code, start, end, 'new_func')282 expected = '\ndef new_func():\n' \283 ' return (10, 20)\n\na_var = new_func()\n'284 self.assertEquals(expected, refactored)285 def test_single_line_extract_method(self):286 code = "class AClass(object):\n\n" \287 " def a_func(self):\n a = 10\n b = a * a\n"288 start = code.rindex('=') + 2289 end = code.rindex('a') + 1290 refactored = self.do_extract_method(code, start, end, 'new_func')291 expected = 'class AClass(object):\n\n' \292 ' def a_func(self):\n' \293 ' a = 10\n b = self.new_func(a)\n\n' \294 ' def new_func(self, a):\n return a * a\n'295 self.assertEquals(expected, refactored)296 def test_single_line_extract_function_if_condition(self):297 code = 'if True:\n pass\n'298 start = code.index('True')299 end = code.index('True') + 4300 refactored = self.do_extract_method(code, start, end, 'new_func')301 expected = "\ndef new_func():\n return True\n\nif new_func():\n pass\n"302 self.assertEquals(expected, refactored)303 def test_unneeded_params(self):304 code = 'class A(object):\n ' \305 'def a_func(self):\n a_var = 10\n a_var += 2\n'306 start = code.rindex('2')307 end = code.rindex('2') + 1308 refactored = self.do_extract_method(code, start, end, 'new_func')309 expected = 'class A(object):\n' \310 ' def a_func(self):\n a_var = 10\n' \311 ' a_var += self.new_func()\n\n' \312 ' def new_func(self):\n return 2\n'313 self.assertEquals(expected, refactored)314 def test_breaks_and_continues_inside_loops(self):315 code = 'def a_func():\n for i in range(10):\n continue\n'316 start = code.index('for')317 end = len(code) - 1318 refactored = self.do_extract_method(code, start, end, 'new_func')319 expected = 'def a_func():\n new_func()\n\n' \320 'def new_func():\n' \321 ' for i in range(10):\n continue\n'322 self.assertEquals(expected, refactored)323 @testutils.assert_raises(rope.base.exceptions.RefactoringError)324 def test_breaks_and_continues_outside_loops(self):325 code = 'def a_func():\n' \326 ' for i in range(10):\n a = i\n continue\n'327 start = code.index('a = i')328 end = len(code) - 1329 refactored = self.do_extract_method(code, start, end, 'new_func')330 def test_variable_writes_followed_by_variable_reads_after_extraction(self):331 code = 'def a_func():\n a = 1\n a = 2\n b = a\n'332 start = code.index('a = 1')333 end = code.index('a = 2') - 1334 refactored = self.do_extract_method(code, start, end, 'new_func')335 expected = 'def a_func():\n new_func()\n a = 2\n b = a\n\n' \336 'def new_func():\n a = 1\n'337 self.assertEquals(expected, refactored)338 def test_variable_writes_followed_by_variable_reads_inside_extraction(self):339 code = 'def a_func():\n a = 1\n a = 2\n b = a\n'340 start = code.index('a = 2')341 end = len(code) - 1342 refactored = self.do_extract_method(code, start, end, 'new_func')343 expected = 'def a_func():\n a = 1\n new_func()\n\n' \344 'def new_func():\n a = 2\n b = a\n'345 self.assertEquals(expected, refactored)346 def test_extract_variable(self):347 code = 'a_var = 10 + 20\n'348 start = code.index('10')349 end = code.index('20') + 2350 refactored = self.do_extract_variable(code, start, end, 'new_var')351 expected = 'new_var = 10 + 20\na_var = new_var\n'352 self.assertEquals(expected, refactored)353 def test_extract_variable_multiple_lines(self):354 code = 'a = 1\nb = 2\n'355 start = code.index('1')356 end = code.index('1') + 1357 refactored = self.do_extract_variable(code, start, end, 'c')358 expected = 'c = 1\na = c\nb = 2\n'359 self.assertEquals(expected, refactored)360 def test_extract_variable_in_the_middle_of_statements(self):361 code = 'a = 1 + 2\n'362 start = code.index('1')363 end = code.index('1') + 1364 refactored = self.do_extract_variable(code, start, end, 'c')365 expected = 'c = 1\na = c + 2\n'366 self.assertEquals(expected, refactored)367 def test_extract_variable_for_a_tuple(self):368 code = 'a = 1, 2\n'369 start = code.index('1')370 end = code.index('2') + 1371 refactored = self.do_extract_variable(code, start, end, 'c')372 expected = 'c = 1, 2\na = c\n'373 self.assertEquals(expected, refactored)374 def test_extract_variable_for_a_string(self):375 code = 'def a_func():\n a = "hey!"\n'376 start = code.index('"')377 end = code.rindex('"') + 1378 refactored = self.do_extract_variable(code, start, end, 'c')379 expected = 'def a_func():\n c = "hey!"\n a = c\n'380 self.assertEquals(expected, refactored)381 def test_extract_variable_inside_ifs(self):382 code = 'if True:\n a = 1 + 2\n'383 start = code.index('1')384 end = code.rindex('2') + 1385 refactored = self.do_extract_variable(code, start, end, 'b')386 expected = 'if True:\n b = 1 + 2\n a = b\n'387 self.assertEquals(expected, refactored)388 def test_extract_variable_inside_ifs_and_logical_lines(self):389 code = 'if True:\n a = (3 + \n(1 + 2))\n'390 start = code.index('1')391 end = code.index('2') + 1392 refactored = self.do_extract_variable(code, start, end, 'b')393 expected = 'if True:\n b = 1 + 2\n a = (3 + \n(b))\n'394 self.assertEquals(expected, refactored)395 # TODO: Handle when extracting a subexpression396 def xxx_test_extract_variable_for_a_subexpression(self):397 code = 'a = 3 + 1 + 2\n'398 start = code.index('1')399 end = code.index('2') + 1400 refactored = self.do_extract_variable(code, start, end, 'b')401 expected = 'b = 1 + 2\na = 3 + b\n'402 self.assertEquals(expected, refactored)403 def test_extract_variable_starting_from_the_start_of_the_line(self):404 code = 'a_dict = {1: 1}\na_dict.values().count(1)\n'405 start = code.rindex('a_dict')406 end = code.index('count') - 1407 refactored = self.do_extract_variable(code, start, end, 'values')408 expected = 'a_dict = {1: 1}\nvalues = a_dict.values()\nvalues.count(1)\n'409 self.assertEquals(expected, refactored)410 def test_extract_variable_on_the_last_line_of_a_function(self):411 code = 'def f():\n a_var = {}\n a_var.keys()\n'412 start = code.rindex('a_var')413 end = code.index('.keys')414 refactored = self.do_extract_variable(code, start, end, 'new_var')415 expected = 'def f():\n a_var = {}\n new_var = a_var\n new_var.keys()\n'416 self.assertEquals(expected, refactored)417 def test_extract_variable_on_the_indented_function_statement(self):418 code = 'def f():\n if True:\n a_var = 1 + 2\n'419 start = code.index('1')420 end = code.index('2') + 1421 refactored = self.do_extract_variable(code, start, end, 'new_var')422 expected = 'def f():\n if True:\n' \423 ' new_var = 1 + 2\n a_var = new_var\n'424 self.assertEquals(expected, refactored)425 def test_extract_method_on_the_last_line_of_a_function(self):426 code = 'def f():\n a_var = {}\n a_var.keys()\n'427 start = code.rindex('a_var')428 end = code.index('.keys')429 refactored = self.do_extract_method(code, start, end, 'new_f')430 expected = 'def f():\n a_var = {}\n new_f(a_var).keys()\n\n' \431 'def new_f(a_var):\n return a_var\n'432 self.assertEquals(expected, refactored)433 @testutils.assert_raises(rope.base.exceptions.RefactoringError)434 def test_raising_exception_when_on_incomplete_variables(self):435 code = 'a_var = 10 + 20\n'436 start = code.index('10') + 1437 end = code.index('20') + 2438 refactored = self.do_extract_method(code, start, end, 'new_func')439 @testutils.assert_raises(rope.base.exceptions.RefactoringError)440 def test_raising_exception_when_on_incomplete_variables_on_end(self):441 code = 'a_var = 10 + 20\n'442 start = code.index('10')443 end = code.index('20') + 1444 refactored = self.do_extract_method(code, start, end, 'new_func')445 @testutils.assert_raises(rope.base.exceptions.RefactoringError)446 def test_raising_exception_on_bad_parens(self):447 code = 'a_var = (10 + 20) + 30\n'448 start = code.index('20')449 end = code.index('30') + 2450 refactored = self.do_extract_method(code, start, end, 'new_func')451 @testutils.assert_raises(rope.base.exceptions.RefactoringError)452 def test_raising_exception_on_bad_operators(self):453 code = 'a_var = 10 + 20 + 30\n'454 start = code.index('10')455 end = code.rindex('+') + 1456 refactored = self.do_extract_method(code, start, end, 'new_func')457 # FIXME: Extract method should be more intelligent about bad ranges458 @testutils.assert_raises(rope.base.exceptions.RefactoringError)459 def xxx_test_raising_exception_on_function_parens(self):460 code = 'a = range(10)'461 start = code.index('(')462 end = code.rindex(')') + 1463 refactored = self.do_extract_method(code, start, end, 'new_func')464 def test_extract_method_and_extra_blank_lines(self):465 code = '\nprint(1)\n'466 refactored = self.do_extract_method(code, 0, len(code), 'new_f')467 expected = '\n\ndef new_f():\n print(1)\n\nnew_f()\n'468 self.assertEquals(expected, refactored)469 def test_variable_writes_in_the_same_line_as_variable_read(self):470 code = 'a = 1\na = 1 + a\n'471 start = code.index('\n') + 1472 end = len(code)473 refactored = self.do_extract_method(code, start, end, 'new_f',474 global_=True)475 expected = 'a = 1\n\ndef new_f(a):\n a = 1 + a\n\nnew_f(a)\n'476 self.assertEquals(expected, refactored)477 def test_variable_writes_in_the_same_line_as_variable_read2(self):478 code = 'a = 1\na += 1\n'479 start = code.index('\n') + 1480 end = len(code)481 refactored = self.do_extract_method(code, start, end, 'new_f',482 global_=True)483 expected = 'a = 1\n\ndef new_f():\n a += 1\n\nnew_f()\n'484 self.assertEquals(expected, refactored)485 def test_variable_and_similar_expressions(self):486 code = 'a = 1\nb = 1\n'487 start = code.index('1')488 end = start + 1489 refactored = self.do_extract_variable(code, start, end,490 'one', similar=True)491 expected = 'one = 1\na = one\nb = one\n'492 self.assertEquals(expected, refactored)493 def test_definition_should_appear_before_the_first_use(self):494 code = 'a = 1\nb = 1\n'495 start = code.rindex('1')496 end = start + 1497 refactored = self.do_extract_variable(code, start, end,498 'one', similar=True)499 expected = 'one = 1\na = one\nb = one\n'500 self.assertEquals(expected, refactored)501 def test_extract_method_and_similar_expressions(self):502 code = 'a = 1\nb = 1\n'503 start = code.index('1')504 end = start + 1505 refactored = self.do_extract_method(code, start, end,506 'one', similar=True)507 expected = '\ndef one():\n return 1\n\na = one()\nb = one()\n'508 self.assertEquals(expected, refactored)509 def test_simple_extract_method_and_similar_statements(self):510 code = 'class AClass(object):\n\n' \511 ' def func1(self):\n a = 1 + 2\n b = a\n' \512 ' def func2(self):\n a = 1 + 2\n b = a\n'513 start, end = self._convert_line_range_to_offset(code, 4, 4)514 refactored = self.do_extract_method(code, start, end,515 'new_func', similar=True)516 expected = 'class AClass(object):\n\n' \517 ' def func1(self):\n' \518 ' a = self.new_func()\n b = a\n\n' \519 ' def new_func(self):\n' \520 ' a = 1 + 2\n return a\n' \521 ' def func2(self):\n' \522 ' a = self.new_func()\n b = a\n'523 self.assertEquals(expected, refactored)524 def test_extract_method_and_similar_statements2(self):525 code = 'class AClass(object):\n\n' \526 ' def func1(self, p1):\n a = p1 + 2\n' \527 ' def func2(self, p2):\n a = p2 + 2\n'528 start = code.rindex('p1')529 end = code.index('2\n') + 1530 refactored = self.do_extract_method(code, start, end,531 'new_func', similar=True)532 expected = 'class AClass(object):\n\n' \533 ' def func1(self, p1):\n a = self.new_func(p1)\n\n' \534 ' def new_func(self, p1):\n return p1 + 2\n' \535 ' def func2(self, p2):\n a = self.new_func(p2)\n'536 self.assertEquals(expected, refactored)537 def test_extract_method_and_similar_statements_where_return_is_different(self):538 code = 'class AClass(object):\n\n' \539 ' def func1(self, p1):\n a = p1 + 2\n' \540 ' def func2(self, p2):\n self.attr = p2 + 2\n'541 start = code.rindex('p1')542 end = code.index('2\n') + 1543 refactored = self.do_extract_method(code, start, end,544 'new_func', similar=True)545 expected = 'class AClass(object):\n\n' \546 ' def func1(self, p1):\n a = self.new_func(p1)\n\n' \547 ' def new_func(self, p1):\n return p1 + 2\n' \548 ' def func2(self, p2):\n self.attr = self.new_func(p2)\n'549 self.assertEquals(expected, refactored)550 def test_definition_should_appear_where_it_is_visible(self):551 code = 'if True:\n a = 1\nelse:\n b = 1\n'552 start = code.rindex('1')553 end = start + 1554 refactored = self.do_extract_variable(code, start, end,555 'one', similar=True)556 expected = 'one = 1\nif True:\n a = one\nelse:\n b = one\n'557 self.assertEquals(expected, refactored)558 def test_extract_variable_and_similar_statements_in_classes(self):559 code = 'class AClass(object):\n\n' \560 ' def func1(self):\n a = 1\n' \561 ' def func2(self):\n b = 1\n'562 start = code.index(' 1') + 1563 refactored = self.do_extract_variable(code, start, start + 1,564 'one', similar=True)565 expected = 'class AClass(object):\n\n' \566 ' def func1(self):\n one = 1\n a = one\n' \567 ' def func2(self):\n b = 1\n'568 self.assertEquals(expected, refactored)569 def test_extract_method_in_staticmethods(self):570 code = 'class AClass(object):\n\n' \571 ' @staticmethod\n def func2():\n b = 1\n'572 start = code.index(' 1') + 1573 refactored = self.do_extract_method(code, start, start + 1,574 'one', similar=True)575 expected = 'class AClass(object):\n\n' \576 ' @staticmethod\n def func2():\n' \577 ' b = AClass.one()\n\n' \578 ' @staticmethod\n def one():\n' \579 ' return 1\n'580 self.assertEquals(expected, refactored)581 def test_extract_normal_method_with_staticmethods(self):582 code = 'class AClass(object):\n\n' \583 ' @staticmethod\n def func1():\n b = 1\n' \584 ' def func2(self):\n b = 1\n'585 start = code.rindex(' 1') + 1586 refactored = self.do_extract_method(code, start, start + 1,587 'one', similar=True)588 expected = 'class AClass(object):\n\n' \589 ' @staticmethod\n def func1():\n b = 1\n' \590 ' def func2(self):\n b = self.one()\n\n' \591 ' def one(self):\n return 1\n'592 self.assertEquals(expected, refactored)593 def test_extract_variable_with_no_new_lines_at_the_end(self):594 code = 'a_var = 10'595 start = code.index('10')596 end = start + 2597 refactored = self.do_extract_variable(code, start, end, 'new_var')598 expected = 'new_var = 10\na_var = new_var'599 self.assertEquals(expected, refactored)600 def test_extract_method_containing_return_in_functions(self):601 code = 'def f(arg):\n return arg\nprint(f(1))\n'602 start, end = self._convert_line_range_to_offset(code, 1, 3)603 refactored = self.do_extract_method(code, start, end, 'a_func')604 expected = '\ndef a_func():\n def f(arg):\n return arg\n' \605 ' print(f(1))\n\na_func()\n'606 self.assertEquals(expected, refactored)607 def test_extract_method_and_varying_first_parameter(self):608 code = 'class C(object):\n' \609 ' def f1(self):\n print(str(self))\n' \610 ' def f2(self):\n print(str(1))\n'611 start = code.index('print(') + 6612 end = code.index('))\n') + 1613 refactored = self.do_extract_method(code, start, end,614 'to_str', similar=True)615 expected = 'class C(object):\n' \616 ' def f1(self):\n print(self.to_str())\n\n' \617 ' def to_str(self):\n return str(self)\n' \618 ' def f2(self):\n print(str(1))\n'619 self.assertEquals(expected, refactored)620 def test_extract_method_when_an_attribute_exists_in_function_scope(self):621 code = 'class A(object):\n def func(self):\n pass\n' \622 'a = A()\n' \623 'def f():\n' \624 ' func = a.func()\n' \625 ' print func\n'626 start, end = self._convert_line_range_to_offset(code, 6, 6)627 refactored = self.do_extract_method(code, start, end, 'g')628 refactored = refactored[refactored.index('A()') + 4:]629 expected = 'def f():\n func = g()\n print func\n\n' \630 'def g():\n func = a.func()\n return func\n'631 self.assertEquals(expected, refactored)632 def test_global_option_for_extract_method(self):633 code = 'def a_func():\n print(1)\n'634 start, end = self._convert_line_range_to_offset(code, 2, 2)635 refactored = self.do_extract_method(code, start, end,636 'extracted', global_=True)637 expected = 'def a_func():\n extracted()\n\n' \638 'def extracted():\n print(1)\n'639 self.assertEquals(expected, refactored)640 def test_global_extract_method(self):641 code = 'class AClass(object):\n\n' \642 ' def a_func(self):\n print(1)\n'643 start, end = self._convert_line_range_to_offset(code, 4, 4)644 refactored = self.do_extract_method(code, start, end,645 'new_func', global_=True)646 expected = 'class AClass(object):\n\n' \647 ' def a_func(self):\n new_func()\n\n' \648 'def new_func():\n print(1)\n'649 self.assertEquals(expected, refactored)650 def test_extract_method_with_multiple_methods(self):651 code = 'class AClass(object):\n' \652 ' def a_func(self):\n' \653 ' print(1)\n\n' \654 ' def another_func(self):\n' \655 ' pass\n'656 start, end = self._convert_line_range_to_offset(code, 3, 3)657 refactored = self.do_extract_method(code, start, end,658 'new_func', global_=True)659 expected = 'class AClass(object):\n' \660 ' def a_func(self):\n' \661 ' new_func()\n\n' \662 ' def another_func(self):\n' \663 ' pass\n\n' \664 'def new_func():\n' \665 ' print(1)\n'666 self.assertEquals(expected, refactored)667 def test_where_to_seach_when_extracting_global_names(self):668 code = 'def a():\n return 1\ndef b():\n return 1\nb = 1\n'669 start = code.index('1')670 end = start + 1671 refactored = self.do_extract_variable(code, start, end, 'one',672 similar=True, global_=True)673 expected = 'def a():\n return one\none = 1\n' \674 'def b():\n return one\nb = one\n'675 self.assertEquals(expected, refactored)676 def test_extracting_pieces_with_distinct_temp_names(self):677 code = 'a = 1\nprint a\nb = 1\nprint b\n'678 start = code.index('a')...
static_list.py
Source:static_list.py
1@new_func('sem:make_opposite', params_affected=['sem:is_opposite'])2# args -> []3def sem_make_opposite(element, arguments=[], branching=[]):4 element.set_parameter('sem:is_opposite', True)5 return element6@new_func('sem:make_causative', params_affected=['sem:causative'])7# args -> []8def sem_make_causative(element, arguments=[], branching=[]):9 element.set_parameter('sem:causative', True)10 return element11@new_func('gram:make_transitive', params_affected=['gram:transitive'])12# args -> []13def gram_make_transitive(element, arguments=[], branching=[]):14 element.set_parameter('gram:transitive', True)15 return element16@new_func('gram:number:set_sing', params_affected=['gram:number'])17# args -> []18def gram_number_set_sing(element, arguments=[], branching=[]):19 element.set_parameter('gram:number', 'sing')20 return element21@new_func('gram:number:set_dual', params_affected=['gram:number'])22# args -> []23def gram_number_set_dual(element, arguments=[], branching=[]):24 element.set_parameter('gram:number', 'dual')25 return element26@new_func('mansi:make_lp', params_affected=[])27# args -> [sing, 1]28def mansi_make_lp(element, arguments=[], branching=[]):29 element.set_parameter('gram:possessor:number', arguments[0])30 element.set_parameter('gram:possessor:person', arguments[1])31 return element32@new_func('gram:number:set_plur', params_affected=['gram:number'])33# args -> []34def gram_number_set_plur(element, arguments=[], branching=[]):35 element.set_parameter('gram:number', 'plur')36 return element37@new_func('gram:case:set_main', params_affected=['gram:case'])38# args -> []39def gram_case_set_main(element, arguments=[], branching=[]):40 element.set_parameter('gram:case', 'main')41 return element42@new_func('gram:case:set_lat', params_affected=['gram:case'])43# args -> []44def gram_case_set_lat(element, arguments=[], branching=[]):45 element.set_parameter('gram:case', 'lat')46 return element47@new_func('gram:case:set_loc', params_affected=['gram:case'])48# args -> []49def gram_case_set_loc(element, arguments=[], branching=[]):50 element.set_parameter('gram:case', 'loc')51 return element52@new_func('gram:case:set_abl', params_affected=['gram:case'])53# args -> []54def gram_case_set_abl(element, arguments=[], branching=[]):55 element.set_parameter('gram:case', 'abl')56 return element57@new_func('gram:case:set_instr', params_affected=['gram:case'])58# args -> []59def gram_case_set_instr(element, arguments=[], branching=[]):60 element.set_parameter('gram:case', 'instr')61 return element62@new_func('gram:case:set_trans', params_affected=['gram:case'])63# args -> []64def gram_case_set_trans(element, arguments=[], branching=[]):65 element.set_parameter('gram:case', 'trans')66 return element67@new_func('gram:case:set_voc', params_affected=['gram:case'])68# args -> []69def gram_case_set_voc(element, arguments=[], branching=[]):70 element.set_parameter('gram:case', 'voc')71 return element72@new_func('gram:verb:set_infinitive', params_affected=['gram:verb:infinitive'])73# args -> []74def gram_verb_set_infinitive(element, arguments=[], branching=[]):75 element.set_parameter('gram:verb:infinitive', True)76 return element77@new_func('mansi:verb_to_noun', params_affected=['mansi:from_verb'])78# args -> []79def mansi_verb_to_noun(element, arguments=[], branching=[]):80 element.set_parameter('mansi:from_verb', True)81 return element82@new_func('mansi:sem:tool-or-action', params_affected=['sem:prop2'])83# args -> []84def mansi_sem_tool_or_action(element, arguments=[], branching=[]):85 element.set_parameter('sem:prop2', True)86 return element87@new_func('mansi:adj_to_noun', params_affected=[])88# args -> []89def mansi_adj_to_noun(element, arguments=[], branching=[]):90 return element91@new_func('mansi:sem:obj-size', params_affected=[])92# args -> []93def mansi_sem_obj_size(element, arguments=[], branching=[]):94 return element95@new_func('mansi:verb_to_noun:size', params_affected=[])96# args -> []97def mansi_verb_to_noun_size(element, arguments=[], branching=[]):98 return element99@new_func('mansi:sem:coll', params_affected=[])100# args -> []101def mansi_sem_coll(element, arguments=[], branching=[]):102 return element103@new_func('gram:adj:comparative', params_affected=['gram:degree_of_comparison'])104# args -> []105def gram_adj_comparative(element, arguments=[], branching=[]):106 element.set_parameter('gram:degree_of_comparison', 'comparative')107 return element108@new_func('mansi:set_pred', params_affected=[])109# args -> []110def mansi_set_pred(element, arguments=[], branching=[]):111 element.set_parameter('gram:pred', True)112 return element113@new_func('gram:set_dimin', params_affected=[])114# args -> []115def gram_set_dimin(element, arguments=[], branching=[]):116 return element117@new_func('gram:adj:superlative', params_affected=['gram:degree_of_comparison'])118# args -> []119def gram_adj_superlative(element, arguments=[], branching=[]):120 element.set_parameter('gram:degree_of_comparison', 'superlative')121 return element122@new_func('gram:set_attr', params_affected=[])123# args -> []124def gram_set_attr(element, arguments=[], branching=[]):125 return element126@new_func('gram:noun_to_adj', params_affected=['mansi:from_noun'])127# args -> []128def gram_noun_to_adj(element, arguments=[], branching=[]):129 element.set_parameter('mansi:from_noun', True)130 return element131@new_func('sem:adj_to_noun_corresp', params_affected=['mansi:from_noune'])132# args -> []133def sem_adj_to_noun_corresp(element, arguments=[], branching=[]):134 element.set_parameter('mansi:from_noun', True)135 return element136@new_func('gram:set_participle', params_affected=['mansi:basic_pos'])137# args -> []138def gram_set_participle(element, arguments=[], branching=[]):139 element.set_parameter('mansi:basic_pos', 'participle')140 return element141@new_func('mansi:russian_loan_word', params_affected=['mansi:is_russian'])142# args -> []143def mansi_russian_loan_word(element, arguments=[], branching=[]):144 element.set_parameter('mansi:is_russian', True)145 return element146@new_func('mansi:phrase_adj', params_affected=['mansi:basic_pos'])147# args -> []148def mansi_phrase_adj(element, arguments=[], branching=[]):149 element.set_parameter('mansi:basic_pos', 'adj')150 return element151@new_func('sem:magnification_colloc', params_affected=[])152# args -> []153def sem_magnification_colloc(element, arguments=[], branching=[]):154 return element155@new_func('gram:set_ord', params_affected=['gram:numeral_cat'])156# args -> []157def gram_set_ord(element, arguments=[], branching=[]):158 element.set_parameter('gram:numeral_cat', 'ordinal')159 return element160@new_func('gram:set_mult', params_affected=['gram:numeral_cat'])161# args -> []162def gram_set_mult(element, arguments=[], branching=[]):163 element.set_parameter('gram:numeral_cat', 'mult')164 return element165@new_func('gram:numeral:co_to_repet_colloc', params_affected=['gram:numeral_cat'])166# args -> []167def gram_numeral_co_to_repet_colloc(element, arguments=[], branching=[]):168 element.set_parameter('gram:numeral_cat', 'repetitive')169 return element170@new_func('gram:numeral:cardinal_to_round', params_affected=[])171# args -> []172def gram_numeral_cardinal_to_round(element, arguments=[], branching=[]):173 return element174@new_func('mansi:numeral:partial_colloc', params_affected=[])175# args -> []176def mansi_numeral_partial_colloc(element, arguments=[], branching=[]):177 return element178@new_func('mansi:pronoun:personal:1SG', params_affected=['mansi:basic_pos', 'mansi:pronoun:person', 'mansi:pronoun:number'])179# args -> []180def mansi_pronoun_personal_1sg(element, arguments=[], branching=[]):181 element.set_parameter('mansi:basic_pos', 'pronoun')182 element.set_parameter('mansi:pronoun:person', '1')183 element.set_parameter('mansi:pronoun:number', 'sing')184 return element185@new_func('gram:case:set_nom', params_affected=['gram:case'])186# args -> []187def gram_case_set_nom(element, arguments=[], branching=[]):188 element.set_parameter('gram:case', 'nom')189 return element190@new_func('gram:case:set_acc', params_affected=['gram:case'])191# args -> []192def gram_case_set_acc(element, arguments=[], branching=[]):193 element.set_parameter('gram:case', 'acc')194 return element195@new_func('gram:case:set_dat', params_affected=['gram:case'])196# args -> []197def gram_case_set_dat(element, arguments=[], branching=[]):198 element.set_parameter('gram:case', 'dat')199 return element200@new_func('mansi:pronoun:personal:2SG', params_affected=['mansi:basic_pos', 'mansi:pronoun:person', 'mansi:pronoun:number'])201# args -> []202def mansi_pronoun_personal_2sg(element, arguments=[], branching=[]):203 element.set_parameter('mansi:basic_pos', 'pronoun')204 element.set_parameter('mansi:pronoun:person', '2')205 element.set_parameter('mansi:pronoun:number', 'sing')206 return element207@new_func('mansi:pronoun:personal:3SG', params_affected=['mansi:basic_pos', 'mansi:pronoun:person', 'mansi:pronoun:number'])208# args -> []209def mansi_pronoun_personal_3sg(element, arguments=[], branching=[]):210 element.set_parameter('mansi:basic_pos', 'pronoun')211 element.set_parameter('mansi:pronoun:person', '3')212 element.set_parameter('mansi:pronoun:number', 'sing')213 return element214@new_func('mansi:pronoun:personal:1DU', params_affected=['mansi:basic_pos', 'mansi:pronoun:person', 'mansi:pronoun:number'])215# args -> []216def mansi_pronoun_personal_1du(element, arguments=[], branching=[]):217 element.set_parameter('mansi:basic_pos', 'pronoun')218 element.set_parameter('mansi:pronoun:person', '1')219 element.set_parameter('mansi:pronoun:number', 'dual')220 return element221@new_func('mansi:pronoun:personal:2DU', params_affected=['mansi:basic_pos', 'mansi:pronoun:person', 'mansi:pronoun:number'])222# args -> []223def mansi_pronoun_personal_2du(element, arguments=[], branching=[]):224 element.set_parameter('mansi:basic_pos', 'pronoun')225 element.set_parameter('mansi:pronoun:person', '2')226 element.set_parameter('mansi:pronoun:number', 'dual')227 return element228@new_func('mansi:pronoun:personal:3DU', params_affected=['mansi:basic_pos', 'mansi:pronoun:person', 'mansi:pronoun:number'])229# args -> []230def mansi_pronoun_personal_3du(element, arguments=[], branching=[]):231 element.set_parameter('mansi:basic_pos', 'pronoun')232 element.set_parameter('mansi:pronoun:person', '3')233 element.set_parameter('mansi:pronoun:number', 'dual')234 return element235@new_func('mansi:pronoun:personal:1PL', params_affected=['mansi:basic_pos', 'mansi:pronoun:person', 'mansi:pronoun:number'])236# args -> []237def mansi_pronoun_personal_1pl(element, arguments=[], branching=[]):238 element.set_parameter('mansi:basic_pos', 'pronoun')239 element.set_parameter('mansi:pronoun:person', '1')240 element.set_parameter('mansi:pronoun:number', 'plur')241 return element242@new_func('mansi:pronoun:personal:2PL', params_affected=['mansi:basic_pos', 'mansi:pronoun:person', 'mansi:pronoun:number'])243# args -> []244def mansi_pronoun_personal_2pl(element, arguments=[], branching=[]):245 element.set_parameter('mansi:basic_pos', 'pronoun')246 element.set_parameter('mansi:pronoun:person', '2')247 element.set_parameter('mansi:pronoun:number', 'plur')248 return element249@new_func('mansi:pronoun:personal:3PL', params_affected=['mansi:basic_pos', 'mansi:pronoun:person', 'mansi:pronoun:number'])250# args -> []251def mansi_pronoun_personal_3pl(element, arguments=[], branching=[]):252 element.set_parameter('mansi:basic_pos', 'pronoun')253 element.set_parameter('mansi:pronoun:person', '3')254 element.set_parameter('mansi:pronoun:number', 'plur')255 return element256@new_func('mansi:pronoun:lich_ukaz', params_affected=[])257# args -> []258def mansi_pronoun_lich_ukaz(element, arguments=[], branching=[]):259 return element260@new_func('mansi:pronoun:set_sol', params_affected=[])261# args -> []262def mansi_pronoun_set_sol(element, arguments=[], branching=[]):263 return element264@new_func('gram:set_refl', params_affected=[])265# args -> []266def gram_set_refl(element, arguments=[], branching=[]):267 return element268@new_func('mansi:pronoun:demonstrative', params_affected=[])269# args -> []270def mansi_pronoun_demonstrative(element, arguments=[], branching=[]):271 return element272@new_func('mansi:set_basic_pos:pronoun', params_affected=['mansi:basic_pos'])273# args -> []274def mansi_set_basic_pos_pronoun(element, arguments=[], branching=[]):275 element.set_parameter('mansi:basic_pos', 'pronoun')276 return element277@new_func('mansi:pronoun:determinative', params_affected=[])278# args -> []279def mansi_pronoun_determinative(element, arguments=[], branching=[]):280 return element281@new_func('gram:make_reflexive', params_affected=[])282# args -> []283def gram_make_reflexive(element, arguments=[], branching=[]):284 return element285@new_func('gram:make_intransitive', params_affected=['gram:intransitive'])286# args -> []287def gram_make_intransitive(element, arguments=[], branching=[]):288 element.set_parameter('gram:intransitive', True)289 return element290@new_func('mansi:set_obj_conj', params_affected=['mansi:conj'])291# args -> []292def mansi_set_obj_conj(element, arguments=[], branching=[]):293 element.set_parameter('mansi:conj', 'obj')294 return element295@new_func('mansi:conj:set_obj', params_affected=['mansi:conj'])296# args -> []297def mansi_conj_set_obj(element, arguments=[], branching=[]):298 element.set_parameter('mansi:conj', 'obj')299 return element300@new_func('mansi:conj:set_subj_pass', params_affected=['mansi:conj'])301# args -> []302def mansi_conj_set_subj_pass(element, arguments=[], branching=[]):303 element.set_parameter('mansi:conj', 'subj_pass')304 return element305@new_func('mansi:conj:set_objectless', params_affected=['mansi:conj'])306# args -> []307def mansi_conj_set_objectless(element, arguments=[], branching=[]):308 element.set_parameter('mansi:conj', 'objectless')309 return element310@new_func('gram:tense:set_present', params_affected=[])311# args -> []312def gram_tense_set_present(element, arguments=[], branching=[]):313 return element314@new_func('gram:tense:set_past', params_affected=[])315# args -> []316def gram_tense_set_past(element, arguments=[], branching=[]):317 return element318@new_func('gram:mood:set_latentive', params_affected=['gram:mood'])319# args -> []320def gram_mood_set_latentive(element, arguments=[], branching=[]):321 element.set_parameter('gram:mood', 'latentive')322 return element323@new_func('mansi:tense:set_past', params_affected=[])324# args -> []325def mansi_tense_set_past(element, arguments=[], branching=[]):326 return element327@new_func('mansi:verb:set_person', params_affected=[])328# args -> [1]329def mansi_verb_set_person(element, arguments=[], branching=[]):330 element.set_parameter('gram:person', arguments[0])331 return element332@new_func('gram:set_number:plur', params_affected=[])333# args -> []334def gram_set_number_plur(element, arguments=[], branching=[]):335 element.set_parameter('gram:number', 'plur')336 return element337@new_func('gram:tense:set_future', params_affected=[])338# args -> []339def gram_tense_set_future(element, arguments=[], branching=[]):340 return element341@new_func('mansi:object_number:set_sing', params_affected=[])342# args -> []343def mansi_object_number_set_sing(element, arguments=[], branching=[]):344 return element345@new_func('mansi:object_number:set_dual', params_affected=[])346# args -> []347def mansi_object_number_set_dual(element, arguments=[], branching=[]):348 return element349@new_func('mansi:object_number:set_plur', params_affected=[])350# args -> []351def mansi_object_number_set_plur(element, arguments=[], branching=[]):352 return element353@new_func('gram:mood:set_imperative', params_affected=['gram:mood'])354# args -> []355def gram_mood_set_imperative(element, arguments=[], branching=[]):356 element.set_parameter('gram:mood', 'imperative')357 return element358@new_func('gram:mood:set_indicative', params_affected=['gram:mood'])359# args -> []360def gram_mood_set_indicative(element, arguments=[], branching=[]):361 element.set_parameter('gram:mood', 'indicative')362 return element363@new_func('gram:mood:set_conjunctive', params_affected=['gram:mood'])364# args -> []365def gram_mood_set_conjunctive(element, arguments=[], branching=[]):366 element.set_parameter('gram:mood', 'conjunctive')367 return element368@new_func('gram:mood:set_optative', params_affected=['gram:mood'])369# args -> []370def gram_mood_set_optative(element, arguments=[], branching=[]):371 element.set_parameter('gram:mood', 'conjunctive')372 return element373@new_func('gram:set_semelfactive', params_affected=[])374# args -> []375def gram_set_semelfactive(element, arguments=[], branching=[]):376 return element377@new_func('gram:set_inchoative', params_affected=[])378# args -> []379def gram_set_inchoative(element, arguments=[], branching=[]):380 return element381@new_func('gram:set_durative', params_affected=[])382# args -> []383def gram_set_durative(element, arguments=[], branching=[]):384 return element385@new_func('gram:set_iterative', params_affected=[])386# args -> []387def gram_set_iterative(element, arguments=[], branching=[]):388 return element389@new_func('mansi:noun_to_verb', params_affected=['mansi:from_noun'])390# args -> []391def mansi_noun_to_verb(element, arguments=[], branching=[]):392 element.set_parameter('mansi:from_noun', True)393 return element394@new_func('direct:set_meaning', params_affected=[])395# args -> [оÑ]396def direct_set_meaning(element, arguments=[], branching=[]):397 return element398@new_func('mansi:basic_pos:set_verb', params_affected=['mansi:basic_pos'])399# args -> []400def mansi_basic_pos_set_verb(element, arguments=[], branching=[]):401 element.set_parameter('mansi:basic_pos', 'verb')402 return element403@new_func('gram:set_resultative', params_affected=[])404# args -> []405def gram_set_resultative(element, arguments=[], branching=[]):406 return element407@new_func('gram:set_converb', params_affected=['mansi:basic_pos'])408# args -> []409def gram_set_converb(element, arguments=[], branching=[]):410 element.set_parameter('mansi:basic_pos', 'converb')411 return element412@new_func('mansi:make_participle', params_affected=['mansi:basic_pos'])413# args -> []414def mansi_make_participle(element, arguments=[], branching=[]):415 element.set_parameter('mansi:basic_pos', 'participle')416 return element417@new_func('gram:set_present', params_affected=[])418# args -> []419def gram_set_present(element, arguments=[], branching=[]):420 return element421@new_func('mansi:make_transgressive', params_affected=[])422# args -> []423def mansi_make_transgressive(element, arguments=[], branching=[]):424 return element425@new_func('mansi:basic_pos:set_adv', params_affected=['mansi:basic_pos'])426# args -> []427def mansi_basic_pos_set_adv(element, arguments=[], branching=[]):428 element.set_parameter('mansi:basic_pos', 'adv')429 return element430@new_func('gram:set_comparative', params_affected=[])431# args -> []432def gram_set_comparative(element, arguments=[], branching=[]):433 return element434@new_func('gram:adv:comparative', params_affected=[])435# args -> []436def gram_adv_comparative(element, arguments=[], branching=[]):437 return element438@new_func('gram:set_superlative', params_affected=[])439# args -> []440def gram_set_superlative(element, arguments=[], branching=[]):441 return element442@new_func('mansi:basic_pos:set_postpos', params_affected=['mansi:basic_pos'])443# args -> []444def mansi_basic_pos_set_postpos(element, arguments=[], branching=[]):445 element.set_parameter('mansi:basic_pos', 'postpos')446 return element447@new_func('mansi:translation:set_new', params_affected=[])448# args -> [до]449def mansi_translation_set_new(element, arguments=[], branching=[]):...
base.py
Source:base.py
...44 #/************************************************************************/45 def test_1_coordinate(self):46 func = lambda coord, *args, **kwargs: coord47 new_func = _Decorator.parse_coordinate(func)48 self.assertEqual(new_func(coord=[[1,-1],[2,-2]], order='Ll'), 49 [[-1, 1], [-2, 2]])50 self.assertEqual(new_func(**{'lat':[1,2], 'Lon': [-1,-2]}),51 [[1, -1], [2, -2]])52 self.assertEqual(new_func(lat=[1,2], Lon=[-1,-2], order='Ll'),53 [[-1, 1], [-2, 2]])54 self.assertEqual(new_func(**{'y':[1,2], 'x': [-1,-2]}),55 [[1, -1], [2, -2]])56 self.assertEqual(new_func([1,-1]), 57 [[1,-1]])58 self.assertEqual(new_func([1,2],[-1,-2]),59 [[1, -1], [2, -2]])60 self.assertEqual(new_func(coord=[[1,-1],[2,-2]]),61 [[1, -1], [2, -2]])62 self.assertRaises(happyError,63 new_func([[1,-1],[2,-2]], lat=[1,2], Lon=[-1,-2]))64 class dummy(object):65 @_Decorator.parse_coordinate66 def meth(self, coord, **kwargs):67 return coord68 self.assertEqual(dummy.meth([1, -1]), 69 [1, -1])70 self.assertEqual(dummy.meth(lat=1, Lon=-1), 71 [1, -1])72 self.assertEqual(dummy.meth(**{'lat': 1, 'Lon': -1}), 73 [1, -1])74 self.assertRaises(happyError,75 new_func(coord=[[1,-1],[2,-2]], lat=[1,2], Lon=[-1,-2]))76 #/************************************************************************/77 def test_2_place(self):78 func = lambda place, *args, **kwargs: place79 new_func = _Decorator.parse_place(func)80 self.assertEqual(new_func(func)('A'),81 'A')82 self.assertEqual(new_func(func)({'place': 'A'}), 83 'A')84 self.assertEqual(new_func(place='Bruxelles, Belgium'),85 ['Bruxelles, Belgium'])86 self.assertEqual(new_func(city=['Athens','Heraklion'],country='Hellas'),87 ['Athens, Hellas', 'Heraklion, Hellas'])88 self.assertEqual(new_func(**{'address':['72 avenue Parmentier','101 Avenue de la République'], 89 'city':'Paris', 'country':'France'}),90 ['72 avenue Parmentier, Paris, France', '101 Avenue de la République, Paris, France'])91 self.assertEqual(new_func(place=['Eurostat', 'DIGIT', 'EIB'],city='Luxembourg'),92 ['Eurostat, Luxembourg', 'DIGIT, Luxembourg', 'EIB, Luxembourg'])93 self.assertEqual(new_func('Athens, Hellas'),94 ['Athens, Hellas'])95 class dummy(object):96 @_Decorator.parse_place97 def meth(self, place, **kwargs):98 return place99 self.assertEqual(dummy.meth('A'), 100 'A')101 self.assertEqual(dummy.meth(place='A'), 102 'A')103 self.assertEqual(dummy.meth(**{'place': 'A'}), 104 'A')105 self.assertRaises(happyError,106 new_func('Athens, Hellas', place='Berlin, Germany'))107 108 #/************************************************************************/109 def test_3_place_or_coordinate(self):110 func = lambda *args, **kwargs: [kwargs.get('coord'), kwargs.get('place')]111 new_func = _Decorator.parse_place_or_coordinate(func)112 self.assertEqual(new_func(lat=[1,2], Lon=[-1,-2]),113 [[[1, -1], [2, -2]], None])114 self.assertEqual(new_func(place='Bruxelles, Belgium'),115 [None, ['Bruxelles, Belgium']])116 class dummy(object):117 @_Decorator.parse_place_or_coordinates118 def meth(self, **kwargs):119 return kwargs.get('place') or [kwargs.get('lat'),kwargs.get('Lon')]120 self.assertEqual(dummy.meth(place='A'), 'A')121 self.assertEqual(dummy.meth(lat=1, Lon=-1), [[1], [-1]])122 123 #/************************************************************************/124 def test_4_geometry(self):125 func = lambda *args, **kwargs: kwargs.get('coord')126 new_func = _Decorator.parse_geometry(func)127 geom = {'A': 1, 'B': 2}128 self.assertEqual(new_func(geom=geom),129 [])130 self.assertRaises(happyError,131 new_func(geom=geom))132 geom = {'geometry': {'coordinates': [1, 2], 'type': 'Point'},133 'properties': {'city': 'somewhere', 134 'country': 'some country',135 'street': 'sesame street',136 'osm_key': 'place'},137 'type': 'Feature'}138 self.assertEqual(new_func(geom=geom),139 [[2, 1]])140 self.assertEqual(new_func(geom, order='Ll'),141 [[1, 2]])142 func = lambda *args, **kwargs: kwargs.get('place')143 new_func = _Decorator.parse_geometry(func)144 self.assertEqual(new_func(geom=geom, filter='place'),145 ['sesame street, somewhere, some country']) 146 147 #/************************************************************************/148 def test_5_nuts(self):149 func = lambda *args, **kwargs: kwargs.get('nuts')150 new_func = _Decorator.parse_nuts(func)151 nuts = {'A': 1, 'B': 2}152 self.assertEqual(new_func(nuts),153 [])154 self.assertRaises(happyError,155 new_func(nuts=nuts))156 nuts = {'attributes': {'CNTR_CODE': 'EU', 'LEVL_CODE': '0'},157 'NUTS_NAME': 'EU',158 'displayFieldName': 'NUTS_ID', 'layerId': 2, 'layerName': 'NUTS_2013',159 'value': 'EU'}160 self.assertTrue([nuts] == new_func(**nuts))161 self.assertTrue([nuts] == new_func(nuts=nuts))162 #/************************************************************************/163 def test_5_projection(self):164 func = lambda *args, **kwargs: kwargs.get('proj')165 new_func = _Decorator.parse_projection(func)166 self.assertEqual(new_func(proj='WGS84'),167 4326)168 self.assertEqual(new_func(proj='EPSG3857'),169 3857)170 self.assertEqual(new_func(proj=3857),171 3857)172 self.assertEqual(new_func(proj='LAEA'),173 3035)174 self.assertRaises(happyError,175 new_func(proj='dumb'))176 177 #/************************************************************************/178 def test_6_year(self):179 func = lambda *args, **kwargs: kwargs.get('year')180 new_func = _Decorator.parse_year(func)181 self.assertEqual(new_func(year=2013),182 2013)183 self.assertRaises(happyError,184 new_func(year=2000))185#==============================================================================186# MAIN METHOD AND TESTING AREA187#==============================================================================188def runtest():189 _runtest(_DecoratorTestCase)190 return191 192if __name__ == '__main__':193 unittest.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!!