nocturne-shift 2.0.0__tar.gz → 2.0.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. {nocturne_shift-2.0.0/src/nocturne_shift.egg-info → nocturne_shift-2.0.2}/PKG-INFO +3 -2
  2. {nocturne_shift-2.0.0 → nocturne_shift-2.0.2}/README.md +2 -1
  3. {nocturne_shift-2.0.0 → nocturne_shift-2.0.2}/pyproject.toml +1 -1
  4. {nocturne_shift-2.0.0 → nocturne_shift-2.0.2}/src/nocturne_shift/bin/get_sunrise_sunset.py +28 -27
  5. {nocturne_shift-2.0.0 → nocturne_shift-2.0.2}/src/nocturne_shift/bin/is_day_or_night.py +7 -10
  6. {nocturne_shift-2.0.0 → nocturne_shift-2.0.2}/src/nocturne_shift/bin/settings.py +5 -3
  7. {nocturne_shift-2.0.0 → nocturne_shift-2.0.2}/src/nocturne_shift/cli.py +13 -10
  8. {nocturne_shift-2.0.0 → nocturne_shift-2.0.2}/src/nocturne_shift/data_store.py +8 -10
  9. {nocturne_shift-2.0.0 → nocturne_shift-2.0.2/src/nocturne_shift.egg-info}/PKG-INFO +3 -2
  10. nocturne_shift-2.0.2/src/nocturne_shift.egg-info/scm_version.json +8 -0
  11. {nocturne_shift-2.0.0 → nocturne_shift-2.0.2}/tests/test_cli.py +10 -5
  12. {nocturne_shift-2.0.0 → nocturne_shift-2.0.2}/tests/test_data_store.py +6 -6
  13. {nocturne_shift-2.0.0 → nocturne_shift-2.0.2}/tests/test_get_sunrise_sunset.py +42 -25
  14. {nocturne_shift-2.0.0 → nocturne_shift-2.0.2}/tests/test_is_day_or_night.py +2 -2
  15. {nocturne_shift-2.0.0 → nocturne_shift-2.0.2}/tests/test_plugins.py +12 -10
  16. {nocturne_shift-2.0.0 → nocturne_shift-2.0.2}/tests/test_settings.py +2 -2
  17. nocturne_shift-2.0.0/src/nocturne_shift.egg-info/scm_version.json +0 -8
  18. {nocturne_shift-2.0.0 → nocturne_shift-2.0.2}/.claude/skills/pytest-review/SKILL.md +0 -0
  19. {nocturne_shift-2.0.0 → nocturne_shift-2.0.2}/.claude/skills/pytest-review/references/mock-pitfalls.md +0 -0
  20. {nocturne_shift-2.0.0 → nocturne_shift-2.0.2}/.claude/skills/pytest-review/references/pytest-rosetta.md +0 -0
  21. {nocturne_shift-2.0.0 → nocturne_shift-2.0.2}/.claude/skills/pytest-review/scripts/mutation_check.py +0 -0
  22. {nocturne_shift-2.0.0 → nocturne_shift-2.0.2}/.github/workflows/publish-pypi.yml +0 -0
  23. {nocturne_shift-2.0.0 → nocturne_shift-2.0.2}/.github/workflows/publish-testpypi.yml +0 -0
  24. {nocturne_shift-2.0.0 → nocturne_shift-2.0.2}/.github/workflows/test.yml +0 -0
  25. {nocturne_shift-2.0.0 → nocturne_shift-2.0.2}/.gitignore +0 -0
  26. {nocturne_shift-2.0.0 → nocturne_shift-2.0.2}/LICENSE +0 -0
  27. {nocturne_shift-2.0.0 → nocturne_shift-2.0.2}/Makefile +0 -0
  28. {nocturne_shift-2.0.0 → nocturne_shift-2.0.2}/docs/README.md +0 -0
  29. {nocturne_shift-2.0.0 → nocturne_shift-2.0.2}/pytest.ini +0 -0
  30. {nocturne_shift-2.0.0 → nocturne_shift-2.0.2}/setup.cfg +0 -0
  31. {nocturne_shift-2.0.0 → nocturne_shift-2.0.2}/src/nocturne_shift/__init__.py +0 -0
  32. {nocturne_shift-2.0.0 → nocturne_shift-2.0.2}/src/nocturne_shift/schemas/com.github.christophermca.night-shift.gschema.xml +0 -0
  33. {nocturne_shift-2.0.0 → nocturne_shift-2.0.2}/src/nocturne_shift/schemas/gschemas.compiled +0 -0
  34. {nocturne_shift-2.0.0 → nocturne_shift-2.0.2}/src/nocturne_shift.egg-info/SOURCES.txt +0 -0
  35. {nocturne_shift-2.0.0 → nocturne_shift-2.0.2}/src/nocturne_shift.egg-info/dependency_links.txt +0 -0
  36. {nocturne_shift-2.0.0 → nocturne_shift-2.0.2}/src/nocturne_shift.egg-info/entry_points.txt +0 -0
  37. {nocturne_shift-2.0.0 → nocturne_shift-2.0.2}/src/nocturne_shift.egg-info/requires.txt +0 -0
  38. {nocturne_shift-2.0.0 → nocturne_shift-2.0.2}/src/nocturne_shift.egg-info/scm_file_list.json +0 -0
  39. {nocturne_shift-2.0.0 → nocturne_shift-2.0.2}/src/nocturne_shift.egg-info/top_level.txt +0 -0
  40. {nocturne_shift-2.0.0 → nocturne_shift-2.0.2}/tests/.gitignore +0 -0
  41. {nocturne_shift-2.0.0 → nocturne_shift-2.0.2}/tests/conftest.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: nocturne-shift
3
- Version: 2.0.0
3
+ Version: 2.0.2
4
4
  Summary: Shift between light and dark with the sun: sunrise/sunset times and day or night
5
5
  Author-email: Christopher McAdams <mca.christopher@gmail.com>
6
6
  License-Expression: MIT
@@ -32,7 +32,6 @@ Nocturne Shift will lookup the time of the sunrise and sunset for the provided l
32
32
  - `nocturne-shift` can also check if the current state of the 24hr period is day or night
33
33
  - `nocturne-shift services`: systemd timers (with `gnome-night-shift`)
34
34
 
35
-
36
35
  ## Features
37
36
 
38
37
  * Use geoclue to determine location. Requires Location services to be enabled. **(Settings > Privacy & Security > Location > Enable "Automatic Device Location"**
@@ -108,3 +107,5 @@ options:
108
107
  [![Publish to PyPI](https://github.com/christophermca/nocturne-shift/actions/workflows/publish-pypi.yml/badge.svg?branch=dev)](https://github.com/christophermca/nocturne-shift/actions/workflows/publish-pypi.yml)
109
108
 
110
109
  [![Publish to TestPyPI](https://github.com/christophermca/nocturne-shift/actions/workflows/publish-testpypi.yml/badge.svg?branch=dev&event=workflow_dispatch)](https://github.com/christophermca/nocturne-shift/actions/workflows/publish-testpypi.yml)
110
+
111
+ [![PyPI](https://img.shields.io/pypi/v/nocturne-shift)](https://pypi.org/project/nocturne-shift/)
@@ -5,7 +5,6 @@ Nocturne Shift will lookup the time of the sunrise and sunset for the provided l
5
5
  - `nocturne-shift` can also check if the current state of the 24hr period is day or night
6
6
  - `nocturne-shift services`: systemd timers (with `gnome-night-shift`)
7
7
 
8
-
9
8
  ## Features
10
9
 
11
10
  * Use geoclue to determine location. Requires Location services to be enabled. **(Settings > Privacy & Security > Location > Enable "Automatic Device Location"**
@@ -81,3 +80,5 @@ options:
81
80
  [![Publish to PyPI](https://github.com/christophermca/nocturne-shift/actions/workflows/publish-pypi.yml/badge.svg?branch=dev)](https://github.com/christophermca/nocturne-shift/actions/workflows/publish-pypi.yml)
82
81
 
83
82
  [![Publish to TestPyPI](https://github.com/christophermca/nocturne-shift/actions/workflows/publish-testpypi.yml/badge.svg?branch=dev&event=workflow_dispatch)](https://github.com/christophermca/nocturne-shift/actions/workflows/publish-testpypi.yml)
83
+
84
+ [![PyPI](https://img.shields.io/pypi/v/nocturne-shift)](https://pypi.org/project/nocturne-shift/)
@@ -53,7 +53,7 @@ test = [
53
53
  ]
54
54
 
55
55
  [tool.setuptools_scm]
56
- # Only tags like cli-v0.4.3 count for this package
56
+ # Only tags like vX.Y.Z count for this package
57
57
  tag_regex = '^v(?P<version>\d+\.\d+\.\d+)$'
58
58
  git_describe_command = "git describe --dirty --tags --long --match 'v[0-9]*'"
59
59
  local_scheme = "no-local-version" # PyPI/TestPyPI reject the "+g1a2b3c" suffix
@@ -2,13 +2,12 @@
2
2
 
3
3
  import re
4
4
  import gi
5
- import sys
6
5
  import pprint
7
6
  import json
8
- import argparse
9
7
  import subprocess
10
8
  import requests
11
9
  import threading
10
+ import logging
12
11
 
13
12
  from zoneinfo import ZoneInfo
14
13
  from collections import namedtuple
@@ -24,6 +23,7 @@ from gi.repository import GLib
24
23
  NOAA = "https://api.sunrise-sunset.org/v2"
25
24
  TIME_THRESHOLD = 3
26
25
  GEOCLUE_TIMEOUT = 30
26
+ log = logging.getLogger(__name__)
27
27
 
28
28
 
29
29
  class AccuracyLevel(IntEnum):
@@ -166,10 +166,6 @@ class GetTimeOfSunriseSunset:
166
166
  previous_coordinates = self.settings.get(
167
167
  "last-known-coordinates"
168
168
  )
169
- try:
170
- previous_coordinates
171
- except Exception as e:
172
- print(f"{e}")
173
169
 
174
170
  # CHECK if should save?
175
171
  if self.override or (list(coords) != previous_coordinates):
@@ -181,14 +177,15 @@ class GetTimeOfSunriseSunset:
181
177
  return coords
182
178
 
183
179
  except subprocess.TimeoutExpired as e:
184
- print(
185
- f"nocturne-shift: geoclue gave no location within {e.timeout} seconds",
186
- file=sys.stderr,
180
+ log.warning(
181
+ "geoclue gave no location within %s seconds", e.timeout
187
182
  )
188
183
  return None
189
184
 
190
185
  except subprocess.CalledProcessError as e:
191
- print(f"Error: {e.returncode} \n\n {e.stderr}")
186
+ log.error(
187
+ "where-am-i failed (exit %s): %s", e.returncode, e.stderr
188
+ )
192
189
  return None
193
190
 
194
191
  finally:
@@ -198,8 +195,8 @@ class GetTimeOfSunriseSunset:
198
195
  self.agent.wait() # Prevents zombie processes
199
196
  self.agent = None
200
197
 
201
- except Exception as e:
202
- print(f"Error: ___{e}")
198
+ except Exception:
199
+ log.exception("stopping geoclue agent failed")
203
200
 
204
201
  def _get_sunrise_sunset(
205
202
  self, lat: float, lng: float, verbose: int
@@ -251,20 +248,23 @@ class GetTimeOfSunriseSunset:
251
248
  return times
252
249
 
253
250
  except requests.exceptions.HTTPError as http_err:
254
- # Only the status: str(http_err) includes the URL, with lat/lng.
251
+ # Only the status: the exception's text includes the URL, with lat/lng.
255
252
  # getattr: an HTTPError raised without a response has .response None
256
253
  status = getattr(http_err.response, "status_code", "no response")
257
- print(f"HTTP error occurred (e.g., 404, 500): {status}")
258
- except (
259
- Exception
260
- ) as e: # Generic Exception must go last becuase it will catch any exception
261
- print(type(e).__name__)
254
+ log.error("fetching sunrise/sunset times failed: HTTP %s", status)
255
+ except requests.exceptions.RequestException as e:
256
+ # Connection errors, timeouts...: their text includes the URL too
257
+ log.error(
258
+ "fetching sunrise/sunset times failed: %s", type(e).__name__
259
+ )
260
+ except Exception:
261
+ # Anything else is a bug here: keep the traceback
262
+ log.exception("fetching sunrise/sunset times failed")
262
263
 
263
264
  def _save(self, data) -> None:
264
265
  if self.settings is None:
265
- print(
266
- f"nocturne-shift: unable to save {', '.join(data)}: settings unavailable",
267
- file=sys.stderr,
266
+ log.error(
267
+ "unable to save %s: settings unavailable", ", ".join(data)
268
268
  )
269
269
  return
270
270
 
@@ -276,15 +276,14 @@ class GetTimeOfSunriseSunset:
276
276
  if self.verbose > 0:
277
277
  pprint.pprint(data)
278
278
 
279
- except Exception as e:
280
- print(f"ERROR SAVING: {e}", file=sys.stderr)
279
+ except Exception:
280
+ log.exception("saving %s failed", ", ".join(data))
281
281
 
282
282
  def _get_static_location_from_settings(self) -> tuple[float, float]:
283
283
 
284
284
  if self.settings is None:
285
- print(
286
- "nocturne-shift: no static location: self.settings unavailable",
287
- file=sys.stderr,
285
+ log.error(
286
+ "no static location: settings unavailable",
288
287
  )
289
288
  return None
290
289
 
@@ -300,4 +299,6 @@ class GetTimeOfSunriseSunset:
300
299
  return static_location
301
300
 
302
301
  else:
303
- print("Missing required keys")
302
+ log.warning(
303
+ "no static location set: latitude or longitude is empty",
304
+ )
@@ -1,9 +1,10 @@
1
1
  #!/usr/bin/python
2
2
 
3
- import sys
4
-
5
3
  from .settings import Settings
6
4
  from datetime import datetime
5
+ import logging
6
+
7
+ log = logging.getLogger(__name__)
7
8
 
8
9
 
9
10
  def is_day_or_night(
@@ -40,9 +41,8 @@ def is_day_or_night(
40
41
  )
41
42
  except ValueError:
42
43
  # the schema default ("sunrise", "sunset"), or "HH:MM" saved before this change
43
- print(
44
- f"nocturne-shift: no usable sunrise/sunset saved ({times}); run nocturne-shift -w",
45
- file=sys.stderr,
44
+ log.warning(
45
+ "no usable sunrise/sunset saved (%s): run nocturne-shift -w", times
46
46
  )
47
47
  return None
48
48
 
@@ -66,11 +66,8 @@ def is_day_or_night(
66
66
  # set day-or-night
67
67
  try:
68
68
  settings.set("day-or-night", DAY_NIGHT)
69
- except Exception as e:
70
- print(
71
- "nocturne-shift: unable to save day-or-night: settings unavailable",
72
- file=sys.stderr,
73
- )
69
+ except Exception:
70
+ log.exception("saving day-or-night failed")
74
71
 
75
72
  print(f"{DAY_NIGHT}")
76
73
  return DAY_NIGHT
@@ -1,7 +1,7 @@
1
1
  import os
2
2
  from pathlib import Path
3
- from gi.repository import Gio
4
3
  from ..data_store import DataStore
4
+ import logging
5
5
 
6
6
  EXTENSION_UUID = "night-shift@christophermca.github.io"
7
7
 
@@ -15,6 +15,8 @@ DEFAULT_SCHEMA_PATH = os.path.expanduser(
15
15
  / "schemas"
16
16
  )
17
17
 
18
+ log = logging.getLogger(__name__)
19
+
18
20
 
19
21
  class Settings:
20
22
  """Wraps the extension's Gio.Settings.
@@ -48,8 +50,8 @@ class Settings:
48
50
  try:
49
51
  return self.data_store.get(key)
50
52
 
51
- except AttributeError as e:
52
- print(f"Error: Failed to GET key:`{key}`")
53
+ except AttributeError:
54
+ log.exception("reading %s failed", key)
53
55
 
54
56
  def set(self, key, value):
55
57
  self.data_store.set(key, value)
@@ -5,6 +5,7 @@ from .bin.is_day_or_night import is_day_or_night
5
5
  from .bin.settings import Settings
6
6
  from .data_store import DataStore
7
7
 
8
+ import logging
8
9
  import sys
9
10
  import argparse
10
11
  import argcomplete
@@ -12,6 +13,7 @@ import importlib.metadata
12
13
 
13
14
  PLUGIN_GROUP = "night_shift.commands"
14
15
  OPTIONAL_COMMANDS = {"services": "gnome-night-shift"}
16
+ log = logging.getLogger(__name__)
15
17
 
16
18
  try:
17
19
  __version__ = importlib.metadata.version("nocturne-shift")
@@ -34,10 +36,7 @@ def load_commands(subparsers) -> dict:
34
36
  except (
35
37
  Exception
36
38
  ) as e: # a broken plugin must not take the core CLI down
37
- print(
38
- f"nocturne-shift: skipping plugin {entry_point.name!r} ({e})",
39
- file=sys.stderr,
40
- )
39
+ log.warning("skipping plugin %r (%s)", entry_point.name, e)
41
40
 
42
41
  # Commands whose plugin isn't installed still parse, and say how to get them
43
42
  for name, extra in OPTIONAL_COMMANDS.items():
@@ -62,8 +61,8 @@ def _not_installed(name, extra):
62
61
  def check(times=None, settings=None, verbose=0):
63
62
  try:
64
63
  is_day_or_night(times, settings, verbose)
65
- except AttributeError as e:
66
- print(f"ERROR: {e}")
64
+ except AttributeError:
65
+ log.exception("check() failed")
67
66
 
68
67
 
69
68
  def run_once(
@@ -80,13 +79,17 @@ def run_once(
80
79
  if check_now != False:
81
80
  try:
82
81
  check(sunrise_sunset.times, settings, verbose)
83
- except Exception as e:
84
- print(f"check failed: {e}")
85
- except Exception as e:
86
- print(f"ERROR during run_once(): {e} ")
82
+ except Exception:
83
+ log.exception("check() failed")
84
+ except Exception:
85
+ log.exception("run_once() failed")
87
86
 
88
87
 
89
88
  def main():
89
+ logging.basicConfig(
90
+ level=logging.INFO,
91
+ format="nocturne-shift: %(levelname)s: %(message)s",
92
+ )
90
93
  parser = argparse.ArgumentParser(
91
94
  description="Get the times for the sunrise/sunset",
92
95
  prog="nocturne-shift",
@@ -1,7 +1,8 @@
1
- import sys
2
- from gi.repository import Gio, GLib
1
+ import logging
2
+ from gi.repository import Gio, GLib, GObject
3
3
  from typing import TypedDict, get_type_hints
4
4
 
5
+ log = logging.getLogger(__name__)
5
6
  default_config_file = ".var/night-shift/data.json"
6
7
 
7
8
 
@@ -60,10 +61,7 @@ class DataStore:
60
61
  self.data = Gio.Settings.new_full(self.schema, None, None)
61
62
 
62
63
  except Exception as e:
63
- print(
64
- f"nocturne-shift: settings unavailable, nothing will be saved ({e})",
65
- file=sys.stderr,
66
- )
64
+ log.error("settings unavailable, nothing will be saved (%s)", e)
67
65
  self.data = None
68
66
 
69
67
  def get_keys(self) -> list[str]:
@@ -104,10 +102,10 @@ class DataStore:
104
102
  # (GLib-GIO-ERROR), so skip it: an older extension's schema may not
105
103
  # have a key a newer nocturne-shift saves, like "backend-version".
106
104
  if self.schema is not None and not self.schema.has_key(key):
107
- print(
108
- f"nocturne-shift: not saving {key}: the schema in"
109
- f" {self.schema_path} has no such key",
110
- file=sys.stderr,
105
+ log.warning(
106
+ "not saving %s: the schema in %s has no such key",
107
+ key,
108
+ self.schema_path,
111
109
  )
112
110
  return
113
111
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: nocturne-shift
3
- Version: 2.0.0
3
+ Version: 2.0.2
4
4
  Summary: Shift between light and dark with the sun: sunrise/sunset times and day or night
5
5
  Author-email: Christopher McAdams <mca.christopher@gmail.com>
6
6
  License-Expression: MIT
@@ -32,7 +32,6 @@ Nocturne Shift will lookup the time of the sunrise and sunset for the provided l
32
32
  - `nocturne-shift` can also check if the current state of the 24hr period is day or night
33
33
  - `nocturne-shift services`: systemd timers (with `gnome-night-shift`)
34
34
 
35
-
36
35
  ## Features
37
36
 
38
37
  * Use geoclue to determine location. Requires Location services to be enabled. **(Settings > Privacy & Security > Location > Enable "Automatic Device Location"**
@@ -108,3 +107,5 @@ options:
108
107
  [![Publish to PyPI](https://github.com/christophermca/nocturne-shift/actions/workflows/publish-pypi.yml/badge.svg?branch=dev)](https://github.com/christophermca/nocturne-shift/actions/workflows/publish-pypi.yml)
109
108
 
110
109
  [![Publish to TestPyPI](https://github.com/christophermca/nocturne-shift/actions/workflows/publish-testpypi.yml/badge.svg?branch=dev&event=workflow_dispatch)](https://github.com/christophermca/nocturne-shift/actions/workflows/publish-testpypi.yml)
110
+
111
+ [![PyPI](https://img.shields.io/pypi/v/nocturne-shift)](https://pypi.org/project/nocturne-shift/)
@@ -0,0 +1,8 @@
1
+ {
2
+ "tag": "2.0.2",
3
+ "distance": 0,
4
+ "node": "gead0531",
5
+ "dirty": false,
6
+ "branch": "HEAD",
7
+ "node_date": "2026-11-25"
8
+ }
@@ -83,7 +83,7 @@ def test_non_numeric_coordinate_is_a_usage_error(argv, mock_fetcher, capsys):
83
83
 
84
84
 
85
85
  # --- -c / --check-now [SCHEMA_PATH] -------------------------------------------
86
- def test_given_check_now_fails_throws_error(argv, settings_class, capsys):
86
+ def test_given_check_now_fails_throws_error(argv, settings_class, caplog):
87
87
  argv("--check-now")
88
88
  with patch(
89
89
  "nocturne_shift.cli.is_day_or_night",
@@ -93,6 +93,7 @@ def test_given_check_now_fails_throws_error(argv, settings_class, capsys):
93
93
  result = cli.main()
94
94
 
95
95
  assert result is None
96
+ assert "check() failed" in caplog.text
96
97
 
97
98
 
98
99
  def test_check_now_uses_default_settings(argv, mock_check, settings_class):
@@ -225,15 +226,17 @@ def test_run_once_without_check_now_does_not_check(mock_fetcher, mock_check):
225
226
  mock_check.assert_not_called()
226
227
 
227
228
 
228
- def test_run_once_catches_fetch_errors(mock_fetcher, capsys):
229
+ def test_run_once_catches_fetch_errors(mock_fetcher, caplog):
229
230
  mock_fetcher.side_effect = RuntimeError("offline")
230
231
 
231
232
  cli.run_once()
232
233
 
233
- assert "ERROR during run_once(): offline" in capsys.readouterr().out
234
+ (record,) = caplog.records
235
+ assert record.getMessage() == "run_once() failed"
236
+ assert "RuntimeError: offline" in caplog.text
234
237
 
235
238
 
236
- def test_run_once_catches_check_errors(mock_fetcher, capsys):
239
+ def test_run_once_catches_check_errors(mock_fetcher, caplog):
237
240
  mock_fetcher.return_value.times = ("06:52", "18:51")
238
241
 
239
242
  with patch(
@@ -243,7 +246,9 @@ def test_run_once_catches_check_errors(mock_fetcher, capsys):
243
246
 
244
247
  check.assert_called_once()
245
248
 
246
- assert "check failed: no schema" in capsys.readouterr().out
249
+ (record,) = caplog.records
250
+ assert record.getMessage() == "check() failed"
251
+ assert "AttributeError: no schema" in caplog.text
247
252
 
248
253
 
249
254
  # --- -v / --verbose and -w / --watch ---------------------------------------------
@@ -105,11 +105,11 @@ def test_schema_id_picks_which_schema_to_load(tmp_path):
105
105
  assert store.schema.get_id() == package_id
106
106
 
107
107
 
108
- def test_folder_without_schemas_says_why(tmp_path, capsys):
108
+ def test_folder_without_schemas_says_why(tmp_path, caplog):
109
109
  store = DataStore(str(tmp_path))
110
110
 
111
111
  assert store.available is False
112
- assert f"no compiled schemas in {tmp_path}" in capsys.readouterr().err
112
+ assert f"no compiled schemas in {tmp_path}" in caplog.text
113
113
 
114
114
 
115
115
  # DataStore finds the schema by ID, not by which .gschema.xml comes first, so a
@@ -153,7 +153,7 @@ def test_a_shared_folder_uses_the_night_shift_schema(tmp_path):
153
153
 
154
154
 
155
155
  def test_a_folder_with_only_another_apps_schema_is_unavailable(
156
- tmp_path, capsys
156
+ tmp_path, caplog
157
157
  ):
158
158
  folder = compiled_folder(
159
159
  tmp_path / "other", **{"com.example.aaa": OTHER_APP_XML}
@@ -162,7 +162,7 @@ def test_a_folder_with_only_another_apps_schema_is_unavailable(
162
162
  store = DataStore(folder)
163
163
 
164
164
  assert store.available is False
165
- assert f"no Night Shift schema in {folder}" in capsys.readouterr().err
165
+ assert f"no Night Shift schema in {folder}" in caplog.text
166
166
 
167
167
 
168
168
  def test_the_extension_schema_is_preferred_over_nocturne_shifts_own(tmp_path):
@@ -177,7 +177,7 @@ def test_the_extension_schema_is_preferred_over_nocturne_shifts_own(tmp_path):
177
177
  assert store.schema.get_id() == "org.gnome.shell.extensions.night-shift"
178
178
 
179
179
 
180
- def test_a_key_missing_from_the_schema_is_skipped(tmp_path, capsys):
180
+ def test_a_key_missing_from_the_schema_is_skipped(tmp_path, caplog):
181
181
  """An older extension's schema lacks keys a newer nocturne-shift saves.
182
182
  Writing one would abort the process (GLib-GIO-ERROR), so it's skipped."""
183
183
  if shutil.which("glib-compile-schemas") is None:
@@ -197,7 +197,7 @@ def test_a_key_missing_from_the_schema_is_skipped(tmp_path, capsys):
197
197
  store.set("backend-version", "0.7.6")
198
198
  store.set("tzid", "America/New_York") # other keys still save
199
199
 
200
- assert "not saving backend-version" in capsys.readouterr().err
200
+ assert "not saving backend-version" in caplog.text
201
201
  assert store.data["tzid"] == "America/New_York"
202
202
 
203
203
 
@@ -1,5 +1,5 @@
1
- import sys
2
1
  import time
2
+ import sys
3
3
  import io
4
4
  import re
5
5
  import pytest
@@ -199,7 +199,7 @@ class TestGetSunriseSunsetGetLocation:
199
199
  ]
200
200
 
201
201
  def test_where_am_i_that_never_answers_times_out(
202
- self, fetcher, popen, capsys
202
+ self, fetcher, popen, caplog
203
203
  ):
204
204
  # a real child process that prints nothing, like geoclue stuck
205
205
  # waiting for a location
@@ -218,7 +218,7 @@ class TestGetSunriseSunsetGetLocation:
218
218
  assert time.monotonic() - started < 5 # not the full 60 s
219
219
 
220
220
  assert silent.poll() is not None # killed and reaped
221
- assert "no location within 0.5 seconds" in capsys.readouterr().err
221
+ assert "no location within 0.5 seconds" in caplog.text
222
222
 
223
223
  def test_where_am_i_that_answers_is_not_timed_out(self, fetcher, popen):
224
224
  coords, _, where_am_i = self._run(fetcher, popen)
@@ -268,7 +268,7 @@ URL_WITH_COORDS = (
268
268
 
269
269
 
270
270
  @patch("nocturne_shift.bin.get_sunrise_sunset.requests.get")
271
- def test_http_errors_report_the_status_not_the_url(mock_get, fetcher, capsys):
271
+ def test_http_errors_report_the_status_not_the_url(mock_get, fetcher, caplog):
272
272
  # what raise_for_status() raises: the message names the URL, and
273
273
  # .response is attached
274
274
  mock_get.return_value.raise_for_status.side_effect = requests.exceptions.HTTPError(
@@ -277,36 +277,41 @@ def test_http_errors_report_the_status_not_the_url(mock_get, fetcher, capsys):
277
277
  )
278
278
 
279
279
  assert fetcher._get_sunrise_sunset(40.712776, -74.005974, 0) is None
280
- out = capsys.readouterr().out
281
- assert "HTTP error occurred (e.g., 404, 500): 500" in out
282
- assert "40.712776" not in out and "74.005974" not in out
280
+
281
+ (record,) = caplog.records
282
+ assert (
283
+ record.getMessage() == "fetching sunrise/sunset times failed: HTTP 500"
284
+ )
285
+ assert record.exc_info is None # a traceback would include the URL
286
+ assert "40.712776" not in caplog.text and "74.005974" not in caplog.text
283
287
 
284
288
 
285
289
  @patch("nocturne_shift.bin.get_sunrise_sunset.requests.get")
286
290
  def test_http_error_without_a_response_is_still_reported(
287
- mock_get, fetcher, capsys
291
+ mock_get, fetcher, caplog
288
292
  ):
289
293
  mock_get.return_value.raise_for_status.side_effect = (
290
294
  requests.exceptions.HTTPError("500 Server Error")
291
295
  )
292
296
 
293
297
  assert fetcher._get_sunrise_sunset(40.7, -74.0, 0) is None
294
- assert (
295
- "HTTP error occurred (e.g., 404, 500): no response"
296
- in capsys.readouterr().out
297
- )
298
+ assert "HTTP no response" in caplog.text
298
299
 
299
300
 
300
301
  @patch("nocturne_shift.bin.get_sunrise_sunset.requests.get")
301
- def test_other_errors_print_only_their_type(mock_get, fetcher, capsys):
302
+ def test_other_errors_log_only_their_type(mock_get, fetcher, caplog):
302
303
  # e.g. no network: requests' message includes the URL with lat/lng
303
304
  mock_get.side_effect = requests.exceptions.ConnectionError(
304
305
  f"Max retries exceeded with url: {URL_WITH_COORDS}"
305
306
  )
306
307
 
307
308
  assert fetcher._get_sunrise_sunset(40.712776, -74.005974, 0) is None
308
- out = capsys.readouterr().out
309
- assert out.strip() == "ConnectionError"
309
+ (record,) = caplog.records
310
+ assert record.getMessage() == (
311
+ "fetching sunrise/sunset times failed: ConnectionError"
312
+ )
313
+ assert record.exc_info is None
314
+ assert "40.712776" not in caplog.text and "74.005974" not in caplog.text
310
315
 
311
316
 
312
317
  @patch("nocturne_shift.bin.get_sunrise_sunset.requests.get")
@@ -334,29 +339,41 @@ def test_coordinates_are_rounded_before_the_request(mock_get, fetcher):
334
339
  assert params == {"lat": 40.71, "lng": -74.01}
335
340
 
336
341
 
337
- def test_save_without_settings_says_why(capsys):
342
+ @patch("nocturne_shift.bin.get_sunrise_sunset.requests.get")
343
+ def test_unexpected_errors_keep_their_traceback(mock_get, fetcher, caplog):
344
+ # not a network problem: a bug in nocturne-shift, so the traceback helps
345
+ mock_get.side_effect = ValueError("bug")
346
+
347
+ assert fetcher._get_sunrise_sunset(40.7, -74.0, 0) is None
348
+ (record,) = caplog.records
349
+ assert record.exc_info is not None
350
+ assert "ValueError: bug" in caplog.text
351
+
352
+
353
+ def test_save_without_settings_says_why(caplog):
338
354
  fetcher = GetTimeOfSunriseSunset() # no settings
339
- capsys.readouterr() # drop __init__'s "no static location" message
355
+ caplog.clear() # drop anything __init__ logged
340
356
 
341
357
  fetcher._save(
342
358
  {"tzid": "America/New_York", "times": (SUNRISE_TIME, SUNSET_TIME)}
343
359
  )
344
360
 
345
- assert capsys.readouterr().err == (
346
- "nocturne-shift: unable to save tzid, times: settings unavailable\n"
361
+ (record,) = caplog.records
362
+ assert record.getMessage() == (
363
+ "unable to save tzid, times: settings unavailable"
347
364
  )
365
+ assert record.exc_info is None # not inside an except: no traceback
348
366
 
349
367
 
350
- def test_save_errors_go_to_stderr(fetcher, capsys):
368
+ def test_save_errors_are_logged_with_their_traceback(fetcher, caplog, capsys):
351
369
  fetcher.settings.set.side_effect = TypeError("can't save tzid")
352
370
 
353
371
  fetcher._save({"tzid": "America/New_York"})
354
372
 
355
- captured = capsys.readouterr()
356
- assert "ERROR SAVING: can't save tzid" in captured.err
357
- assert (
358
- captured.out == ""
359
- ) # stdout stays clean for `nocturne-shift ... | cmd`
373
+ (record,) = caplog.records
374
+ assert record.getMessage() == "saving tzid failed"
375
+ assert "TypeError: can't save tzid" in caplog.text
376
+ assert capsys.readouterr().out == "" # stdout stays clean for `| cmd`
360
377
 
361
378
 
362
379
  @patch("nocturne_shift.bin.get_sunrise_sunset.requests.get")
@@ -128,14 +128,14 @@ def test_times_in_another_time_zone_are_converted_to_local():
128
128
  assert is_day_or_night(times_in_utc, None) == "night"
129
129
 
130
130
 
131
- def test_times_that_are_not_iso_are_skipped(capsys):
131
+ def test_times_that_are_not_iso_are_skipped(caplog):
132
132
  """The schema default before the first fetch is ("sunrise", "sunset")."""
133
133
  help_message = "run nocturne-shift -w"
134
134
  settings = create_autospec(Settings, instance=True)
135
135
  with at("12:00"):
136
136
  assert is_day_or_night(("sunrise", "sunset"), settings) is None
137
137
  settings.set.assert_not_called()
138
- assert help_message in capsys.readouterr().err
138
+ assert help_message in caplog.text
139
139
 
140
140
 
141
141
  @pytest.mark.parametrize(
@@ -1,8 +1,8 @@
1
- import importlib.metadata
2
1
  import sys
3
2
  import types
4
-
5
3
  import pytest
4
+ import importlib.metadata
5
+
6
6
 
7
7
  from nocturne_shift import cli
8
8
 
@@ -10,7 +10,8 @@ from nocturne_shift import cli
10
10
  @pytest.fixture
11
11
  def plugins(monkeypatch):
12
12
  """Control which plugins load_commands() sees, whatever this machine has
13
- installed (e.g. `pip install -e ./gnome-night-shift` registers the real one)."""
13
+ installed (e.g. `pip install -e ./gnome-night-shift` registers the real one).
14
+ """
14
15
  installed = []
15
16
 
16
17
  def entry_points(group):
@@ -59,17 +60,18 @@ def test_missing_plugin_says_how_to_install(argv, plugins):
59
60
  with pytest.raises(SystemExit) as exit_info:
60
61
  cli.main()
61
62
 
62
- assert "pip install 'gnome-night-shift'" in str(
63
- exit_info.value.code
64
- )
63
+ assert "pip install 'gnome-night-shift'" in str(exit_info.value.code)
65
64
 
66
65
 
67
- def test_broken_plugin_does_not_break_the_core_cli(argv, plugins, capsys):
66
+ def test_broken_plugin_does_not_break_the_core_cli(
67
+ argv, plugins, capsys, caplog
68
+ ):
68
69
  plugins("services", "no_such_module:register")
69
70
  argv() # no arguments: prints help
70
71
 
71
72
  cli.main()
72
73
 
73
- captured = capsys.readouterr()
74
- assert "usage: nocturne-shift" in captured.out
75
- assert "skipping plugin 'services'" in captured.err
74
+ assert (
75
+ "usage: nocturne-shift" in capsys.readouterr().out
76
+ ) # Prints the help message
77
+ assert "skipping plugin 'services'" in caplog.text # logs the problem
@@ -63,10 +63,10 @@ def test_available_reflects_the_data_store(store, available):
63
63
  assert Settings(store).available is available
64
64
 
65
65
 
66
- def test_missing_schema_means_unavailable(tmp_path, capsys):
66
+ def test_missing_schema_means_unavailable(tmp_path, caplog):
67
67
  # Real DataStore and real Gio: an empty directory has no compiled schema,
68
68
  # which is exactly a machine without the GNOME extension installed.
69
69
  settings = Settings(DataStore(str(tmp_path)))
70
70
 
71
71
  assert settings.available is False
72
- assert "settings unavailable" in capsys.readouterr().err
72
+ assert "settings unavailable" in caplog.text
@@ -1,8 +0,0 @@
1
- {
2
- "tag": "2.0.0",
3
- "distance": 0,
4
- "node": "gaa50296",
5
- "dirty": false,
6
- "branch": "HEAD",
7
- "node_date": "2026-11-18"
8
- }
File without changes
File without changes
File without changes