test-ein-core.el 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. (eval-when-compile (require 'cl))
  2. (require 'ert)
  3. (require 'ein-core)
  4. ;;; `ein:version'
  5. (ert-deftest ein:version ()
  6. "Check if `ein:version' can be parsed by `version-to-list'."
  7. (version-to-list ein:version))
  8. (ert-deftest ein:version-func-prefix-is-the-variable ()
  9. (should (string-prefix-p ein:version (ein:version)))
  10. (let ((default-directory "/tmp/"))
  11. (should (string-prefix-p ein:version (ein:version)))))
  12. (ert-deftest ein:version-func-outside-of-git-repo ()
  13. (flet ((ein:git-root-p (dir) nil))
  14. (should (equal (ein:version) ein:version)))
  15. (flet ((ein:git-revision-dirty () nil))
  16. (should (equal (ein:version) ein:version))))
  17. ;; Generic getter
  18. (defmacro eintest:generic-getter-should-return-nil (func)
  19. "In an \"empty\" context, generic getter should return nil."
  20. `(ert-deftest ,(intern (format "%s--nil name" func)) ()
  21. (with-temp-buffer
  22. (should (not (,func))))))
  23. (eintest:generic-getter-should-return-nil ein:get-url-or-port)
  24. (eintest:generic-getter-should-return-nil ein:get-notebook)
  25. (eintest:generic-getter-should-return-nil ein:get-kernel)
  26. (eintest:generic-getter-should-return-nil ein:get-cell-at-point)
  27. (eintest:generic-getter-should-return-nil ein:get-traceback-data)
  28. ;;; File name translation
  29. ;; Requiring `tramp' during (inside of) tests yields error from
  30. ;; MuMaMo. Although I don't understand the reason, requiring it
  31. ;; before running tests workarounds this problem.
  32. (require 'tramp)
  33. (ert-deftest ein:filename-translations-from-to-tramp ()
  34. (loop with ein:filename-translations =
  35. `((8888 . ,(ein:tramp-create-filename-translator "HOST" "USER")))
  36. with filename = "/file/name"
  37. for port in '(7777 8888) ; check for the one w/o translation
  38. for emacs-filename = (ein:filename-from-python port filename)
  39. do (message "emacs-filename = %s" emacs-filename)
  40. do (should
  41. (equal (ein:filename-to-python port emacs-filename)
  42. filename))))
  43. (ert-deftest ein:filename-translations-to-from-tramp ()
  44. (loop with ein:filename-translations =
  45. `((8888 . ,(ein:tramp-create-filename-translator "HOST" "USER")))
  46. with filename = "/USER@HOST:/filename"
  47. for port in '(8888)
  48. do (should
  49. (equal (ein:filename-from-python
  50. port (ein:filename-to-python port filename))
  51. filename))))
  52. (ert-deftest ein:filename-to-python-tramp ()
  53. (let* ((port 8888)
  54. (ein:filename-translations
  55. `((,port . ,(ein:tramp-create-filename-translator "DUMMY")))))
  56. (loop with python-filename = "/file/name"
  57. for emacs-filename in '("/scpc:HOST:/file/name"
  58. "/USER@HOST:/file/name")
  59. do (should
  60. (equal (ein:filename-to-python port emacs-filename)
  61. python-filename)))
  62. ;; Error: Not a Tramp file name: /file/name
  63. (should-error (ein:filename-to-python port "/file/name"))))
  64. (ert-deftest ein:filename-from-python-tramp ()
  65. (loop with ein:filename-translations =
  66. `((8888 . ,(ein:tramp-create-filename-translator "HOST" "USER")))
  67. with python-filename = "/file/name"
  68. for emacs-filename in '("/USER@HOST:/file/name" "/file/name")
  69. for port in '(8888 7777)
  70. do (should
  71. (equal (ein:filename-from-python port python-filename)
  72. emacs-filename))))