diff options
| author | Craig Jennings <c@cjennings.net> | 2026-06-25 16:03:18 -0400 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-06-25 16:03:18 -0400 |
| commit | 7027cccea9eb7170ea0f08e1def3f979f2e59932 (patch) | |
| tree | 51752f8cac0d92b4442048d913272e923211b619 /tests/test-wttrin--format-location-line.el | |
| parent | 33621b5a6e5407da190767b89756e287698ef234 (diff) | |
| download | emacs-wttrin-7027cccea9eb7170ea0f08e1def3f979f2e59932.tar.gz emacs-wttrin-7027cccea9eb7170ea0f08e1def3f979f2e59932.zip | |
feat: add external-command geolocation, opt-out, and example adapters
These build on the current-location picker with the rest of the geolocation work.
wttrin-geolocation-command runs a command that prints {lat,lng} (and optionally an address) and queries wttr.in by those coordinates. IP geolocation only finds the network's exit point, which is wrong on a VPN or hotspot. A command that scans nearby WiFi resolves to street level. It runs asynchronously, falls back to the IP provider when unset or failing, and assumes nothing about the OS, so it's inert until set. When the command returns an address, wttrin shows it on a "Location:" line, so the resolved place is readable even though the fetch is by raw coordinates.
wttrin-use-current-location is a labeled command that sets the favorite to auto-detect, so the bare t value never has to be typed into init by hand.
wttrin-geolocation-enabled (default t) turns every geolocation surface off for anyone who wants that: the picker entry, the auto-detect favorite, and the command.
examples/geolocation/ ships two reference adapters for the command: google-geolocate.py (Google API, key via the environment or ~/.authinfo.gpg) and apple-wps.py (Apple's keyless WiFi positioning, which uses an undocumented endpoint, so read its caveat). Both are Python 3 standard library and scan via nmcli, with notes on adapting the scan to other systems.
Diffstat (limited to 'tests/test-wttrin--format-location-line.el')
| -rw-r--r-- | tests/test-wttrin--format-location-line.el | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/tests/test-wttrin--format-location-line.el b/tests/test-wttrin--format-location-line.el new file mode 100644 index 0000000..28a9af8 --- /dev/null +++ b/tests/test-wttrin--format-location-line.el @@ -0,0 +1,35 @@ +;;; test-wttrin--format-location-line.el --- Tests for the buffer Location line -*- lexical-binding: t; -*- + +;; Copyright (C) 2024-2026 Craig Jennings + +;;; Commentary: +;; Unit tests for `wttrin--format-location-line', the "Location: ADDRESS" line +;; shown in the weather buffer when a geolocation command supplies an address. + +;;; Code: + +(require 'ert) +(require 'wttrin) + +(ert-deftest test-wttrin--format-location-line-normal-builds-line () + "Normal: a non-empty address becomes a \"Location: ...\" line." + (let ((line (wttrin--format-location-line "Westerly, Rhode Island, USA"))) + (should (stringp line)) + (should (string-prefix-p "Location: Westerly, Rhode Island, USA" line)))) + +(ert-deftest test-wttrin--format-location-line-normal-uses-face () + "Normal: the line carries the staleness-header face." + (let ((line (wttrin--format-location-line "Westerly, RI"))) + (should (eq 'wttrin-staleness-header + (get-text-property 0 'face line))))) + +(ert-deftest test-wttrin--format-location-line-boundary-nil-returns-nil () + "Boundary: a nil address yields no line." + (should (null (wttrin--format-location-line nil)))) + +(ert-deftest test-wttrin--format-location-line-boundary-empty-returns-nil () + "Boundary: an empty address yields no line." + (should (null (wttrin--format-location-line "")))) + +(provide 'test-wttrin--format-location-line) +;;; test-wttrin--format-location-line.el ends here |
