aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorFabián Ezequiel Gallina2015-04-05 23:58:13 -0300
committerFabián Ezequiel Gallina2015-04-05 23:58:13 -0300
commitdeea36f0ece7b1b14afe2a833b6a0f66d59f4459 (patch)
treee3e41e0a5a03b0ea83b293c0c65835be038d56d4 /test
parent7514b24b6a512d85b762c603e9e0107d2c8a52f1 (diff)
downloademacs-deea36f0ece7b1b14afe2a833b6a0f66d59f4459.tar.gz
emacs-deea36f0ece7b1b14afe2a833b6a0f66d59f4459.zip
python.el: Enhance docstring detection following PEP-257.
* lisp/progmodes/python.el (python-docstring-at-p): Remove function. (python-info-assignment-statement-p): New function. (python-info-assignment-continuation-line-p): Use it. (python-info-docstring-p): New function. (python-font-lock-syntactic-face-function) (python-fill-string): Use it. * test/automated/python-tests.el (python-info-assignment-statement-p-1) (python-info-assignment-statement-p-2) (python-info-assignment-statement-p-3, python-info-docstring-p-1) (python-info-docstring-p-2, python-info-docstring-p-3) (python-info-docstring-p-4, python-info-docstring-p-5) (python-info-docstring-p-6): New tests.
Diffstat (limited to 'test')
-rw-r--r--test/ChangeLog9
-rw-r--r--test/automated/python-tests.el173
2 files changed, 182 insertions, 0 deletions
diff --git a/test/ChangeLog b/test/ChangeLog
index f7bec2ee119..813f5dd42b7 100644
--- a/test/ChangeLog
+++ b/test/ChangeLog
@@ -1,3 +1,12 @@
12015-04-06 Fabián Ezequiel Gallina <fgallina@gnu.org>
2
3 * automated/python-tests.el (python-info-assignment-statement-p-1)
4 (python-info-assignment-statement-p-2)
5 (python-info-assignment-statement-p-3, python-info-docstring-p-1)
6 (python-info-docstring-p-2, python-info-docstring-p-3)
7 (python-info-docstring-p-4, python-info-docstring-p-5)
8 (python-info-docstring-p-6): New tests.
9
12015-04-01 Artur Malabarba <bruce.connor.am@gmail.com> 102015-04-01 Artur Malabarba <bruce.connor.am@gmail.com>
2 11
3 * automated/package-test.el: Avoid async while testing. 12 * automated/package-test.el: Avoid async while testing.
diff --git a/test/automated/python-tests.el b/test/automated/python-tests.el
index b377a26f77a..22c111fc04a 100644
--- a/test/automated/python-tests.el
+++ b/test/automated/python-tests.el
@@ -4273,6 +4273,49 @@ def foo(a,
4273 (python-tests-look-at "c):") 4273 (python-tests-look-at "c):")
4274 (should (not (python-info-block-continuation-line-p))))) 4274 (should (not (python-info-block-continuation-line-p)))))
4275 4275
4276(ert-deftest python-info-assignment-statement-p-1 ()
4277 (python-tests-with-temp-buffer
4278 "
4279data = foo(), bar() \\\\
4280 baz(), 4 \\\\
4281 5, 6
4282"
4283 (python-tests-look-at "data = foo(), bar()")
4284 (should (python-info-assignment-statement-p))
4285 (should (python-info-assignment-statement-p t))
4286 (python-tests-look-at "baz(), 4")
4287 (should (python-info-assignment-statement-p))
4288 (should (not (python-info-assignment-statement-p t)))
4289 (python-tests-look-at "5, 6")
4290 (should (python-info-assignment-statement-p))
4291 (should (not (python-info-assignment-statement-p t)))))
4292
4293(ert-deftest python-info-assignment-statement-p-2 ()
4294 (python-tests-with-temp-buffer
4295 "
4296data = (foo(), bar()
4297 baz(), 4
4298 5, 6)
4299"
4300 (python-tests-look-at "data = (foo(), bar()")
4301 (should (python-info-assignment-statement-p))
4302 (should (python-info-assignment-statement-p t))
4303 (python-tests-look-at "baz(), 4")
4304 (should (python-info-assignment-statement-p))
4305 (should (not (python-info-assignment-statement-p t)))
4306 (python-tests-look-at "5, 6)")
4307 (should (python-info-assignment-statement-p))
4308 (should (not (python-info-assignment-statement-p t)))))
4309
4310(ert-deftest python-info-assignment-statement-p-3 ()
4311 (python-tests-with-temp-buffer
4312 "
4313data '=' 42
4314"
4315 (python-tests-look-at "data '=' 42")
4316 (should (not (python-info-assignment-statement-p)))
4317 (should (not (python-info-assignment-statement-p t)))))
4318
4276(ert-deftest python-info-assignment-continuation-line-p-1 () 4319(ert-deftest python-info-assignment-continuation-line-p-1 ()
4277 (python-tests-with-temp-buffer 4320 (python-tests-with-temp-buffer
4278 " 4321 "
@@ -4360,6 +4403,136 @@ foo = True # another comment
4360 (forward-line 1) 4403 (forward-line 1)
4361 (should (python-info-current-line-empty-p)))) 4404 (should (python-info-current-line-empty-p))))
4362 4405
4406(ert-deftest python-info-docstring-p-1 ()
4407 "Test module docstring detection."
4408 (python-tests-with-temp-buffer
4409 "# -*- coding: utf-8 -*-
4410#!/usr/bin/python
4411
4412'''
4413Module Docstring Django style.
4414'''
4415u'''Additional module docstring.'''
4416'''Not a module docstring.'''
4417"
4418 (python-tests-look-at "Module Docstring Django style.")
4419 (should (python-info-docstring-p))
4420 (python-tests-look-at "u'''Additional module docstring.'''")
4421 (should (python-info-docstring-p))
4422 (python-tests-look-at "'''Not a module docstring.'''")
4423 (should (not (python-info-docstring-p)))))
4424
4425(ert-deftest python-info-docstring-p-2 ()
4426 "Test variable docstring detection."
4427 (python-tests-with-temp-buffer
4428 "
4429variable = 42
4430U'''Variable docstring.'''
4431'''Additional variable docstring.'''
4432'''Not a variable docstring.'''
4433"
4434 (python-tests-look-at "Variable docstring.")
4435 (should (python-info-docstring-p))
4436 (python-tests-look-at "u'''Additional variable docstring.'''")
4437 (should (python-info-docstring-p))
4438 (python-tests-look-at "'''Not a variable docstring.'''")
4439 (should (not (python-info-docstring-p)))))
4440
4441(ert-deftest python-info-docstring-p-3 ()
4442 "Test function docstring detection."
4443 (python-tests-with-temp-buffer
4444 "
4445def func(a, b):
4446 r'''
4447 Function docstring.
4448
4449 onetwo style.
4450 '''
4451 R'''Additional function docstring.'''
4452 '''Not a function docstring.'''
4453 return a + b
4454"
4455 (python-tests-look-at "Function docstring.")
4456 (should (python-info-docstring-p))
4457 (python-tests-look-at "R'''Additional function docstring.'''")
4458 (should (python-info-docstring-p))
4459 (python-tests-look-at "'''Not a function docstring.'''")
4460 (should (not (python-info-docstring-p)))))
4461
4462(ert-deftest python-info-docstring-p-4 ()
4463 "Test class docstring detection."
4464 (python-tests-with-temp-buffer
4465 "
4466class Class:
4467 ur'''
4468 Class docstring.
4469
4470 symmetric style.
4471 '''
4472 uR'''
4473 Additional class docstring.
4474 '''
4475 '''Not a class docstring.'''
4476 pass
4477"
4478 (python-tests-look-at "Class docstring.")
4479 (should (python-info-docstring-p))
4480 (python-tests-look-at "uR'''") ;; Additional class docstring
4481 (should (python-info-docstring-p))
4482 (python-tests-look-at "'''Not a class docstring.'''")
4483 (should (not (python-info-docstring-p)))))
4484
4485(ert-deftest python-info-docstring-p-5 ()
4486 "Test class attribute docstring detection."
4487 (python-tests-with-temp-buffer
4488 "
4489class Class:
4490 attribute = 42
4491 Ur'''
4492 Class attribute docstring.
4493
4494 pep-257 style.
4495
4496 '''
4497 UR'''
4498 Additional class attribute docstring.
4499 '''
4500 '''Not a class attribute docstring.'''
4501 pass
4502"
4503 (python-tests-look-at "Class attribute docstring.")
4504 (should (python-info-docstring-p))
4505 (python-tests-look-at "UR'''") ;; Additional class attr docstring
4506 (should (python-info-docstring-p))
4507 (python-tests-look-at "'''Not a class attribute docstring.'''")
4508 (should (not (python-info-docstring-p)))))
4509
4510(ert-deftest python-info-docstring-p-6 ()
4511 "Test class method docstring detection."
4512 (python-tests-with-temp-buffer
4513 "
4514class Class:
4515
4516 def __init__(self, a, b):
4517 self.a = a
4518 self.b = b
4519
4520 def __call__(self):
4521 '''Method docstring.
4522
4523 pep-257-nn style.
4524 '''
4525 '''Additional method docstring.'''
4526 '''Not a method docstring.'''
4527 return self.a + self.b
4528"
4529 (python-tests-look-at "Method docstring.")
4530 (should (python-info-docstring-p))
4531 (python-tests-look-at "'''Additional method docstring.'''")
4532 (should (python-info-docstring-p))
4533 (python-tests-look-at "'''Not a method docstring.'''")
4534 (should (not (python-info-docstring-p)))))
4535
4363(ert-deftest python-info-encoding-from-cookie-1 () 4536(ert-deftest python-info-encoding-from-cookie-1 ()
4364 "Should detect it on first line." 4537 "Should detect it on first line."
4365 (python-tests-with-temp-buffer 4538 (python-tests-with-temp-buffer