~python-mode-devs/python-mode/python-mode

« back to all changes in this revision

Viewing changes to test/py-ert-tests-2.el

  • Committer: Barry Warsaw
  • Date: 2017-02-24 21:38:07 UTC
  • Revision ID: barry@python.org-20170224213807-h762012vx6fgvrve
Move repo to GitLab

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
;; py-ert-tests.el --- Tests, some adapted from python.el -*- lexical-binding: t; -*-
2
 
 
3
 
;; Copyright (C) 2014 Andreas Röhler, <andreas.roehler@online.de>
4
 
 
5
 
;; GNU Emacs is free software: you can redistribute it and/or modify
6
 
;; it under the terms of the GNU General Public License as published by
7
 
;; the Free Software Foundation, either version 3 of the License, or
8
 
;; (at your option) any later version.
9
 
 
10
 
;; GNU Emacs is distributed in the hope that it will be useful,
11
 
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 
;; GNU General Public License for more details.
14
 
 
15
 
;; You should have received a copy of the GNU General Public License
16
 
;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.
17
 
 
18
 
;;; Commentary:
19
 
 
20
 
;;; Code:
21
 
 
22
 
;; tests are expected to run from directory test
23
 
 
24
 
(add-to-list 'load-path default-directory)
25
 
(load "py-ert-tests-1.el" nil t)
26
 
 
27
 
;; (require 'python-mode-test)
28
 
 
29
 
;;;
30
 
(ert-deftest py-ert-keyword-face-lp-1294742 ()
31
 
  (py-test-with-temp-buffer-point-min
32
 
      " and as assert break continue del elif else except exec finally for global if in is lambda not or pass raise return while with yield"
33
 
    (font-lock-fontify-buffer)
34
 
    (while (and (not (eobp))(< 0 (skip-chars-forward " ")))
35
 
      (should (eq 'font-lock-keyword-face (get-char-property (point) 'face)))
36
 
      (skip-chars-forward "^ \n"))))
37
 
 
38
 
(ert-deftest py-ert-builtins-face-lp-1294742 ()
39
 
  (let ((py-shell-name "python3"))
40
 
    (py-test-with-temp-buffer-point-min
41
 
        "_ __doc__ __import__ __name__ __package__ abs all any apply basestring bin bool buffer bytearray bytes callable chr classmethod cmp coerce compile complex delattr dict dir divmod enumerate eval execfile file filter float format frozenset getattr globals hasattr hash help hex id input int intern isinstance issubclass iter len list locals long map max min next object oct open ord pow print property range raw_input reduce reload repr reversed round set setattr slice sorted staticmethod str sum super tuple type unichr unicode vars xrange zip"
42
 
      (font-lock-fontify-buffer)
43
 
      (when py-debug-p (switch-to-buffer (current-buffer)))
44
 
 
45
 
      ;; (when py-debug-p (switch-to-buffer (current-buffer)))
46
 
      (should (eq 'py-builtins-face (get-char-property (point) 'face))))))
47
 
 
48
 
(ert-deftest py-ert-pseudo-keyword-face-lp-1294742 ()
49
 
  (py-test-with-temp-buffer-point-min
50
 
      "  Ellipsis True False None  __debug__ NotImplemented"
51
 
    (font-lock-fontify-buffer)
52
 
    (while (and (not (eobp))(< 0 (skip-chars-forward " ")))
53
 
      (should (eq 'py-pseudo-keyword-face (get-char-property (point) 'face)))
54
 
      (skip-chars-forward "^ \n"))))
55
 
 
56
 
(ert-deftest py-ert-object-reference-face-lp-1294742 ()
57
 
  (py-test-with-temp-buffer-point-min
58
 
      " self cls"
59
 
    (font-lock-fontify-buffer)
60
 
    (while (and (not (eobp))(< 0 (skip-chars-forward " ")))
61
 
      (should (eq 'py-object-reference-face (get-char-property (point) 'face)))
62
 
      (skip-chars-forward "^ \n"))))
63
 
 
64
 
(ert-deftest py-ert-borks-all-lp-1294820 ()
65
 
  (py-test-with-temp-buffer-point-min
66
 
      "# M-q within some code (not in= a docstring) completely borks all previous
67
 
# code in the file:
68
 
#
69
 
# E.g. here, if I M-q within the last function:
70
 
 
71
 
def foo(self):
72
 
    some_actual_code()
73
 
 
74
 
def bar(self):
75
 
    some_actual_code()
76
 
 
77
 
def baz(self):
78
 
    some_actual_code()
79
 
 
80
 
# def foo(self): some_actual_code() def bar(self): some_actual_code() def
81
 
# baz(self):
82
 
#     some_actual_code()
83
 
"
84
 
    (font-lock-fontify-buffer)
85
 
    (search-forward "def baz(self):")
86
 
    (fill-paragraph)
87
 
    (forward-line -1)
88
 
    (should (eq (char-after) ?\n))))
89
 
 
90
 
(ert-deftest py-ert-respect-paragraph-1294829 ()
91
 
 
92
 
  (py-test-with-temp-buffer-point-min
93
 
      "# py-fill-paragraph doesn';t respect existing paragraph breaks when
94
 
# reflowing the docstring, e.g.
95
 
 
96
 
def foo(self)
97
 
    \"\"\"First one-line summary.
98
 
 
99
 
    Some other stuff which I don't want a paragraph break inserted into
100
 
    the middle of.
101
 
 
102
 
    And another para hjkdfgh fdjkg hfdjkg hdfjk ghdfk ghjkdf
103
 
    ghjkdf ghjdf ghjdkf k
104
 
    \"\"\"
105
 
 
106
 
def foo(self)
107
 
    \"\"\"Second one-line summary. Some other stuff which I don't want a
108
 
paragraph
109
 
 
110
 
    break inserted into the middle of. And another para hjkdfgh
111
 
fdjkg
112
 
    hfdjkg hdfjk ghdfk ghjkdf ghjkdf ghjdf ghjdkf k \"\"\"
113
 
 
114
 
# I feel it would be better if it didn't attempt to
115
 
# reflow the whole docstring, rather just reflow the
116
 
# particular paragraph within it which the point is
117
 
# positioned in.
118
 
 
119
 
# It would also be good if it could avoid mangling parameter
120
 
# descriptions like this:
121
 
 
122
 
def foo(self):
123
 
    \"\"\"Summary line.
124
 
 
125
 
    Foo bar fhgdjkfd hgjfd hgjkfd ghjkdf ghjkdf hgjdf ghjkdf
126
 
hgjdf hjgk dfhjkg dfhjkg dfhjkg fdhjkg hjfdkg
127
 
 
128
 
    Parameters
129
 
    ----------
130
 
    endog : array-like
131
 
        1-d endogenous response variable. The dependent variable.
132
 
    exog : array-like
133
 
        A nobs x k array where `nobs` is the number of
134
 
observations and `k`
135
 
        is the number of regressors. An interecept is not
136
 
included by default
137
 
        and should be added by the user. See
138
 
        `statsmodels.tools.add_constant`.\"\"\"
139
 
 
140
 
def foo(self):
141
 
    \"\"\"Summary line. Foo bar fhgdjkfdhgjfd hgjkfd ghjkdf ghjkdf
142
 
hgjdf
143
 
 
144
 
    ghjkdf hgjdf hjgk dfhjkg dfhjkg dfhjkg fdhjkghjfdkg
145
 
Parameters
146
 
    ---------- endog : array-like 1-d endogenous response
147
 
variable. The
148
 
    dependent variable. exog : array-like A nobs x karray where
149
 
`nobs`
150
 
    is the number of observations and `k` is the number of
151
 
regressors.
152
 
    An interecept is not included by default and should be added
153
 
by the
154
 
    user. See `statsmodels.tools.add_constant`.
155
 
    \"\"\"
156
 
 
157
 
# Failing that though, if I can at least choose to
158
 
# reflow individual paragraphs in the docstring and
159
 
# leave others intact, I can format these things
160
 
# manually while still being able to flow other
161
 
# paragraphs using M-q.
162
 
"
163
 
    (when py-debug-p (switch-to-buffer (current-buffer)))
164
 
    (font-lock-fontify-buffer)
165
 
    (search-forward "Some other" nil t 1)
166
 
    (sit-for 0.1 t)
167
 
    (fill-paragraph)
168
 
    (forward-line -2)
169
 
    (should (not (empty-line-p)))
170
 
    (forward-line 1)
171
 
    (should (eq (char-after) ?\n))
172
 
    (search-forward "one-line summary." nil t 1)
173
 
    (when py-debug-p (message "fill-column: %s" fill-column))
174
 
    (fill-paragraph)
175
 
    (forward-line 1)
176
 
    (sit-for 0.1 t)
177
 
    (should (empty-line-p))
178
 
    (search-forward "Foo bar" nil t 1)
179
 
    (fill-paragraph)
180
 
    (forward-line 2)
181
 
    (should (eq (char-after) ?\n))))
182
 
 
183
 
(ert-deftest py-ert-backward-same-level-test ()
184
 
  (py-test-with-temp-buffer-point-min
185
 
      "def foo():
186
 
    if True:
187
 
        def bar():
188
 
            pass
189
 
    elif False:
190
 
        def baz():
191
 
            pass
192
 
    else:
193
 
        try:
194
 
            1 == 1
195
 
        except True:
196
 
            def foo1():
197
 
                if True:
198
 
                    def bar1():
199
 
                        pass
200
 
                elif False:
201
 
                    def baz1():
202
 
                        pass
203
 
                else:
204
 
                    try:
205
 
                        1 == 1
206
 
                    except True:
207
 
                        pass
208
 
                    else:
209
 
                        pass
210
 
                    finally:
211
 
                        pass
212
 
        else True:
213
 
            pass
214
 
        finally:
215
 
            pass
216
 
"
217
 
    (font-lock-fontify-buffer)
218
 
    (goto-char 632)
219
 
    (py-backward-same-level)
220
 
    (should (looking-at "except"))
221
 
    (py-backward-same-level)
222
 
    (should (looking-at "try"))))
223
 
 
224
 
(ert-deftest py-ert-up-level-test-2 ()
225
 
  (py-test-with-temp-buffer-point-min
226
 
      "def foo():
227
 
    if True:
228
 
        def bar():
229
 
            pass
230
 
    elif False:
231
 
        def baz():
232
 
            pass
233
 
    else:
234
 
        try:
235
 
            1 == 1
236
 
        except True:
237
 
            def foo1():
238
 
                if True:
239
 
                    def bar1():
240
 
                        pass
241
 
                elif False:
242
 
                    def baz1():
243
 
                        pass
244
 
                else:
245
 
                    try:
246
 
                        1 == 1
247
 
                    except True:
248
 
                        pass
249
 
                    else True:
250
 
                        pass
251
 
                    finally:
252
 
                        pass
253
 
        else True:
254
 
            pass
255
 
        finally:
256
 
            pass
257
 
"
258
 
    (goto-char 632)
259
 
    (py-up-block)
260
 
    (should (looking-at "else:"))))
261
 
 
262
 
 
263
 
(ert-deftest py-ert-deletes-too-much-lp:1300270 ()
264
 
  (py-test-with-temp-buffer "
265
 
x = {'abc':'def',
266
 
         'ghi':'jkl'}
267
 
"
268
 
    ;; (when py-debug-p (switch-to-buffer (current-buffer)))
269
 
    (goto-char 24)
270
 
    (py-electric-delete)
271
 
    (should (eq 5 (current-indentation)))))
272
 
 
273
 
(ert-deftest py-ert-mark-expression-test ()
274
 
    "Avoid infinite loop"
275
 
  (py-test-with-temp-buffer
276
 
      "assert pycompletions('TestClass.test' , name) == \
277
 
          ['testclassmeth', 'testmeth', 'testprop', 'teststaticmeth']"
278
 
    (forward-char -1)
279
 
    (py-mark-expression)
280
 
    (should (eq 119 (mark)))
281
 
    (goto-char 44)
282
 
    (py-mark-expression)
283
 
    (should (eq 46 (mark)))))
284
 
 
285
 
(ert-deftest py-dedicated-shell-test ()
286
 
  ""
287
 
  (let ((erg (py-shell nil t "python")))
288
 
    (should (< 8 (length erg)))
289
 
    (should (eq 0 (string-match "^*Python" erg)))))
290
 
 
291
 
(ert-deftest py-python-shell-test ()
292
 
  ""
293
 
  (let ((erg (python)))
294
 
    (should (bufferp (get-buffer erg)))
295
 
    (should (get-buffer-process erg))))
296
 
 
297
 
(ert-deftest py-python2-shell-test ()
298
 
  ""
299
 
  (let ((erg (python2)))
300
 
    (should (bufferp (get-buffer erg)))
301
 
    (should (get-buffer-process erg))))
302
 
 
303
 
(ert-deftest py-python3-shell-test ()
304
 
  ""
305
 
  (let ((erg (python3)))
306
 
    (should (bufferp (get-buffer erg)))
307
 
    (should (get-buffer-process erg))))
308
 
 
309
 
(ert-deftest py-keep-windows-configuration-test ()
310
 
  (py-test-with-temp-buffer
311
 
      "print('py-keep-windows-configuration-test-string')"
312
 
    (delete-other-windows)
313
 
    (let ((py-keep-windows-configuration t)
314
 
          (py-split-window-on-execute t)
315
 
          (full-height (window-height)))
316
 
      (py-execute-statement)
317
 
      (should (eq (window-height) full-height)))))
318
 
 
319
 
(ert-deftest py-compute-indentation-after-import-test ()
320
 
    (py-test-with-temp-buffer
321
 
    "import pdb
322
 
"
323
 
    (should (eq 0 (py-compute-indentation)))))
324
 
 
325
 
(ert-deftest py-compute-indentation-bob-test ()
326
 
    (py-test-with-temp-buffer-point-min
327
 
    " def foo():
328
 
    if True:
329
 
        pass
330
 
    else:
331
 
        pass
332
 
"
333
 
 
334
 
    (should (eq 0 (py-compute-indentation)))))
335
 
 
336
 
(ert-deftest py-indentation-lp-1375122-test ()
337
 
  (py-test-with-temp-buffer
338
 
      "def foo():
339
 
    if True:
340
 
pass
341
 
"
342
 
    (forward-line -1)
343
 
    (call-interactively 'py-indent-or-complete)
344
 
    (sit-for 0.1 t)
345
 
    (should (eq 8 (current-column)))
346
 
    (beginning-of-line)
347
 
    (delete-horizontal-space)
348
 
    (indent-to 4)
349
 
    (call-interactively 'py-indent-or-complete)
350
 
    (sit-for 0.1 t)
351
 
    (should (eq 8 (current-column)))
352
 
    ;;
353
 
    ;; (call-interactively 'py-indent-or-complete)
354
 
    ;; (call-interactively 'py-indent-or-complete)
355
 
    ;; (sit-for 0.1 t)
356
 
    ;; (should (eq 4 (current-column)))
357
 
    ;; (py-indent-or-complete)
358
 
    ;; (sit-for 0.1 t)
359
 
    ;; (should (eq 8 (current-column)))
360
 
    ))
361
 
 
362
 
(ert-deftest py-shell-python-lp-1398530-test ()
363
 
  (when (buffer-live-p (get-buffer "*Python*"))(py-kill-buffer-unconditional "*Python*"))
364
 
  (py-test-with-temp-buffer
365
 
      ""
366
 
    (when py-debug-p (switch-to-buffer (current-buffer)))
367
 
    (let ((py-shell-name "python"))
368
 
      (py-shell)
369
 
      (sit-for 0.1 t)
370
 
      (should (buffer-live-p (get-buffer "*Python*"))))))
371
 
 
372
 
(ert-deftest py-shell-python3-lp-1398530-test ()
373
 
  (when (buffer-live-p (get-buffer "*Python3*"))(py-kill-buffer-unconditional "*Python3*"))
374
 
  (py-test-with-temp-buffer
375
 
      ""
376
 
 
377
 
    (let ((py-shell-name "python3"))
378
 
      (py-shell)
379
 
      (sit-for 0.1 t)
380
 
      (should (buffer-live-p (get-buffer "*Python3*"))))))
381
 
 
382
 
(ert-deftest py-shell-python2-lp-1398530-test ()
383
 
  (when (buffer-live-p (get-buffer "*Python2*"))(py-kill-buffer-unconditional "*Python2*"))
384
 
  (py-test-with-temp-buffer
385
 
      ""
386
 
    (when py-debug-p (switch-to-buffer (current-buffer)))
387
 
    (let ((py-shell-name "python2"))
388
 
      (py-shell)
389
 
      (sit-for 0.1 t)
390
 
      (should (buffer-live-p (get-buffer "*Python2*"))))))
391
 
 
392
 
(ert-deftest py-backward-statement-test-1 ()
393
 
  (py-test-with-temp-buffer
394
 
      (let ((py-return-result-p t)
395
 
            py-result py-store-result-p)
396
 
        "# -*- coding: utf-8 -*-
397
 
print dir()
398
 
c = Cat()
399
 
c.hello() #causes error, but emacs tracking fails
400
 
import sys, os; os.remove('do/something/nasty') # lp:1025000
401
 
 
402
 
def foo(*args):2
403
 
    \"\"\"
404
 
    ASDF
405
 
    \"\"\"
406
 
    # ABD
407
 
    args = \"asdf\"
408
 
")
409
 
    (py-backward-statement)
410
 
    (should (eq (char-after) ?a))
411
 
    (py-backward-statement)
412
 
    (should (eq (char-after) ?d))
413
 
    (py-backward-statement)
414
 
    (should (eq (char-after) ?o))
415
 
    (py-backward-statement)
416
 
    (should (eq (char-after) ?i))
417
 
    (py-backward-statement)
418
 
    (should (eq (char-after) ?c))
419
 
    (py-backward-statement)
420
 
    (should (eq (char-after) ?c))
421
 
    (py-backward-statement)
422
 
    (should (eq (char-after) ?p))
423
 
    (py-backward-statement)
424
 
    (should (bobp))))
425
 
 
426
 
(ert-deftest py-ert-backward-except-block-test ()
427
 
  (py-test-with-temp-buffer
428
 
      "
429
 
# -*- coding: utf-8 -*-
430
 
class bar:
431
 
    def foo ():
432
 
        try:
433
 
            if True:
434
 
                for a in range(anzahl):
435
 
                    pass
436
 
        except:
437
 
            block2
438
 
        "
439
 
    (py-backward-except-block)
440
 
    (should (eq (char-after) ?e))))
441
 
 
442
 
(ert-deftest py-ert-backward-except-block-bol-test ()
443
 
  (py-test-with-temp-buffer
444
 
      "
445
 
# -*- coding: utf-8 -*-
446
 
class bar:
447
 
    def foo ():
448
 
        try:
449
 
            if True:
450
 
                for a in range(anzahl):
451
 
                    pass
452
 
        except:
453
 
            block2
454
 
        "
455
 
    (py-backward-except-block-bol)
456
 
    (should (eq (char-after) ?\ ))))
457
 
 
458
 
  ;; (and (bufferp (get-buffer "*Python*"))(buffer-live-p (get-buffer "*Python*"))(py-kill-buffer-unconditional "*Python*"))
459
 
  ;; (and (bufferp (get-buffer "*IPython*"))(buffer-live-p (get-buffer "*IPython*"))(py-kill-buffer-unconditional "*IPython*")))
460
 
 
461
 
(defun nested-dictionaries-indent-lp:328791-test (&optional arg)
462
 
  "With ARG greater 1 keep test buffer open.
463
 
 
464
 
If no `load-branch-function' is specified, make sure the appropriate branch is loaded. Otherwise default python-mode will be checked. "
465
 
  (interactive "p")
466
 
  (let ((teststring "
467
 
 
468
 
# hanging
469
 
asdf = {
470
 
    'a':{
471
 
         'b':3,
472
 
         'c':4
473
 
        }
474
 
    }
475
 
 
476
 
# closing
477
 
asdf = {
478
 
    'a':{
479
 
        'b':3,
480
 
        'c':4
481
 
    }
482
 
}
483
 
 
484
 
data = {
485
 
    'key':
486
 
    {
487
 
        'objlist': [
488
 
            {
489
 
                'pk': 1,
490
 
                'name': 'first',
491
 
            },
492
 
            {
493
 
                'pk': 2,
494
 
                'name': 'second',
495
 
            }
496
 
        ]
497
 
    }
498
 
}
499
 
 
500
 
"))
501
 
    (py-bug-tests-intern 'nested-dictionaries-indent-lp:328791-base arg teststring)))
502
 
 
503
 
(ert-deftest py-ert-nested-dictionaries-indent-lp:328791-test ()
504
 
  (py-test-with-temp-buffer-point-min
505
 
      "
506
 
 
507
 
# hanging
508
 
asdf = {
509
 
    'a':{
510
 
         'b':3,
511
 
         'c':4
512
 
        }
513
 
    }
514
 
 
515
 
# closing
516
 
asdf = {
517
 
    'a':{
518
 
        'b':3,
519
 
        'c':4
520
 
    }
521
 
}
522
 
 
523
 
data = {
524
 
    'key':
525
 
    {
526
 
        'objlist': [
527
 
            {
528
 
                'pk': 1,
529
 
                'name': 'first',
530
 
            },
531
 
            {
532
 
                'pk': 2,
533
 
                'name': 'second',
534
 
            }
535
 
        ]
536
 
    }
537
 
}
538
 
 
539
 
"
540
 
    (let ((py-indent-honors-multiline-listing t)
541
 
          py-closing-list-dedents-bos)
542
 
      (search-forward "'a':{")
543
 
      (should (eq 4 (py-compute-indentation)))
544
 
      (search-forward "}")
545
 
      (should (eq 8 (py-compute-indentation)))
546
 
      (search-forward "}")
547
 
      (should (eq 4 (py-compute-indentation)))
548
 
      ;; py-closing-list-dedents-bos
549
 
      (setq py-closing-list-dedents-bos t)
550
 
      (search-forward "'a':{")
551
 
      (should (eq 4 (py-compute-indentation)))
552
 
      (search-forward "}")
553
 
      (should (eq 4 (py-compute-indentation)))
554
 
      (search-forward "}")
555
 
      (should (eq 0 (py-compute-indentation)))
556
 
      (search-forward "}" nil nil 2)
557
 
      (should (eq 12 (py-compute-indentation)))
558
 
      (search-forward "]")
559
 
      (should (eq 8 (py-compute-indentation)))
560
 
      (search-forward "}")
561
 
      (should (eq 4 (py-compute-indentation)))
562
 
      (search-forward "}")
563
 
      (should (eq 0 (py-compute-indentation))))))
564
 
 
565
 
(ert-deftest py-ert-flexible-indentation-lp-328842-test-1 ()
566
 
  (py-test-with-temp-buffer-point-min
567
 
      "\(long, sequence, of_items,
568
 
 that, needs, to_be, wrapped) = input_list
569
 
 
570
 
packed_entry = (long, sequence, of_items,
571
 
that, needs, to_be, wrapped)
572
 
 
573
 
\( whitespaced, long, sequence, of_items,
574
 
    that, needs, to_be, wrapped) = input_list
575
 
"
576
 
    (let ((py-indent-honors-multiline-listing t))
577
 
        (search-forward "(long")
578
 
      (forward-char -1)
579
 
      ;; (goto-char 6)
580
 
      (should (eq nil (get-char-property (point) 'face))))))
581
 
 
582
 
(ert-deftest py-ert-flexible-indentation-lp-328842-test-2 ()
583
 
  (py-test-with-temp-buffer-point-min
584
 
      "\(long, sequence, of_items,
585
 
 that, needs, to_be, wrapped) = input_list
586
 
 
587
 
packed_entry = (long, sequence, of_items,
588
 
that, needs, to_be, wrapped)
589
 
 
590
 
\( whitespaced, long, sequence, of_items,
591
 
    that, needs, to_be, wrapped) = input_list
592
 
"
593
 
    (let ((py-indent-honors-multiline-listing t)
594
 
          py-indent-paren-spanned-multilines-p)
595
 
      (goto-char 33)
596
 
      (assert (eq 1 (py-compute-indentation)) nil "flexible-indentation-lp-328842-test failed")
597
 
      (goto-char 115)
598
 
      (assert (eq 16 (py-compute-indentation)) nil "flexible-indentation-lp-328842-test failed")
599
 
      (goto-char 202)
600
 
      (assert (eq 2 (py-compute-indentation)) nil "flexible-indentation-lp-328842-test failed"))))
601
 
 
602
 
(ert-deftest py-ert-flexible-indentation-lp-328842-test-3 ()
603
 
  (py-test-with-temp-buffer-point-min
604
 
      "\(long, sequence, of_items,
605
 
 that, needs, to_be, wrapped) = input_list
606
 
 
607
 
packed_entry = (long, sequence, of_items,
608
 
that, needs, to_be, wrapped)
609
 
 
610
 
\( whitespaced, long, sequence, of_items,
611
 
    that, needs, to_be, wrapped) = input_list
612
 
"
613
 
    (let ((py-indent-honors-multiline-listing t)
614
 
          (py-indent-paren-spanned-multilines-p t))
615
 
      (goto-char 33)
616
 
      (assert (eq 5 (py-compute-indentation)) nil "flexible-indentation-lp-328842-test failed")
617
 
      (goto-char 115)
618
 
      (assert (eq 20 (py-compute-indentation)) nil "flexible-indentation-lp-328842-test failed")
619
 
      (goto-char 202)
620
 
      (assert (eq 6 (py-compute-indentation)) nil "flexible-indentation-lp-328842-test failed"))))
621
 
 
622
 
(ert-deftest py-ert-indent-in-arglist-test ()
623
 
  (py-test-with-temp-buffer
624
 
      "def foo (a,
625
 
 
626
 
):"
627
 
    (let (py-indent-paren-spanned-multilines-p)
628
 
      (should (eq 9 (py-compute-indentation))))
629
 
    (let ((py-indent-paren-spanned-multilines-p t))
630
 
      (should (eq 13 (py-compute-indentation))))))
631
 
 
632
 
(ert-deftest py-complete-in-python-shell-test ()
633
 
  (let ((py-shell-name "python")
634
 
        (py-switch-buffers-on-execute-p t))
635
 
    (py-kill-buffer-unconditional "*Python*")
636
 
    (python)
637
 
    (goto-char (point-max))
638
 
    (insert "pri")
639
 
    (py-indent-or-complete)
640
 
    (forward-word -1)
641
 
    (should (eq ?p (char-after)))))
642
 
 
643
 
(ert-deftest py-complete-in-python3-shell-test ()
644
 
  (let ((py-shell-name "python3")
645
 
        (py-switch-buffers-on-execute-p t))
646
 
    (py-kill-buffer-unconditional "*Python3*")
647
 
    (python3)
648
 
    (should (eq (current-buffer) (get-buffer "*Python3*")))
649
 
    (goto-char (point-max))
650
 
    (insert "pri")
651
 
    (py-indent-or-complete)
652
 
    (forward-word -1)
653
 
    (should (eq ?p (char-after)))))
654
 
 
655
 
(ert-deftest py-complete-empty-string-result-test ()
656
 
  (let ((py-shell-name "python3")
657
 
        (py-switch-buffers-on-execute-p t))
658
 
    (py-kill-buffer-unconditional "*Python3*")
659
 
    (python3)
660
 
    (goto-char (point-max))
661
 
    (insert "foo")
662
 
    (py-indent-or-complete)
663
 
    (should (looking-back "foo"))))
664
 
 
665
 
(ert-deftest py-ert-close-block-test ()
666
 
  (py-test-with-temp-buffer-point-min
667
 
      "# -*- coding: utf-8 -*-
668
 
 
669
 
def main():
670
 
    if len(sys.argv)==1:
671
 
        usage()
672
 
        sys.exit()
673
 
if __name__==\"__main__\":
674
 
    main()
675
 
"
676
 
    (search-forward "exit()")
677
 
    (should (eq 4 (py-close-block)))))
678
 
 
679
 
(ert-deftest py-ert-close-def-or-class-test ()
680
 
  (py-test-with-temp-buffer-point-min
681
 
      "# -*- coding: utf-8 -*-
682
 
 
683
 
def main():
684
 
    if len(sys.argv)==1:
685
 
        usage()
686
 
        sys.exit()
687
 
if __name__==\"__main__\":
688
 
    main()
689
 
"
690
 
    (search-forward "exit()")
691
 
    (should (eq 0 (py-close-def-or-class)))))
692
 
 
693
 
(ert-deftest py-ert-close-def-test ()
694
 
  (py-test-with-temp-buffer-point-min
695
 
      "# -*- coding: utf-8 -*-
696
 
 
697
 
def main():
698
 
    if len(sys.argv)==1:
699
 
        usage()
700
 
        sys.exit()
701
 
if __name__==\"__main__\":
702
 
    main()
703
 
"
704
 
    (search-forward "exit()")
705
 
    (should (eq 0 (py-close-def)))))
706
 
 
707
 
(ert-deftest py-ert-close-class-test ()
708
 
  (py-test-with-temp-buffer-point-min
709
 
      "# -*- coding: utf-8 -*-
710
 
class asdf:
711
 
    def main():
712
 
        if len(sys.argv)==1:
713
 
            usage()
714
 
            sys.exit()
715
 
    if __name__==\"__main__\":
716
 
        main()
717
 
"
718
 
    (search-forward "exit()")
719
 
    (should (eq 0 (py-close-class)))))
720
 
 
721
 
(ert-deftest py-ert-dedent-forward-test ()
722
 
  (py-test-with-temp-buffer
723
 
   "with file(\"roulette-\" + zeit + \".csv\", 'w') as datei:
724
 
    for i in range(anzahl):
725
 
        klauf.pylauf()
726
 
        datei.write(str(spiel[i]) + \"\\n\")"
727
 
   (skip-chars-backward " \t\r\n\f")
728
 
   (py-dedent-forward-line)
729
 
   (should (empty-line-p))
730
 
   (forward-line -1)
731
 
   (should (eq 4 (current-indentation)))))
732
 
 
733
 
 
734
 
(ert-deftest py-face-lp-1454858-python2-1-test ()
735
 
  (let ((py-python-edit-version ""))
736
 
    (py-test-with-temp-buffer
737
 
        "#! /usr/bin/env python2
738
 
file.close()"
739
 
      (beginning-of-line)
740
 
      (font-lock-fontify-buffer)
741
 
      (sit-for 0.1)
742
 
      (should (eq (face-at-point) 'py-builtins-face)))))
743
 
 
744
 
;; Setting of py-python-edit-version should precede
745
 
(ert-deftest py-face-lp-1454858-python2-2-test ()
746
 
  (let ((py-python-edit-version "python2"))
747
 
    (py-test-with-temp-buffer
748
 
        "#! /usr/bin/env python3
749
 
file.close()"
750
 
      (beginning-of-line)
751
 
      (font-lock-fontify-buffer)
752
 
      (sit-for 0.1)
753
 
      (should (eq (face-at-point) 'py-builtins-face)))))
754
 
 
755
 
(ert-deftest py-face-lp-1454858-python2-3-test ()
756
 
  (let ((py-python-edit-version ""))
757
 
    (with-temp-buffer
758
 
      (insert "#! /usr/bin/env python2
759
 
print()")
760
 
      (switch-to-buffer (current-buffer))
761
 
      (beginning-of-line)
762
 
      (python-mode)
763
 
      (font-lock-fontify-buffer)
764
 
      (sit-for 0.1)
765
 
      (should (eq (face-at-point) 'font-lock-keyword-face)))))
766
 
 
767
 
(ert-deftest py-ert-in-comment-p-test ()
768
 
  (py-test-with-temp-buffer
769
 
      "# "
770
 
    (should (py--in-comment-p))))
771
 
 
772
 
(ert-deftest py-ert-in-sq-string-p-test ()
773
 
  (py-test-with-temp-buffer
774
 
      "' "
775
 
    (should (py-in-string-p))))
776
 
 
777
 
(ert-deftest py-ert-in-dq-string-p-test ()
778
 
  (py-test-with-temp-buffer
779
 
      "\" "
780
 
    (should (py-in-string-p))))
781
 
 
782
 
(ert-deftest py-ert-in-sq-tqs-string-p-test ()
783
 
  (py-test-with-temp-buffer
784
 
      "''' "
785
 
    (should (py-in-string-p))))
786
 
 
787
 
(ert-deftest py-ert-in-dq-tqs-string-p-test ()
788
 
  (py-test-with-temp-buffer
789
 
      "\"\"\" "
790
 
    (should (py-in-string-p))))
791
 
 
792
 
(ert-deftest py-ert-electric-delete-test ()
793
 
  (py-test-with-temp-buffer-point-min
794
 
      "  {}"
795
 
    (py-electric-delete)
796
 
    (should (eq (char-after) ?{))))
797
 
 
798
 
(ert-deftest py-ert-end-of-def-or-class-test-1 ()
799
 
  (py-test-with-temp-buffer-point-min
800
 
      "class MyTest(unittest.TestCase):
801
 
    def test(self):
802
 
        self.assertEqual(fun(3), 4)"
803
 
    (skip-chars-forward "^(")
804
 
    (py-end-of-def-or-class)
805
 
    (should (eobp))))
806
 
 
807
 
(ert-deftest py-ert-end-of-def-or-class-test-2 ()
808
 
  (py-test-with-temp-buffer-point-min
809
 
      "class MyTest(unittest.TestCase):
810
 
    def test(self):
811
 
        pass
812
 
    def test(self):
813
 
        pass"
814
 
    (search-forward "pass")
815
 
    (py-end-of-def-or-class)
816
 
    (should (eobp))))
817
 
 
818
 
(ert-deftest py-ert-narrow-to-block-test ()
819
 
  (py-test-with-temp-buffer
820
 
      "with file(\"roulette-\" + zeit + \".csv\", 'w') as datei:
821
 
    for i in range(anzahl):
822
 
        klauf.pylauf()
823
 
        "
824
 
      (py-narrow-to-block)
825
 
      (should (eq 50 (length (buffer-substring-no-properties (point-min)(point-max)))))))
826
 
 
827
 
(ert-deftest py-ert-narrow-to-block-or-clause-test ()
828
 
  (py-test-with-temp-buffer
829
 
      "if treffer in gruen:
830
 
    # print \"0, Gruen\"
831
 
    ausgabe[1] = treffer
832
 
    ausgabe[2] = treffer
833
 
 
834
 
elif treffer in schwarz:
835
 
    # print \"%i, Schwarz\" % (treffer)
836
 
    ausgabe[1] = treffer
837
 
"
838
 
    (py-narrow-to-block-or-clause)
839
 
    (should (eq 87 (length (buffer-substring-no-properties (point-min)(point-max)))))))
840
 
 
841
 
(ert-deftest py-ert-narrow-to-clause-test ()
842
 
  (py-test-with-temp-buffer
843
 
      "if treffer in gruen:
844
 
    # print \"0, Gruen\"
845
 
    ausgabe[1] = treffer
846
 
    ausgabe[2] = treffer
847
 
 
848
 
elif treffer in schwarz:
849
 
    # print \"%i, Schwarz\" % (treffer)
850
 
    ausgabe[1] = treffer
851
 
"
852
 
    (py-narrow-to-clause)
853
 
    (should (eq 87 (length (buffer-substring-no-properties (point-min)(point-max)))))))
854
 
 
855
 
(ert-deftest py-ert-narrow-to-class-test ()
856
 
  (py-test-with-temp-buffer
857
 
      py-def-and-class-test-string
858
 
    (search-backward "treffer")
859
 
    (py-narrow-to-class)
860
 
    (should (eq 710 (length (buffer-substring-no-properties (point-min)(point-max)))))))
861
 
 
862
 
(ert-deftest py-ert-narrow-to-def-test ()
863
 
  (py-test-with-temp-buffer
864
 
      py-def-and-class-test-string
865
 
    (search-backward "treffer")
866
 
    (py-narrow-to-def)
867
 
    (should (< 480 (length (buffer-substring-no-properties (point-min)(point-max)))))))
868
 
 
869
 
(ert-deftest py-ert-narrow-to-def-or-class-test ()
870
 
  (py-test-with-temp-buffer
871
 
      py-def-and-class-test-string
872
 
    (search-backward "treffer")
873
 
    (py-narrow-to-def-or-class)
874
 
    (should (< 480 (length (buffer-substring-no-properties (point-min)(point-max)))))
875
 
    (should (> 490 (length (buffer-substring-no-properties (point-min)(point-max)))))))
876
 
 
877
 
(ert-deftest py-ert-narrow-to-statement-test ()
878
 
  (py-test-with-temp-buffer
879
 
      py-def-and-class-test-string
880
 
    (search-backward "treffer")
881
 
    (py-narrow-to-statement)
882
 
    (should (eq 32 (length (buffer-substring-no-properties (point-min)(point-max)))))))
883
 
 
884
 
(ert-deftest py-ert-section-backward-test ()
885
 
  (py-test-with-temp-buffer
886
 
      "# {{
887
 
print('%(language)s has %(number)03d quote types.' %
888
 
       {'language': \"Python\", \"number\": 2})
889
 
# }}
890
 
# {{
891
 
print(\"%(language)s has %(number)03d quote types.\" %
892
 
       {'language': \"Python\", \"number\": 2})
893
 
# }}
894
 
"
895
 
    (py-backward-section)
896
 
    (should (eq (char-after) ?#))
897
 
    (py-backward-section)
898
 
    (should (eq (char-after) ?#))))
899
 
 
900
 
(ert-deftest py-ert-section-forward-test ()
901
 
  (py-test-with-temp-buffer-point-min
902
 
      "# {{
903
 
print('%(language)s has %(number)03d quote types.' %
904
 
       {'language': \"Python\", \"number\": 2})
905
 
# }}
906
 
# {{
907
 
print(\"%(language)s has %(number)03d quote types.\" %
908
 
       {'language': \"Python\", \"number\": 2})
909
 
# }}
910
 
"
911
 
    (py-forward-section)
912
 
    (should (eq (char-before) ?}))
913
 
    (py-forward-section)
914
 
    (should (eq (char-before) ?}))))
915
 
 
916
 
(ert-deftest py-ert-sectionize-test ()
917
 
  (py-test-with-temp-buffer-point-min
918
 
      "print('%(language)s has %(number)03d quote types.' %
919
 
       {'language': \"Python\", \"number\": 2})
920
 
"
921
 
    (end-of-line)
922
 
    (py-sectionize-region (point-min) (point-max))
923
 
    (goto-char (point-min))
924
 
    (should (eq (char-after) ?#))
925
 
    (py-forward-section)
926
 
    (should (eq (char-before) ?}))))
927
 
 
928
 
(ert-deftest py-ert-jump-matching-indent-test ()
929
 
  (py-test-with-temp-buffer
930
 
      py-def-and-class-test-string
931
 
    (search-backward "if ")
932
 
    (forward-line -1)
933
 
    (indent-to 12)
934
 
    (py-backward-block)
935
 
    (should (eq (current-column) 8))))
936
 
 
937
 
(ert-deftest py-ert-fill-plain-string-test ()
938
 
  (py-test-with-temp-buffer-point-min
939
 
      "'''asdf' asdf asdf asdf asdf asdfasdf asdfasdf a asdf asdf asdf asdfasdfa asdf asdf asdf asdf asdf' asdf asdf asdf asdf asdfasdf asdfasdf a asdf asdf asdf asdfasdfa asdf asdf asdf asdfasdf' asdf asdf asdf asdf asdfasdf asdfasdf a asdf asdf asdf asdfasdfa asdf asdf asdf asdf
940
 
'''"
941
 
      (forward-char 4)
942
 
      (fill-paragraph)
943
 
      (forward-line 1)
944
 
      (should (not (empty-line-p)))))
945
 
 
946
 
(ert-deftest py-ert-nil-docstring-style-lp-1477422-test ()
947
 
  (py-test-with-temp-buffer-point-min
948
 
      "def foo():
949
 
    '''asdf' asdf asdf asdf asdf asdfasdf asdfasdf a asdf asdf asdf asdfasdfa asdf asdf asdf asdf asdf' asdf asdf asdf asdf asdfasdf asdfasdf a asdf asdf asdf asdfasdfa asdf asdf asdf asdfasdf' asdf asdf asdf asdf asdfasdf asdfasdf a asdf asdf asdf asdfasdfa asdf asdf asdf asdf'''"
950
 
    (let (py-docstring-style)
951
 
      (search-forward "'''")
952
 
      (save-excursion
953
 
        (fill-paragraph))
954
 
      (forward-line 1)
955
 
      (should (not (empty-line-p))))))
956
 
 
957
 
(ert-deftest py-markup-region-as-section-test ()
958
 
  (py-test-with-temp-buffer-point-min
959
 
      py-def-and-class-test-string
960
 
      (search-forward "fertig")
961
 
      (py-sectionize-region (match-beginning 0) (line-end-position))
962
 
      (py-mark-section)
963
 
      (should (eq 371 (region-beginning)))
964
 
      (should (eq 408 (region-end)))))
965
 
 
966
 
 
967
 
(ert-deftest py-indent-in-docstring-gh6 ()
968
 
  (py-test-with-temp-buffer-point-min
969
 
      "def f():
970
 
    \"\"\"
971
 
    Return nothing.
972
 
 
973
 
    .. NOTE::
974
 
 
975
 
        First note line
976
 
    second note line\"\"\"
977
 
    pass"
978
 
    (search-forward "second")
979
 
    (back-to-indentation)
980
 
    (should (eq 8 (py-compute-indentation)))))
981
 
 
982
 
(provide 'py-ert-tests-2)
983
 
;;; py-ert-tests-2.el ends here