diff options
Diffstat (limited to 'test/automated/python-tests.el')
| -rw-r--r-- | test/automated/python-tests.el | 207 |
1 files changed, 145 insertions, 62 deletions
diff --git a/test/automated/python-tests.el b/test/automated/python-tests.el index d490f7f9df5..1f8533f9b1a 100644 --- a/test/automated/python-tests.el +++ b/test/automated/python-tests.el | |||
| @@ -2440,107 +2440,190 @@ Using `python-shell-interpreter' and | |||
| 2440 | python-shell-interpreter-args) | 2440 | python-shell-interpreter-args) |
| 2441 | (python-shell-calculate-command))))) | 2441 | (python-shell-calculate-command))))) |
| 2442 | 2442 | ||
| 2443 | (ert-deftest python-shell-calculate-pythonpath-1 () | ||
| 2444 | "Test PYTHONPATH calculation." | ||
| 2445 | (let ((process-environment '("PYTHONPATH=/path0")) | ||
| 2446 | (python-shell-extra-pythonpaths '("/path1" "/path2"))) | ||
| 2447 | (should (string= (python-shell-calculate-pythonpath) | ||
| 2448 | "/path1:/path2:/path0")))) | ||
| 2449 | |||
| 2450 | (ert-deftest python-shell-calculate-pythonpath-2 () | ||
| 2451 | "Test existing paths are moved to front." | ||
| 2452 | (let ((process-environment '("PYTHONPATH=/path0:/path1")) | ||
| 2453 | (python-shell-extra-pythonpaths '("/path1" "/path2"))) | ||
| 2454 | (should (string= (python-shell-calculate-pythonpath) | ||
| 2455 | "/path1:/path2:/path0")))) | ||
| 2456 | |||
| 2443 | (ert-deftest python-shell-calculate-process-environment-1 () | 2457 | (ert-deftest python-shell-calculate-process-environment-1 () |
| 2444 | "Test `python-shell-process-environment' modification." | 2458 | "Test `python-shell-process-environment' modification." |
| 2445 | (let* ((python-shell-process-environment | 2459 | (let* ((python-shell-process-environment |
| 2446 | '("TESTVAR1=value1" "TESTVAR2=value2")) | 2460 | '("TESTVAR1=value1" "TESTVAR2=value2")) |
| 2447 | (process-environment | 2461 | (process-environment (python-shell-calculate-process-environment))) |
| 2448 | (python-shell-calculate-process-environment))) | ||
| 2449 | (should (equal (getenv "TESTVAR1") "value1")) | 2462 | (should (equal (getenv "TESTVAR1") "value1")) |
| 2450 | (should (equal (getenv "TESTVAR2") "value2")))) | 2463 | (should (equal (getenv "TESTVAR2") "value2")))) |
| 2451 | 2464 | ||
| 2452 | (ert-deftest python-shell-calculate-process-environment-2 () | 2465 | (ert-deftest python-shell-calculate-process-environment-2 () |
| 2453 | "Test `python-shell-extra-pythonpaths' modification." | 2466 | "Test `python-shell-extra-pythonpaths' modification." |
| 2454 | (let* ((process-environment process-environment) | 2467 | (let* ((process-environment process-environment) |
| 2455 | (original-pythonpath (setenv "PYTHONPATH" "path3")) | 2468 | (original-pythonpath (setenv "PYTHONPATH" "/path0")) |
| 2456 | (paths '("path1" "path2")) | 2469 | (python-shell-extra-pythonpaths '("/path1" "/path2")) |
| 2457 | (python-shell-extra-pythonpaths paths) | 2470 | (process-environment (python-shell-calculate-process-environment))) |
| 2458 | (process-environment | 2471 | (should (equal (getenv "PYTHONPATH") "/path1:/path2:/path0")))) |
| 2459 | (python-shell-calculate-process-environment))) | ||
| 2460 | (should (equal (getenv "PYTHONPATH") | ||
| 2461 | (concat | ||
| 2462 | (mapconcat 'identity paths path-separator) | ||
| 2463 | path-separator original-pythonpath))))) | ||
| 2464 | 2472 | ||
| 2465 | (ert-deftest python-shell-calculate-process-environment-3 () | 2473 | (ert-deftest python-shell-calculate-process-environment-3 () |
| 2466 | "Test `python-shell-virtualenv-root' modification." | 2474 | "Test `python-shell-virtualenv-root' modification." |
| 2467 | (let* ((python-shell-virtualenv-root | 2475 | (let* ((python-shell-virtualenv-root "/env") |
| 2468 | (directory-file-name user-emacs-directory)) | ||
| 2469 | (process-environment | 2476 | (process-environment |
| 2470 | (python-shell-calculate-process-environment))) | 2477 | (let (process-environment process-environment) |
| 2478 | (setenv "PYTHONHOME" "/home") | ||
| 2479 | (setenv "VIRTUAL_ENV") | ||
| 2480 | (python-shell-calculate-process-environment)))) | ||
| 2471 | (should (not (getenv "PYTHONHOME"))) | 2481 | (should (not (getenv "PYTHONHOME"))) |
| 2472 | (should (string= (getenv "VIRTUAL_ENV") python-shell-virtualenv-root)))) | 2482 | (should (string= (getenv "VIRTUAL_ENV") "/env")))) |
| 2473 | 2483 | ||
| 2474 | (ert-deftest python-shell-calculate-process-environment-4 () | 2484 | (ert-deftest python-shell-calculate-process-environment-4 () |
| 2475 | "Test `python-shell-unbuffered' modification." | 2485 | "Test PYTHONUNBUFFERED when `python-shell-unbuffered' is non-nil." |
| 2476 | (setenv "PYTHONUNBUFFERED") | 2486 | (let* ((python-shell-unbuffered t) |
| 2477 | (let* ((process-environment | 2487 | (process-environment |
| 2478 | (python-shell-calculate-process-environment))) | 2488 | (let ((process-environment process-environment)) |
| 2479 | ;; Defaults to t | 2489 | (setenv "PYTHONUNBUFFERED") |
| 2480 | (should python-shell-unbuffered) | 2490 | (python-shell-calculate-process-environment)))) |
| 2481 | (should (string= (getenv "PYTHONUNBUFFERED") "1")))) | 2491 | (should (string= (getenv "PYTHONUNBUFFERED") "1")))) |
| 2482 | 2492 | ||
| 2483 | (ert-deftest python-shell-calculate-process-environment-5 () | 2493 | (ert-deftest python-shell-calculate-process-environment-5 () |
| 2484 | (setenv "PYTHONUNBUFFERED") | 2494 | "Test PYTHONUNBUFFERED when `python-shell-unbuffered' is nil." |
| 2485 | "Test `python-shell-unbuffered' modification." | ||
| 2486 | (let* ((python-shell-unbuffered nil) | 2495 | (let* ((python-shell-unbuffered nil) |
| 2487 | (process-environment | 2496 | (process-environment |
| 2488 | (python-shell-calculate-process-environment))) | 2497 | (let ((process-environment process-environment)) |
| 2498 | (setenv "PYTHONUNBUFFERED") | ||
| 2499 | (python-shell-calculate-process-environment)))) | ||
| 2489 | (should (not (getenv "PYTHONUNBUFFERED"))))) | 2500 | (should (not (getenv "PYTHONUNBUFFERED"))))) |
| 2490 | 2501 | ||
| 2502 | (ert-deftest python-shell-calculate-process-environment-6 () | ||
| 2503 | "Test PYTHONUNBUFFERED=1 when `python-shell-unbuffered' is nil." | ||
| 2504 | (let* ((python-shell-unbuffered nil) | ||
| 2505 | (process-environment | ||
| 2506 | (let ((process-environment process-environment)) | ||
| 2507 | (setenv "PYTHONUNBUFFERED" "1") | ||
| 2508 | (python-shell-calculate-process-environment)))) | ||
| 2509 | ;; User default settings must remain untouched: | ||
| 2510 | (should (string= (getenv "PYTHONUNBUFFERED") "1")))) | ||
| 2511 | |||
| 2512 | (ert-deftest python-shell-calculate-process-environment-7 () | ||
| 2513 | "Test no side-effects on `process-environment'." | ||
| 2514 | (let* ((python-shell-process-environment | ||
| 2515 | '("TESTVAR1=value1" "TESTVAR2=value2")) | ||
| 2516 | (python-shell-virtualenv-root "/env") | ||
| 2517 | (python-shell-unbuffered t) | ||
| 2518 | (python-shell-extra-pythonpaths'("/path1" "/path2")) | ||
| 2519 | (original-process-environment (copy-sequence process-environment))) | ||
| 2520 | (python-shell-calculate-process-environment) | ||
| 2521 | (should (equal process-environment original-process-environment)))) | ||
| 2522 | |||
| 2523 | (ert-deftest python-shell-calculate-process-environment-8 () | ||
| 2524 | "Test no side-effects on `tramp-remote-process-environment'." | ||
| 2525 | (let* ((default-directory "/ssh::/example/dir/") | ||
| 2526 | (python-shell-process-environment | ||
| 2527 | '("TESTVAR1=value1" "TESTVAR2=value2")) | ||
| 2528 | (python-shell-virtualenv-root "/env") | ||
| 2529 | (python-shell-unbuffered t) | ||
| 2530 | (python-shell-extra-pythonpaths'("/path1" "/path2")) | ||
| 2531 | (original-process-environment | ||
| 2532 | (copy-sequence tramp-remote-process-environment))) | ||
| 2533 | (python-shell-calculate-process-environment) | ||
| 2534 | (should (equal tramp-remote-process-environment original-process-environment)))) | ||
| 2535 | |||
| 2491 | (ert-deftest python-shell-calculate-exec-path-1 () | 2536 | (ert-deftest python-shell-calculate-exec-path-1 () |
| 2492 | "Test `python-shell-exec-path' modification." | 2537 | "Test `python-shell-exec-path' modification." |
| 2493 | (let* ((original-exec-path exec-path) | 2538 | (let* ((exec-path '("/path0")) |
| 2494 | (python-shell-exec-path '("path1" "path2")) | 2539 | (python-shell-exec-path '("/path1" "/path2")) |
| 2495 | (exec-path (python-shell-calculate-exec-path))) | 2540 | (new-exec-path (python-shell-calculate-exec-path))) |
| 2496 | (should (equal | 2541 | (should (equal new-exec-path '("/path1" "/path2" "/path0"))))) |
| 2497 | exec-path | ||
| 2498 | (append python-shell-exec-path | ||
| 2499 | original-exec-path))))) | ||
| 2500 | 2542 | ||
| 2501 | (ert-deftest python-shell-calculate-exec-path-2 () | 2543 | (ert-deftest python-shell-calculate-exec-path-2 () |
| 2502 | "Test `python-shell-virtualenv-root' modification." | 2544 | "Test `python-shell-virtualenv-root' modification." |
| 2503 | (let* ((original-exec-path exec-path) | 2545 | (let* ((exec-path '("/path0")) |
| 2504 | (python-shell-virtualenv-root | 2546 | (python-shell-virtualenv-root "/env") |
| 2505 | (directory-file-name (expand-file-name user-emacs-directory))) | 2547 | (new-exec-path (python-shell-calculate-exec-path))) |
| 2506 | (exec-path (python-shell-calculate-exec-path))) | 2548 | (should (equal new-exec-path '("/env/bin" "/path0"))))) |
| 2507 | (should (equal | 2549 | |
| 2508 | exec-path | 2550 | (ert-deftest python-shell-calculate-exec-path-3 () |
| 2509 | (append (cons | 2551 | "Test complete `python-shell-virtualenv-root' modification." |
| 2510 | (format "%s/bin" python-shell-virtualenv-root) | 2552 | (let* ((exec-path '("/path0")) |
| 2511 | original-exec-path)))))) | 2553 | (python-shell-exec-path '("/path1" "/path2")) |
| 2554 | (python-shell-virtualenv-root "/env") | ||
| 2555 | (new-exec-path (python-shell-calculate-exec-path))) | ||
| 2556 | (should (equal new-exec-path '("/env/bin" "/path1" "/path2" "/path0"))))) | ||
| 2557 | |||
| 2558 | (ert-deftest python-shell-calculate-exec-path-4 () | ||
| 2559 | "Test complete `python-shell-virtualenv-root' with remote." | ||
| 2560 | (let* ((default-directory "/ssh::/example/dir/") | ||
| 2561 | (python-shell-remote-exec-path '("/path0")) | ||
| 2562 | (python-shell-exec-path '("/path1" "/path2")) | ||
| 2563 | (python-shell-virtualenv-root "/env") | ||
| 2564 | (new-exec-path (python-shell-calculate-exec-path))) | ||
| 2565 | (should (equal new-exec-path '("/env/bin" "/path1" "/path2" "/path0"))))) | ||
| 2566 | |||
| 2567 | (ert-deftest python-shell-calculate-exec-path-5 () | ||
| 2568 | "Test no side-effects on `exec-path'." | ||
| 2569 | (let* ((exec-path '("/path0")) | ||
| 2570 | (python-shell-exec-path '("/path1" "/path2")) | ||
| 2571 | (python-shell-virtualenv-root "/env") | ||
| 2572 | (original-exec-path (copy-sequence exec-path))) | ||
| 2573 | (python-shell-calculate-exec-path) | ||
| 2574 | (should (equal exec-path original-exec-path)))) | ||
| 2575 | |||
| 2576 | (ert-deftest python-shell-calculate-exec-path-6 () | ||
| 2577 | "Test no side-effects on `python-shell-remote-exec-path'." | ||
| 2578 | (let* ((default-directory "/ssh::/example/dir/") | ||
| 2579 | (python-shell-remote-exec-path '("/path0")) | ||
| 2580 | (python-shell-exec-path '("/path1" "/path2")) | ||
| 2581 | (python-shell-virtualenv-root "/env") | ||
| 2582 | (original-exec-path (copy-sequence python-shell-remote-exec-path))) | ||
| 2583 | (python-shell-calculate-exec-path) | ||
| 2584 | (should (equal python-shell-remote-exec-path original-exec-path)))) | ||
| 2512 | 2585 | ||
| 2513 | (ert-deftest python-shell-with-environment-1 () | 2586 | (ert-deftest python-shell-with-environment-1 () |
| 2514 | "Test with local `default-directory'." | 2587 | "Test environment with local `default-directory'." |
| 2515 | (let* ((original-exec-path exec-path) | 2588 | (let* ((exec-path '("/path0")) |
| 2516 | (python-shell-virtualenv-root | 2589 | (python-shell-exec-path '("/path1" "/path2")) |
| 2517 | (directory-file-name (expand-file-name user-emacs-directory)))) | 2590 | (original-exec-path exec-path) |
| 2591 | (python-shell-virtualenv-root "/env")) | ||
| 2518 | (python-shell-with-environment | 2592 | (python-shell-with-environment |
| 2519 | (should (equal | 2593 | (should (equal exec-path '("/env/bin" "/path1" "/path2" "/path0"))) |
| 2520 | exec-path | ||
| 2521 | (append (cons | ||
| 2522 | (format "%s/bin" python-shell-virtualenv-root) | ||
| 2523 | original-exec-path)))) | ||
| 2524 | (should (not (getenv "PYTHONHOME"))) | 2594 | (should (not (getenv "PYTHONHOME"))) |
| 2525 | (should (string= (getenv "VIRTUAL_ENV") python-shell-virtualenv-root))))) | 2595 | (should (string= (getenv "VIRTUAL_ENV") "/env"))) |
| 2596 | (should (equal exec-path original-exec-path)))) | ||
| 2526 | 2597 | ||
| 2527 | (ert-deftest python-shell-with-environment-2 () | 2598 | (ert-deftest python-shell-with-environment-2 () |
| 2528 | "Test with remote `default-directory'." | 2599 | "Test environment with remote `default-directory'." |
| 2529 | (let* ((default-directory "/ssh::/example/dir/") | 2600 | (let* ((default-directory "/ssh::/example/dir/") |
| 2530 | (original-exec-path tramp-remote-path) | 2601 | (python-shell-remote-exec-path '("/remote1" "/remote2")) |
| 2531 | (original-process-environment tramp-remote-process-environment) | 2602 | (python-shell-exec-path '("/path1" "/path2")) |
| 2532 | (python-shell-virtualenv-root | 2603 | (tramp-remote-process-environment '("EMACS=t")) |
| 2533 | (directory-file-name (expand-file-name user-emacs-directory)))) | 2604 | (original-process-environment (copy-sequence tramp-remote-process-environment)) |
| 2605 | (python-shell-virtualenv-root "/env")) | ||
| 2534 | (python-shell-with-environment | 2606 | (python-shell-with-environment |
| 2535 | (should (equal | 2607 | (should (equal (python-shell-calculate-exec-path) |
| 2536 | tramp-remote-path | 2608 | '("/env/bin" "/path1" "/path2" "/remote1" "/remote2"))) |
| 2537 | (append (cons | ||
| 2538 | (format "%s/bin" python-shell-virtualenv-root) | ||
| 2539 | original-exec-path)))) | ||
| 2540 | (let ((process-environment tramp-remote-process-environment)) | 2609 | (let ((process-environment tramp-remote-process-environment)) |
| 2541 | (should (not (getenv "PYTHONHOME"))) | 2610 | (should (not (getenv "PYTHONHOME"))) |
| 2542 | (should (string= (getenv "VIRTUAL_ENV") | 2611 | (should (string= (getenv "VIRTUAL_ENV") "/env")))) |
| 2543 | python-shell-virtualenv-root)))))) | 2612 | (should (equal tramp-remote-process-environment original-process-environment)))) |
| 2613 | |||
| 2614 | (ert-deftest python-shell-with-environment-3 () | ||
| 2615 | "Test `python-shell-with-environment' is idempotent." | ||
| 2616 | (let* ((python-shell-extra-pythonpaths '("/example/dir/")) | ||
| 2617 | (python-shell-exec-path '("path1" "path2")) | ||
| 2618 | (python-shell-virtualenv-root "/home/user/env") | ||
| 2619 | (single-call | ||
| 2620 | (python-shell-with-environment | ||
| 2621 | (list exec-path process-environment))) | ||
| 2622 | (nested-call | ||
| 2623 | (python-shell-with-environment | ||
| 2624 | (python-shell-with-environment | ||
| 2625 | (list exec-path process-environment))))) | ||
| 2626 | (should (equal single-call nested-call)))) | ||
| 2544 | 2627 | ||
| 2545 | (ert-deftest python-shell-make-comint-1 () | 2628 | (ert-deftest python-shell-make-comint-1 () |
| 2546 | "Check comint creation for global shell buffer." | 2629 | "Check comint creation for global shell buffer." |