diff options
author | Holger Dürer <me@hdurer.net> | 2021-11-01 15:53:37 +0100 |
---|---|---|
committer | Holger Dürer <me@hdurer.net> | 2021-11-01 15:53:37 +0100 |
commit | e7c7da386c812f9452b072567e822077180f3dc5 (patch) | |
tree | cfd28454b3c54404381620a1e77e722b6d5e9740 | |
parent | d7593a06912b7946d2fb318093ec7e27c64b3be7 (diff) |
Fix tests.
These needed a bit of tender love and care to get back into passing
state.
- Move the auth tests to the `test` directory. No idea what it was
doing in `lisp`.
- Image tests are mostly broken because with later Emacsen we no
longer need the `imagemagic` option on create-image.
- Some method signatures have changed and mocking calls needed to
follow suit.
-rw-r--r-- | Cask | 1 | ||||
-rw-r--r-- | lisp/mastodon-http.el | 16 | ||||
-rw-r--r-- | lisp/mastodon-profile.el | 2 | ||||
-rw-r--r-- | lisp/mastodon-tl.el | 2 | ||||
-rw-r--r-- | lisp/mastodon.el | 2 | ||||
-rw-r--r-- | test/ert-helper.el | 11 | ||||
-rw-r--r-- | test/mastodon-auth-test.el (renamed from lisp/mastodon-auth--test.el) | 0 | ||||
-rw-r--r-- | test/mastodon-http-tests.el | 2 | ||||
-rw-r--r-- | test/mastodon-media-tests.el | 34 | ||||
-rw-r--r-- | test/mastodon-notifications-test.el | 2 | ||||
-rw-r--r-- | test/mastodon-tl-tests.el | 6 |
11 files changed, 52 insertions, 26 deletions
@@ -4,6 +4,7 @@ (package-file "lisp/mastodon.el") (files "lisp/*.el") +(depends-on "request") (depends-on "seq") (development diff --git a/lisp/mastodon-http.el b/lisp/mastodon-http.el index 27f8ef0..875e9bf 100644 --- a/lisp/mastodon-http.el +++ b/lisp/mastodon-http.el @@ -3,7 +3,7 @@ ;; Copyright (C) 2017-2019 Johnson Denen ;; Author: Johnson Denen <johnson.denen@gmail.com> ;; Version: 0.9.1 -;; Package-Requires: ((emacs "26.1") (request "0.2.0")) +;; Package-Requires: ((emacs "27.1") (request "0.2.0")) ;; Homepage: https://github.com/jdenen/mastodon.el ;; This file is not part of GNU Emacs. @@ -127,9 +127,17 @@ Pass response buffer to CALLBACK function." (url-request-extra-headers `(("Authorization" . ,(concat "Bearer " (mastodon-auth--access-token)))))) - (if (< (cdr (func-arity 'url-retrieve-synchronously)) 4) - (url-retrieve-synchronously url) - (url-retrieve-synchronously url nil nil mastodon-http--timeout)))) + (mastodon-http--url-retrieve-synchronously url))) + +(defun mastodon-http--url-retrieve-synchronously (url) + "Retrieve URL asynchronously. + +This is a thin abstraction over the system +`url-retrieve-synchronously`. Depending on which version of this +is available we will call it with or without a timeout." + (if (< (cdr (func-arity 'url-retrieve-synchronously)) 4) + (url-retrieve-synchronously url) + (url-retrieve-synchronously url nil nil mastodon-http--timeout))) (defun mastodon-http--get-json (url) "Make synchronous GET request to URL. Return JSON response." diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index 22120fe..018af21 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -3,7 +3,7 @@ ;; Copyright (C) 2017-2019 Johnson Denen ;; Author: Johnson Denen <johnson.denen@gmail.com> ;; Version: 0.9.1 -;; Package-Requires: ((emacs "26.1") (seq "1.8")) +;; Package-Requires: ((emacs "26.1") (seq "1.0")) ;; Homepage: https://github.com/jdenen/mastodon.el ;; This file is not part of GNU Emacs. diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index e5ded3f..3cb4ccb 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -1321,7 +1321,7 @@ JSON is the data returned from the server." (defun mastodon-tl--init-sync (buffer-name endpoint update-function) "Initialize BUFFER-NAME with timeline targeted by ENDPOINT. -UPDATE-FUNCTION is used to recieve more toots. +UPDATE-FUNCTION is used to receive more toots. Runs synchronously." (let* ((url (mastodon-http--api endpoint)) (buffer (concat "*mastodon-" buffer-name "*")) diff --git a/lisp/mastodon.el b/lisp/mastodon.el index 159b9b2..d405bed 100644 --- a/lisp/mastodon.el +++ b/lisp/mastodon.el @@ -3,7 +3,7 @@ ;; Copyright (C) 2017-2019 Johnson Denen ;; Author: Johnson Denen <johnson.denen@gmail.com> ;; Version: 0.9.1 -;; Package-Requires: ((emacs "26.1") (request "0.2.0") (seq "1.8")) +;; Package-Requires: ((emacs "26.1") (request "0.3.2") (seq "1.0")) ;; Homepage: https://github.com/jdenen/mastodon.el ;; This file is not part of GNU Emacs. diff --git a/test/ert-helper.el b/test/ert-helper.el index 6979837..d3e0016 100644 --- a/test/ert-helper.el +++ b/test/ert-helper.el @@ -1,8 +1,13 @@ +(load-file "lisp/mastodon-async.el") (load-file "lisp/mastodon-http.el") -(load-file "lisp/mastodon-client.el") (load-file "lisp/mastodon-auth.el") -(load-file "lisp/mastodon-toot.el") +(load-file "lisp/mastodon-client.el") +(load-file "lisp/mastodon-discover.el") +(load-file "lisp/mastodon-inspect.el") (load-file "lisp/mastodon-media.el") -(load-file "lisp/mastodon-tl.el") (load-file "lisp/mastodon-notifications.el") +(load-file "lisp/mastodon-profile.el") +(load-file "lisp/mastodon-search.el") +(load-file "lisp/mastodon-tl.el") +(load-file "lisp/mastodon-toot.el") (load-file "lisp/mastodon.el") diff --git a/lisp/mastodon-auth--test.el b/test/mastodon-auth-test.el index 9a765b9..9a765b9 100644 --- a/lisp/mastodon-auth--test.el +++ b/test/mastodon-auth-test.el diff --git a/test/mastodon-http-tests.el b/test/mastodon-http-tests.el index 972cedb..d0f715e 100644 --- a/test/mastodon-http-tests.el +++ b/test/mastodon-http-tests.el @@ -4,6 +4,6 @@ "Should make a `url-retrieve' of the given URL." (let ((callback-double (lambda () "double"))) (with-mock - (mock (url-retrieve-synchronously "https://foo.bar/baz")) + (mock (mastodon-http--url-retrieve-synchronously "https://foo.bar/baz")) (mock (mastodon-auth--access-token) => "test-token") (mastodon-http--get "https://foo.bar/baz")))) diff --git a/test/mastodon-media-tests.el b/test/mastodon-media-tests.el index a586be9..20993f9 100644 --- a/test/mastodon-media-tests.el +++ b/test/mastodon-media-tests.el @@ -4,7 +4,7 @@ "Should return text with all expected properties." (with-mock (mock (image-type-available-p 'imagemagick) => t) - (mock (create-image * 'imagemagick t :height 123) => :mock-image) + (mock (create-image * (when (version< emacs-version "27.1") 'imagemagick) t :height 123) => :mock-image) (let* ((mastodon-media--avatar-height 123) (result (mastodon-media--get-avatar-rendering "http://example.org/img.png")) @@ -37,12 +37,15 @@ (mastodon-media--avatar-height 123)) (with-mock (mock (image-type-available-p 'imagemagick) => t) - (mock (create-image * 'imagemagick t :height 123) => '(image foo)) + (mock (create-image + * + (when (version< emacs-version "27.1") 'imagemagick) + t :height 123) => '(image foo)) (mock (copy-marker 7) => :my-marker ) (mock (url-retrieve url #'mastodon-media--process-image-response - '(:my-marker (:height 123) 1)) + `(:my-marker (:height 123) 1 ,url)) => :called-as-expected) (with-temp-buffer @@ -62,7 +65,7 @@ (mock (url-retrieve url #'mastodon-media--process-image-response - '(:my-marker () 1)) + `(:my-marker () 1 ,url)) => :called-as-expected) (with-temp-buffer @@ -82,7 +85,7 @@ (mock (url-retrieve "http://example.org/image.png" #'mastodon-media--process-image-response - '(:my-marker (:max-height 321) 5)) + '(:my-marker (:max-height 321) 5 "http://example.org/image.png")) => :called-as-expected) (with-temp-buffer (insert (concat "Start:" @@ -101,7 +104,7 @@ (mock (url-retrieve "http://example.org/image.png" #'mastodon-media--process-image-response - '(:my-marker () 5)) + '(:my-marker () 5 "http://example.org/image.png")) => :called-as-expected) (with-temp-buffer @@ -117,7 +120,10 @@ (mastodon-media--avatar-height 123)) (with-mock (mock (image-type-available-p 'imagemagick) => t) - (mock (create-image * 'imagemagick t :height 123) => '(image foo)) + (mock (create-image + * + (when (version< emacs-version "27.1") 'imagemagick) + t :height 123) => '(image foo)) (stub url-retrieve => (error "url-retrieve failed")) (with-temp-buffer @@ -139,9 +145,11 @@ (insert "start:") (setq used-marker (copy-marker (point)) saved-marker (copy-marker (point))) - ;; Mock needed for the preliminary image created in mastodon-media--get-avatar-rendering + ;; Mock needed for the preliminary image created in + ;; mastodon-media--get-avatar-rendering (stub create-image => :fake-image) - (insert (mastodon-media--get-avatar-rendering "http://example.org/image.png") + (insert (mastodon-media--get-avatar-rendering + "http://example.org/image.png.") ":end") (with-temp-buffer (insert "some irrelevant\n" @@ -150,9 +158,13 @@ "fake\nimage\ndata") (goto-char (point-min)) - (mock (create-image "fake\nimage\ndata" 'imagemagick t ':image :option) => :fake-image) + (mock (create-image + "fake\nimage\ndata" + (when (version< emacs-version "27.1") 'imagemagick) + t ':image :option) => :fake-image) - (mastodon-media--process-image-response () used-marker '(:image :option) 1) + (mastodon-media--process-image-response + () used-marker '(:image :option) 1 "http://example.org/image.png") ;; the used marker has been unset: (should (null (marker-position used-marker))) diff --git a/test/mastodon-notifications-test.el b/test/mastodon-notifications-test.el index 19b591d..778d350 100644 --- a/test/mastodon-notifications-test.el +++ b/test/mastodon-notifications-test.el @@ -185,7 +185,7 @@ "Ensure get request format for notifictions is accurate." (let ((mastodon-instance-url "https://instance.url")) (with-mock - (mock (mastodon-http--get-json-async "https://instance.url/api/v1/notifications" 'mastodon-tl--init* "*mastodon-notifications*" "notifications" 'mastodon-notifications--timeline)) + (mock (mastodon-http--get-json "https://instance.url/api/v1/notifications" )) (mastodon-notifications--get)))) (defun mastodon-notifications--test-type (fun sample) diff --git a/test/mastodon-tl-tests.el b/test/mastodon-tl-tests.el index c7dfc9a..24de5d0 100644 --- a/test/mastodon-tl-tests.el +++ b/test/mastodon-tl-tests.el @@ -285,7 +285,7 @@ a string or a numeric." (mastodon-tl--byline mastodon-tl-test-base-toot 'mastodon-tl--byline-author 'mastodon-tl--byline-boosted)) - " Account 42 (@acct42@example.space) 2999-99-99 00:11:22 + "Account 42 (@acct42@example.space) 2999-99-99 00:11:22 ------------ "))))) @@ -395,8 +395,8 @@ a string or a numeric." (mastodon-tl--byline toot 'mastodon-tl--byline-author 'mastodon-tl--byline-boosted)) - " Account 42 (@acct42@example.space) - Boosted Account 43 (@acct43@example.space) original time + "Account 42 (@acct42@example.space) + Boosted Account 43 (@acct43@example.space) original time ------------ "))))) |