diff options
Diffstat (limited to 'test/automated/python-tests.el')
| -rw-r--r-- | test/automated/python-tests.el | 233 |
1 files changed, 218 insertions, 15 deletions
diff --git a/test/automated/python-tests.el b/test/automated/python-tests.el index b377a26f77a..ae4323ba8af 100644 --- a/test/automated/python-tests.el +++ b/test/automated/python-tests.el | |||
| @@ -1014,7 +1014,7 @@ lines | |||
| 1014 | def fn(a, b, c=True): | 1014 | def fn(a, b, c=True): |
| 1015 | '''docstring | 1015 | '''docstring |
| 1016 | bunch | 1016 | bunch |
| 1017 | of | 1017 | of |
| 1018 | lines | 1018 | lines |
| 1019 | ''' | 1019 | ''' |
| 1020 | " | 1020 | " |
| @@ -1022,16 +1022,17 @@ def fn(a, b, c=True): | |||
| 1022 | (should (eq (car (python-indent-context)) :after-block-start)) | 1022 | (should (eq (car (python-indent-context)) :after-block-start)) |
| 1023 | (should (= (python-indent-calculate-indentation) 4)) | 1023 | (should (= (python-indent-calculate-indentation) 4)) |
| 1024 | (python-tests-look-at "bunch") | 1024 | (python-tests-look-at "bunch") |
| 1025 | (should (eq (car (python-indent-context)) :inside-string)) | 1025 | (should (eq (car (python-indent-context)) :inside-docstring)) |
| 1026 | (should (= (python-indent-calculate-indentation) 4)) | 1026 | (should (= (python-indent-calculate-indentation) 4)) |
| 1027 | (python-tests-look-at "of") | 1027 | (python-tests-look-at "of") |
| 1028 | (should (eq (car (python-indent-context)) :inside-string)) | 1028 | (should (eq (car (python-indent-context)) :inside-docstring)) |
| 1029 | (should (= (python-indent-calculate-indentation) 4)) | 1029 | ;; Any indentation deeper than the base-indent must remain unmodified. |
| 1030 | (should (= (python-indent-calculate-indentation) 8)) | ||
| 1030 | (python-tests-look-at "lines") | 1031 | (python-tests-look-at "lines") |
| 1031 | (should (eq (car (python-indent-context)) :inside-string)) | 1032 | (should (eq (car (python-indent-context)) :inside-docstring)) |
| 1032 | (should (= (python-indent-calculate-indentation) 4)) | 1033 | (should (= (python-indent-calculate-indentation) 4)) |
| 1033 | (python-tests-look-at "'''") | 1034 | (python-tests-look-at "'''") |
| 1034 | (should (eq (car (python-indent-context)) :inside-string)) | 1035 | (should (eq (car (python-indent-context)) :inside-docstring)) |
| 1035 | (should (= (python-indent-calculate-indentation) 4)))) | 1036 | (should (= (python-indent-calculate-indentation) 4)))) |
| 1036 | 1037 | ||
| 1037 | (ert-deftest python-indent-inside-string-3 () | 1038 | (ert-deftest python-indent-inside-string-3 () |
| @@ -1189,21 +1190,33 @@ def f(): | |||
| 1189 | expected))))) | 1190 | expected))))) |
| 1190 | 1191 | ||
| 1191 | (ert-deftest python-indent-region-5 () | 1192 | (ert-deftest python-indent-region-5 () |
| 1192 | "Test region indentation leaves strings untouched (start delimiter)." | 1193 | "Test region indentation for docstrings." |
| 1193 | (let ((contents " | 1194 | (let ((contents " |
| 1194 | def f(): | 1195 | def f(): |
| 1195 | ''' | 1196 | ''' |
| 1196 | this is | 1197 | this is |
| 1197 | a multiline | 1198 | a multiline |
| 1198 | string | 1199 | string |
| 1199 | ''' | 1200 | ''' |
| 1201 | x = \\ | ||
| 1202 | ''' | ||
| 1203 | this is an arbitrarily | ||
| 1204 | indented multiline | ||
| 1205 | string | ||
| 1206 | ''' | ||
| 1200 | ") | 1207 | ") |
| 1201 | (expected " | 1208 | (expected " |
| 1202 | def f(): | 1209 | def f(): |
| 1203 | ''' | 1210 | ''' |
| 1204 | this is | 1211 | this is |
| 1205 | a multiline | 1212 | a multiline |
| 1206 | string | 1213 | string |
| 1214 | ''' | ||
| 1215 | x = \\ | ||
| 1216 | ''' | ||
| 1217 | this is an arbitrarily | ||
| 1218 | indented multiline | ||
| 1219 | string | ||
| 1207 | ''' | 1220 | ''' |
| 1208 | ")) | 1221 | ")) |
| 1209 | (python-tests-with-temp-buffer | 1222 | (python-tests-with-temp-buffer |
| @@ -1985,19 +1998,36 @@ c() | |||
| 1985 | (should (save-excursion | 1998 | (should (save-excursion |
| 1986 | (beginning-of-line) | 1999 | (beginning-of-line) |
| 1987 | (looking-at "c()"))) | 2000 | (looking-at "c()"))) |
| 1988 | ;; Movement next to a paren should do what lisp does and | 2001 | ;; The default behavior when next to a paren should do what lisp |
| 1989 | ;; unfortunately It can't change, because otherwise | 2002 | ;; does and, otherwise `blink-matching-open' breaks. |
| 1990 | ;; `blink-matching-open' breaks. | ||
| 1991 | (python-nav-forward-sexp -1) | 2003 | (python-nav-forward-sexp -1) |
| 1992 | (should (looking-at "()")) | 2004 | (should (looking-at "()")) |
| 1993 | (should (save-excursion | 2005 | (should (save-excursion |
| 1994 | (beginning-of-line) | 2006 | (beginning-of-line) |
| 1995 | (looking-at "c()"))) | 2007 | (looking-at "c()"))) |
| 1996 | (python-nav-forward-sexp -1) | 2008 | (end-of-line) |
| 2009 | ;; Skipping parens should jump to `bolp' | ||
| 2010 | (python-nav-forward-sexp -1 nil t) | ||
| 1997 | (should (looking-at "c()")) | 2011 | (should (looking-at "c()")) |
| 2012 | (forward-line -1) | ||
| 2013 | (end-of-line) | ||
| 2014 | ;; b() | ||
| 2015 | (python-nav-forward-sexp -1) | ||
| 2016 | (should (looking-at "()")) | ||
| 1998 | (python-nav-forward-sexp -1) | 2017 | (python-nav-forward-sexp -1) |
| 1999 | (should (looking-at "b()")) | 2018 | (should (looking-at "b()")) |
| 2019 | (end-of-line) | ||
| 2020 | (python-nav-forward-sexp -1 nil t) | ||
| 2021 | (should (looking-at "b()")) | ||
| 2022 | (forward-line -1) | ||
| 2023 | (end-of-line) | ||
| 2024 | ;; a() | ||
| 2000 | (python-nav-forward-sexp -1) | 2025 | (python-nav-forward-sexp -1) |
| 2026 | (should (looking-at "()")) | ||
| 2027 | (python-nav-forward-sexp -1) | ||
| 2028 | (should (looking-at "a()")) | ||
| 2029 | (end-of-line) | ||
| 2030 | (python-nav-forward-sexp -1 nil t) | ||
| 2001 | (should (looking-at "a()")))) | 2031 | (should (looking-at "a()")))) |
| 2002 | 2032 | ||
| 2003 | (ert-deftest python-nav-forward-sexp-2 () | 2033 | (ert-deftest python-nav-forward-sexp-2 () |
| @@ -4273,6 +4303,49 @@ def foo(a, | |||
| 4273 | (python-tests-look-at "c):") | 4303 | (python-tests-look-at "c):") |
| 4274 | (should (not (python-info-block-continuation-line-p))))) | 4304 | (should (not (python-info-block-continuation-line-p))))) |
| 4275 | 4305 | ||
| 4306 | (ert-deftest python-info-assignment-statement-p-1 () | ||
| 4307 | (python-tests-with-temp-buffer | ||
| 4308 | " | ||
| 4309 | data = foo(), bar() \\\\ | ||
| 4310 | baz(), 4 \\\\ | ||
| 4311 | 5, 6 | ||
| 4312 | " | ||
| 4313 | (python-tests-look-at "data = foo(), bar()") | ||
| 4314 | (should (python-info-assignment-statement-p)) | ||
| 4315 | (should (python-info-assignment-statement-p t)) | ||
| 4316 | (python-tests-look-at "baz(), 4") | ||
| 4317 | (should (python-info-assignment-statement-p)) | ||
| 4318 | (should (not (python-info-assignment-statement-p t))) | ||
| 4319 | (python-tests-look-at "5, 6") | ||
| 4320 | (should (python-info-assignment-statement-p)) | ||
| 4321 | (should (not (python-info-assignment-statement-p t))))) | ||
| 4322 | |||
| 4323 | (ert-deftest python-info-assignment-statement-p-2 () | ||
| 4324 | (python-tests-with-temp-buffer | ||
| 4325 | " | ||
| 4326 | data = (foo(), bar() | ||
| 4327 | baz(), 4 | ||
| 4328 | 5, 6) | ||
| 4329 | " | ||
| 4330 | (python-tests-look-at "data = (foo(), bar()") | ||
| 4331 | (should (python-info-assignment-statement-p)) | ||
| 4332 | (should (python-info-assignment-statement-p t)) | ||
| 4333 | (python-tests-look-at "baz(), 4") | ||
| 4334 | (should (python-info-assignment-statement-p)) | ||
| 4335 | (should (not (python-info-assignment-statement-p t))) | ||
| 4336 | (python-tests-look-at "5, 6)") | ||
| 4337 | (should (python-info-assignment-statement-p)) | ||
| 4338 | (should (not (python-info-assignment-statement-p t))))) | ||
| 4339 | |||
| 4340 | (ert-deftest python-info-assignment-statement-p-3 () | ||
| 4341 | (python-tests-with-temp-buffer | ||
| 4342 | " | ||
| 4343 | data '=' 42 | ||
| 4344 | " | ||
| 4345 | (python-tests-look-at "data '=' 42") | ||
| 4346 | (should (not (python-info-assignment-statement-p))) | ||
| 4347 | (should (not (python-info-assignment-statement-p t))))) | ||
| 4348 | |||
| 4276 | (ert-deftest python-info-assignment-continuation-line-p-1 () | 4349 | (ert-deftest python-info-assignment-continuation-line-p-1 () |
| 4277 | (python-tests-with-temp-buffer | 4350 | (python-tests-with-temp-buffer |
| 4278 | " | 4351 | " |
| @@ -4360,6 +4433,136 @@ foo = True # another comment | |||
| 4360 | (forward-line 1) | 4433 | (forward-line 1) |
| 4361 | (should (python-info-current-line-empty-p)))) | 4434 | (should (python-info-current-line-empty-p)))) |
| 4362 | 4435 | ||
| 4436 | (ert-deftest python-info-docstring-p-1 () | ||
| 4437 | "Test module docstring detection." | ||
| 4438 | (python-tests-with-temp-buffer | ||
| 4439 | "# -*- coding: utf-8 -*- | ||
| 4440 | #!/usr/bin/python | ||
| 4441 | |||
| 4442 | ''' | ||
| 4443 | Module Docstring Django style. | ||
| 4444 | ''' | ||
| 4445 | u'''Additional module docstring.''' | ||
| 4446 | '''Not a module docstring.''' | ||
| 4447 | " | ||
| 4448 | (python-tests-look-at "Module Docstring Django style.") | ||
| 4449 | (should (python-info-docstring-p)) | ||
| 4450 | (python-tests-look-at "u'''Additional module docstring.'''") | ||
| 4451 | (should (python-info-docstring-p)) | ||
| 4452 | (python-tests-look-at "'''Not a module docstring.'''") | ||
| 4453 | (should (not (python-info-docstring-p))))) | ||
| 4454 | |||
| 4455 | (ert-deftest python-info-docstring-p-2 () | ||
| 4456 | "Test variable docstring detection." | ||
| 4457 | (python-tests-with-temp-buffer | ||
| 4458 | " | ||
| 4459 | variable = 42 | ||
| 4460 | U'''Variable docstring.''' | ||
| 4461 | '''Additional variable docstring.''' | ||
| 4462 | '''Not a variable docstring.''' | ||
| 4463 | " | ||
| 4464 | (python-tests-look-at "Variable docstring.") | ||
| 4465 | (should (python-info-docstring-p)) | ||
| 4466 | (python-tests-look-at "u'''Additional variable docstring.'''") | ||
| 4467 | (should (python-info-docstring-p)) | ||
| 4468 | (python-tests-look-at "'''Not a variable docstring.'''") | ||
| 4469 | (should (not (python-info-docstring-p))))) | ||
| 4470 | |||
| 4471 | (ert-deftest python-info-docstring-p-3 () | ||
| 4472 | "Test function docstring detection." | ||
| 4473 | (python-tests-with-temp-buffer | ||
| 4474 | " | ||
| 4475 | def func(a, b): | ||
| 4476 | r''' | ||
| 4477 | Function docstring. | ||
| 4478 | |||
| 4479 | onetwo style. | ||
| 4480 | ''' | ||
| 4481 | R'''Additional function docstring.''' | ||
| 4482 | '''Not a function docstring.''' | ||
| 4483 | return a + b | ||
| 4484 | " | ||
| 4485 | (python-tests-look-at "Function docstring.") | ||
| 4486 | (should (python-info-docstring-p)) | ||
| 4487 | (python-tests-look-at "R'''Additional function docstring.'''") | ||
| 4488 | (should (python-info-docstring-p)) | ||
| 4489 | (python-tests-look-at "'''Not a function docstring.'''") | ||
| 4490 | (should (not (python-info-docstring-p))))) | ||
| 4491 | |||
| 4492 | (ert-deftest python-info-docstring-p-4 () | ||
| 4493 | "Test class docstring detection." | ||
| 4494 | (python-tests-with-temp-buffer | ||
| 4495 | " | ||
| 4496 | class Class: | ||
| 4497 | ur''' | ||
| 4498 | Class docstring. | ||
| 4499 | |||
| 4500 | symmetric style. | ||
| 4501 | ''' | ||
| 4502 | uR''' | ||
| 4503 | Additional class docstring. | ||
| 4504 | ''' | ||
| 4505 | '''Not a class docstring.''' | ||
| 4506 | pass | ||
| 4507 | " | ||
| 4508 | (python-tests-look-at "Class docstring.") | ||
| 4509 | (should (python-info-docstring-p)) | ||
| 4510 | (python-tests-look-at "uR'''") ;; Additional class docstring | ||
| 4511 | (should (python-info-docstring-p)) | ||
| 4512 | (python-tests-look-at "'''Not a class docstring.'''") | ||
| 4513 | (should (not (python-info-docstring-p))))) | ||
| 4514 | |||
| 4515 | (ert-deftest python-info-docstring-p-5 () | ||
| 4516 | "Test class attribute docstring detection." | ||
| 4517 | (python-tests-with-temp-buffer | ||
| 4518 | " | ||
| 4519 | class Class: | ||
| 4520 | attribute = 42 | ||
| 4521 | Ur''' | ||
| 4522 | Class attribute docstring. | ||
| 4523 | |||
| 4524 | pep-257 style. | ||
| 4525 | |||
| 4526 | ''' | ||
| 4527 | UR''' | ||
| 4528 | Additional class attribute docstring. | ||
| 4529 | ''' | ||
| 4530 | '''Not a class attribute docstring.''' | ||
| 4531 | pass | ||
| 4532 | " | ||
| 4533 | (python-tests-look-at "Class attribute docstring.") | ||
| 4534 | (should (python-info-docstring-p)) | ||
| 4535 | (python-tests-look-at "UR'''") ;; Additional class attr docstring | ||
| 4536 | (should (python-info-docstring-p)) | ||
| 4537 | (python-tests-look-at "'''Not a class attribute docstring.'''") | ||
| 4538 | (should (not (python-info-docstring-p))))) | ||
| 4539 | |||
| 4540 | (ert-deftest python-info-docstring-p-6 () | ||
| 4541 | "Test class method docstring detection." | ||
| 4542 | (python-tests-with-temp-buffer | ||
| 4543 | " | ||
| 4544 | class Class: | ||
| 4545 | |||
| 4546 | def __init__(self, a, b): | ||
| 4547 | self.a = a | ||
| 4548 | self.b = b | ||
| 4549 | |||
| 4550 | def __call__(self): | ||
| 4551 | '''Method docstring. | ||
| 4552 | |||
| 4553 | pep-257-nn style. | ||
| 4554 | ''' | ||
| 4555 | '''Additional method docstring.''' | ||
| 4556 | '''Not a method docstring.''' | ||
| 4557 | return self.a + self.b | ||
| 4558 | " | ||
| 4559 | (python-tests-look-at "Method docstring.") | ||
| 4560 | (should (python-info-docstring-p)) | ||
| 4561 | (python-tests-look-at "'''Additional method docstring.'''") | ||
| 4562 | (should (python-info-docstring-p)) | ||
| 4563 | (python-tests-look-at "'''Not a method docstring.'''") | ||
| 4564 | (should (not (python-info-docstring-p))))) | ||
| 4565 | |||
| 4363 | (ert-deftest python-info-encoding-from-cookie-1 () | 4566 | (ert-deftest python-info-encoding-from-cookie-1 () |
| 4364 | "Should detect it on first line." | 4567 | "Should detect it on first line." |
| 4365 | (python-tests-with-temp-buffer | 4568 | (python-tests-with-temp-buffer |