test-ob-python.el 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. ;;; test-ob-python.el --- tests for ob-python.el
  2. ;; Copyright (c) 2011-2014 Eric Schulte
  3. ;; Authors: Eric Schulte
  4. ;; This file is not part of GNU Emacs.
  5. ;; This program 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. ;; This program is distributed in the hope that it will be useful,
  10. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. ;; GNU General Public License for more details.
  13. ;; You should have received a copy of the GNU General Public License
  14. ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. ;;; Code:
  16. (org-test-for-executable "python")
  17. (unless (featurep 'ob-python)
  18. (signal 'missing-test-dependency "Support for Python code blocks"))
  19. (ert-deftest test-ob-python/colnames-yes-header-argument ()
  20. (org-test-with-temp-text "#+name: eg
  21. | col |
  22. |-----|
  23. | a |
  24. | b |
  25. #+header: :colnames yes
  26. #+header: :var x = eg
  27. #+begin_src python
  28. return x
  29. #+end_src"
  30. (org-babel-next-src-block)
  31. (should (equal '(("col") hline ("a") ("b"))
  32. (org-babel-execute-src-block)))))
  33. (ert-deftest test-ob-python/colnames-yes-header-argument-again ()
  34. (org-test-with-temp-text "#+name: less-cols
  35. | a |
  36. |---|
  37. | b |
  38. | c |
  39. #+header: :colnames yes
  40. #+begin_src python :var tab=less-cols
  41. return [[val + '*' for val in row] for row in tab]
  42. #+end_src"
  43. (org-babel-next-src-block)
  44. (should (equal '(("a") hline ("b*") ("c*"))
  45. (org-babel-execute-src-block)))))
  46. (ert-deftest test-ob-python/colnames-nil-header-argument ()
  47. (org-test-with-temp-text "#+name: eg
  48. | col |
  49. |-----|
  50. | a |
  51. | b |
  52. #+header: :colnames nil
  53. #+header: :var x = eg
  54. #+begin_src python
  55. return x
  56. #+end_src"
  57. (org-babel-next-src-block)
  58. (should (equal '(("col") hline ("a") ("b"))
  59. (org-babel-execute-src-block)))))
  60. (ert-deftest test-ob-python/colnames-no-header-argument-again ()
  61. (org-test-with-temp-text "#+name: less-cols
  62. | a |
  63. |---|
  64. | b |
  65. | c |
  66. #+header: :colnames no
  67. #+begin_src python :var tab=less-cols
  68. return [[val + '*' for val in row] for row in tab]
  69. #+end_src"
  70. (org-babel-next-src-block)
  71. (should (equal '(("a*") ("b*") ("c*"))
  72. (org-babel-execute-src-block)))))
  73. (ert-deftest test-ob-python/colnames-no-header-argument ()
  74. (org-test-with-temp-text "#+name: eg
  75. | col |
  76. |-----|
  77. | a |
  78. | b |
  79. #+header: :colnames no
  80. #+header: :var x = eg
  81. #+begin_src python
  82. return x
  83. #+end_src"
  84. (org-babel-next-src-block)
  85. (should (equal '(("col") ("a") ("b"))
  86. (org-babel-execute-src-block)))))
  87. (ert-deftest test-ob-python/session-multiline ()
  88. ;; FIXME workaround to prevent starting prompt leaking into output
  89. (run-python)
  90. (sleep-for 0 10)
  91. (org-test-with-temp-text "
  92. #+begin_src python :session :results output
  93. foo = 0
  94. for _ in range(10):
  95. foo += 1
  96. foo += 1
  97. print(foo)
  98. #+end_src"
  99. (org-babel-next-src-block)
  100. (should (equal "20" (org-babel-execute-src-block)))))
  101. (provide 'test-ob-python)
  102. ;;; test-ob-python.el ends here