pywiim 3.0.2__tar.gz → 3.0.3__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 (87) hide show
  1. {pywiim-3.0.2/pywiim.egg-info → pywiim-3.0.3}/PKG-INFO +1 -1
  2. {pywiim-3.0.2 → pywiim-3.0.3}/pyproject.toml +1 -1
  3. {pywiim-3.0.2 → pywiim-3.0.3}/pywiim/__init__.py +1 -1
  4. {pywiim-3.0.2 → pywiim-3.0.3}/pywiim/api/audio_settings.py +18 -2
  5. {pywiim-3.0.2 → pywiim-3.0.3}/pywiim/player/__init__.py +21 -2
  6. {pywiim-3.0.2 → pywiim-3.0.3}/pywiim/player/audio.py +17 -6
  7. {pywiim-3.0.2 → pywiim-3.0.3}/pywiim/player/base.py +2 -0
  8. {pywiim-3.0.2 → pywiim-3.0.3}/pywiim/player/properties.py +15 -0
  9. {pywiim-3.0.2 → pywiim-3.0.3}/pywiim/player/statemgr.py +9 -3
  10. {pywiim-3.0.2 → pywiim-3.0.3/pywiim.egg-info}/PKG-INFO +1 -1
  11. {pywiim-3.0.2 → pywiim-3.0.3}/pywiim.egg-info/SOURCES.txt +2 -1
  12. pywiim-3.0.3/tests/test_release_preflight.py +115 -0
  13. {pywiim-3.0.2 → pywiim-3.0.3}/LICENSE +0 -0
  14. {pywiim-3.0.2 → pywiim-3.0.3}/README.md +0 -0
  15. {pywiim-3.0.2 → pywiim-3.0.3}/pywiim/api/__init__.py +0 -0
  16. {pywiim-3.0.2 → pywiim-3.0.3}/pywiim/api/audio_pro.py +0 -0
  17. {pywiim-3.0.2 → pywiim-3.0.3}/pywiim/api/base.py +0 -0
  18. {pywiim-3.0.2 → pywiim-3.0.3}/pywiim/api/bluetooth.py +0 -0
  19. {pywiim-3.0.2 → pywiim-3.0.3}/pywiim/api/constants.py +0 -0
  20. {pywiim-3.0.2 → pywiim-3.0.3}/pywiim/api/device.py +0 -0
  21. {pywiim-3.0.2 → pywiim-3.0.3}/pywiim/api/diagnostics.py +0 -0
  22. {pywiim-3.0.2 → pywiim-3.0.3}/pywiim/api/endpoints.py +0 -0
  23. {pywiim-3.0.2 → pywiim-3.0.3}/pywiim/api/eq.py +0 -0
  24. {pywiim-3.0.2 → pywiim-3.0.3}/pywiim/api/firmware.py +0 -0
  25. {pywiim-3.0.2 → pywiim-3.0.3}/pywiim/api/group.py +0 -0
  26. {pywiim-3.0.2 → pywiim-3.0.3}/pywiim/api/lms.py +0 -0
  27. {pywiim-3.0.2 → pywiim-3.0.3}/pywiim/api/loop_mode.py +0 -0
  28. {pywiim-3.0.2 → pywiim-3.0.3}/pywiim/api/misc.py +0 -0
  29. {pywiim-3.0.2 → pywiim-3.0.3}/pywiim/api/parser.py +0 -0
  30. {pywiim-3.0.2 → pywiim-3.0.3}/pywiim/api/peq.py +0 -0
  31. {pywiim-3.0.2 → pywiim-3.0.3}/pywiim/api/playback.py +0 -0
  32. {pywiim-3.0.2 → pywiim-3.0.3}/pywiim/api/preset.py +0 -0
  33. {pywiim-3.0.2 → pywiim-3.0.3}/pywiim/api/ssl.py +0 -0
  34. {pywiim-3.0.2 → pywiim-3.0.3}/pywiim/api/subwoofer.py +0 -0
  35. {pywiim-3.0.2 → pywiim-3.0.3}/pywiim/api/timer.py +0 -0
  36. {pywiim-3.0.2 → pywiim-3.0.3}/pywiim/backoff.py +0 -0
  37. {pywiim-3.0.2 → pywiim-3.0.3}/pywiim/capabilities.py +0 -0
  38. {pywiim-3.0.2 → pywiim-3.0.3}/pywiim/cli/__init__.py +0 -0
  39. {pywiim-3.0.2 → pywiim-3.0.3}/pywiim/cli/diagnostics.py +0 -0
  40. {pywiim-3.0.2 → pywiim-3.0.3}/pywiim/cli/discovery_cli.py +0 -0
  41. {pywiim-3.0.2 → pywiim-3.0.3}/pywiim/cli/group_test_cli.py +0 -0
  42. {pywiim-3.0.2 → pywiim-3.0.3}/pywiim/cli/join_test_cli.py +0 -0
  43. {pywiim-3.0.2 → pywiim-3.0.3}/pywiim/cli/monitor_cli.py +0 -0
  44. {pywiim-3.0.2 → pywiim-3.0.3}/pywiim/cli/verify_cli.py +0 -0
  45. {pywiim-3.0.2 → pywiim-3.0.3}/pywiim/client.py +0 -0
  46. {pywiim-3.0.2 → pywiim-3.0.3}/pywiim/device_capabilities.py +0 -0
  47. {pywiim-3.0.2 → pywiim-3.0.3}/pywiim/discovery.py +0 -0
  48. {pywiim-3.0.2 → pywiim-3.0.3}/pywiim/exceptions.py +0 -0
  49. {pywiim-3.0.2 → pywiim-3.0.3}/pywiim/group.py +0 -0
  50. {pywiim-3.0.2 → pywiim-3.0.3}/pywiim/group_helpers.py +0 -0
  51. {pywiim-3.0.2 → pywiim-3.0.3}/pywiim/mcp/__init__.py +0 -0
  52. {pywiim-3.0.2 → pywiim-3.0.3}/pywiim/mcp/__main__.py +0 -0
  53. {pywiim-3.0.2 → pywiim-3.0.3}/pywiim/mcp/config.example.json +0 -0
  54. {pywiim-3.0.2 → pywiim-3.0.3}/pywiim/mcp/config.py +0 -0
  55. {pywiim-3.0.2 → pywiim-3.0.3}/pywiim/mcp/context.py +0 -0
  56. {pywiim-3.0.2 → pywiim-3.0.3}/pywiim/mcp/server.py +0 -0
  57. {pywiim-3.0.2 → pywiim-3.0.3}/pywiim/metadata.py +0 -0
  58. {pywiim-3.0.2 → pywiim-3.0.3}/pywiim/model_names.py +0 -0
  59. {pywiim-3.0.2 → pywiim-3.0.3}/pywiim/models.py +0 -0
  60. {pywiim-3.0.2 → pywiim-3.0.3}/pywiim/normalize.py +0 -0
  61. {pywiim-3.0.2 → pywiim-3.0.3}/pywiim/player/bluetooth.py +0 -0
  62. {pywiim-3.0.2 → pywiim-3.0.3}/pywiim/player/coverart.py +0 -0
  63. {pywiim-3.0.2 → pywiim-3.0.3}/pywiim/player/debounce.py +0 -0
  64. {pywiim-3.0.2 → pywiim-3.0.3}/pywiim/player/diagnostics.py +0 -0
  65. {pywiim-3.0.2 → pywiim-3.0.3}/pywiim/player/groupops.py +0 -0
  66. {pywiim-3.0.2 → pywiim-3.0.3}/pywiim/player/media.py +0 -0
  67. {pywiim-3.0.2 → pywiim-3.0.3}/pywiim/player/playback.py +0 -0
  68. {pywiim-3.0.2 → pywiim-3.0.3}/pywiim/player/source_capabilities.py +0 -0
  69. {pywiim-3.0.2 → pywiim-3.0.3}/pywiim/player/stream.py +0 -0
  70. {pywiim-3.0.2 → pywiim-3.0.3}/pywiim/player/stream_enricher.py +0 -0
  71. {pywiim-3.0.2 → pywiim-3.0.3}/pywiim/player/volume.py +0 -0
  72. {pywiim-3.0.2 → pywiim-3.0.3}/pywiim/polling.py +0 -0
  73. {pywiim-3.0.2 → pywiim-3.0.3}/pywiim/profiles.py +0 -0
  74. {pywiim-3.0.2 → pywiim-3.0.3}/pywiim/py.typed +0 -0
  75. {pywiim-3.0.2 → pywiim-3.0.3}/pywiim/role.py +0 -0
  76. {pywiim-3.0.2 → pywiim-3.0.3}/pywiim/state.py +0 -0
  77. {pywiim-3.0.2 → pywiim-3.0.3}/pywiim/upnp/__init__.py +0 -0
  78. {pywiim-3.0.2 → pywiim-3.0.3}/pywiim/upnp/client.py +0 -0
  79. {pywiim-3.0.2 → pywiim-3.0.3}/pywiim/upnp/eventer.py +0 -0
  80. {pywiim-3.0.2 → pywiim-3.0.3}/pywiim/upnp/health.py +0 -0
  81. {pywiim-3.0.2 → pywiim-3.0.3}/pywiim/upnp/metadata.py +0 -0
  82. {pywiim-3.0.2 → pywiim-3.0.3}/pywiim/upnp/playqueue.py +0 -0
  83. {pywiim-3.0.2 → pywiim-3.0.3}/pywiim.egg-info/dependency_links.txt +0 -0
  84. {pywiim-3.0.2 → pywiim-3.0.3}/pywiim.egg-info/entry_points.txt +0 -0
  85. {pywiim-3.0.2 → pywiim-3.0.3}/pywiim.egg-info/requires.txt +0 -0
  86. {pywiim-3.0.2 → pywiim-3.0.3}/pywiim.egg-info/top_level.txt +0 -0
  87. {pywiim-3.0.2 → pywiim-3.0.3}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pywiim
3
- Version: 3.0.2
3
+ Version: 3.0.3
4
4
  Summary: Python library for WiiM/LinkPlay device communication
5
5
  Author-email: Michael Cumming <mjcumming@gmail.com>
6
6
  License: MIT
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "pywiim"
7
- version = "3.0.2"
7
+ version = "3.0.3"
8
8
  description = "Python library for WiiM/LinkPlay device communication"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.11"
@@ -105,7 +105,7 @@ from .profiles import (
105
105
  from .role import RoleDetectionResult, detect_role
106
106
  from .state import GroupStateSynchronizer, StateSynchronizer
107
107
 
108
- __version__ = "3.0.2"
108
+ __version__ = "3.0.3"
109
109
  __all__ = [
110
110
  # Main client
111
111
  "WiiMClient",
@@ -25,6 +25,7 @@ from .constants import (
25
25
  API_ENDPOINT_SET_CHANNEL_MODE,
26
26
  API_ENDPOINT_SET_OUTPUT_CHANNEL,
27
27
  API_ENDPOINT_SET_SPDIF_SWITCH_DELAY,
28
+ CHANNEL_MODE_MAP,
28
29
  OUTPUT_CHANNEL_MAP,
29
30
  )
30
31
 
@@ -44,6 +45,21 @@ def output_channel_value(channel: str) -> int:
44
45
  raise ValueError(f"Output channel must be one of {list(OUTPUT_CHANNEL_MAP.values())}, got {channel!r}")
45
46
 
46
47
 
48
+ def channel_mode_value(channel: str) -> int:
49
+ """Return the standalone channel-mode wire value (0-3) for a name.
50
+
51
+ Accepts ``stereo`` / ``left`` / ``right`` / ``mono``, ignoring case and surrounding spaces.
52
+
53
+ Raises:
54
+ ValueError: If ``channel`` is not one of the four names.
55
+ """
56
+ wanted = channel.strip().lower() if isinstance(channel, str) else ""
57
+ for value, name in CHANNEL_MODE_MAP.items():
58
+ if name == wanted:
59
+ return value
60
+ raise ValueError(f"Channel mode must be one of {list(CHANNEL_MODE_MAP.values())}, got {channel!r}")
61
+
62
+
47
63
  class AudioSettingsAPI:
48
64
  """Audio settings helpers (SPDIF, balance, etc.).
49
65
 
@@ -210,8 +226,8 @@ class AudioSettingsAPI:
210
226
  return mode
211
227
 
212
228
  async def set_channel_mode(self, channel: str) -> None:
213
- """Set standalone playback to stereo, left or right."""
214
- value = output_channel_value(channel)
229
+ """Set standalone playback to stereo, left, right or mono."""
230
+ value = channel_mode_value(channel)
215
231
  endpoint = f"{API_ENDPOINT_SET_CHANNEL_MODE}{value}"
216
232
  response = await self._request(endpoint) # type: ignore[attr-defined]
217
233
  if (response.raw or "").strip().upper() != "OK" and response.parsed != "OK":
@@ -448,6 +448,7 @@ class Player(PlayerBase):
448
448
  self._eq_enabled = False
449
449
  self._eq_band_preset = None
450
450
  self._eq_is_custom = False
451
+ self._eq_custom_stored = False
451
452
 
452
453
  async def refresh_eq_state(self) -> None:
453
454
  """Read the active input's graphic and supported parametric EQ."""
@@ -568,14 +569,17 @@ class Player(PlayerBase):
568
569
  await self._audio_config.set_channel_balance(balance)
569
570
 
570
571
  async def set_output_channel(self, channel: str) -> None:
571
- """Set the output channel: ``"stereo"``, ``"left"`` or ``"right"``.
572
+ """Set the output channel: ``"stereo"``, ``"left"``, ``"right"`` or ``"mono"``.
573
+
574
+ ``"mono"`` works only for a solo player that supports the standalone channel mode
575
+ (``setChannelMode:3``); otherwise it raises ``WiiMError``.
572
576
 
573
577
  Uses the standalone channel mode when supported and solo; otherwise uses
574
578
  the device's group-channel command. Updates ``output_channel`` right away.
575
579
 
576
580
  Raises:
577
581
  WiiMError: If ``supports_output_channel`` is false or the request fails.
578
- ValueError: If ``channel`` is not one of the three names.
582
+ ValueError: If ``channel`` is not a known name.
579
583
  """
580
584
  await self._audio_config.set_output_channel(channel)
581
585
 
@@ -1275,6 +1279,16 @@ class Player(PlayerBase):
1275
1279
  """Whether the active graphic EQ consists of unsaved custom bands."""
1276
1280
  return self._eq_is_custom
1277
1281
 
1282
+ @property
1283
+ def eq_custom_stored(self) -> bool:
1284
+ """Whether graphic EQ is off while an unsaved custom setting is stored.
1285
+
1286
+ ``eq_preset`` stays "Off" in that state. Selecting "Custom" with
1287
+ ``set_eq_preset()`` turns EQ back on with those bands. A saved preset
1288
+ that was switched off does not count.
1289
+ """
1290
+ return self._eq_enabled is False and self._eq_custom_stored
1291
+
1278
1292
  @property
1279
1293
  def shuffle(self) -> bool | None:
1280
1294
  """Shuffle state from cached status (alias for shuffle_state)."""
@@ -1630,6 +1644,11 @@ class Player(PlayerBase):
1630
1644
  """Whether output channel (stereo / left / right) is supported."""
1631
1645
  return self._properties.supports_output_channel
1632
1646
 
1647
+ @property
1648
+ def available_output_channels(self) -> list[str]:
1649
+ """Channel names ``set_output_channel()`` accepts now (``"mono"`` only for a capable solo player)."""
1650
+ return self._properties.available_output_channels
1651
+
1633
1652
  @property
1634
1653
  def supports_presets(self) -> bool:
1635
1654
  """Whether preset/favorites are supported."""
@@ -8,8 +8,8 @@ import time
8
8
  from collections.abc import Sequence
9
9
  from typing import TYPE_CHECKING, Any
10
10
 
11
- from ..api.audio_settings import output_channel_value
12
- from ..api.constants import API_ENDPOINT_GET_CHANNEL_BALANCE, OUTPUT_CHANNEL_MAP
11
+ from ..api.audio_settings import channel_mode_value
12
+ from ..api.constants import API_ENDPOINT_GET_CHANNEL_BALANCE, CHANNEL_MODE_MAP
13
13
  from ..capabilities import _channel_balance_probe_success
14
14
  from ..exceptions import WiiMError, WiiMResponseError
15
15
  from ..normalize import canonical_source_key, source_rename_reverse
@@ -437,16 +437,20 @@ class AudioConfiguration:
437
437
  """Set the solo mode or group channel and update the matching cache.
438
438
 
439
439
  Args:
440
- channel: ``"stereo"``, ``"left"`` or ``"right"``, any case.
440
+ channel: ``"stereo"``, ``"left"`` or ``"right"``, any case. ``"mono"`` is also
441
+ accepted for a solo player that supports the standalone channel mode.
441
442
 
442
443
  Raises:
443
- WiiMError: If the device does not support output channel.
444
- ValueError: If ``channel`` is not one of the three names.
444
+ WiiMError: If the device does not support output channel, or ``"mono"`` is
445
+ requested for a grouped player or one without the standalone channel mode.
446
+ ValueError: If ``channel`` is not a known name.
445
447
  """
446
448
  if not self.player.supports_output_channel:
447
449
  raise WiiMError("Output channel is not supported")
448
- name = OUTPUT_CHANNEL_MAP[output_channel_value(channel)]
450
+ name = CHANNEL_MODE_MAP[channel_mode_value(channel)]
449
451
  mode_support = self.player.client.capabilities.get("supports_output_channel_mode")
452
+ if name == "mono" and "mono" not in self.player.available_output_channels:
453
+ raise WiiMError("Output channel 'mono' requires a standalone player with channel mode support")
450
454
  if self.player.is_solo and mode_support is None:
451
455
  raise WiiMError("Standalone output channel support is not yet known")
452
456
  if self.player.is_solo and mode_support:
@@ -473,6 +477,13 @@ class AudioConfiguration:
473
477
  await self.set_eq_enabled(False)
474
478
  return
475
479
 
480
+ # Unsaved custom bands stay stored while EQ is off; EQOn restores them.
481
+ if preset.lower() == "custom" and self.player.eq_custom_stored:
482
+ await self.set_eq_enabled(True)
483
+ if not self.player._eq_is_custom:
484
+ raise WiiMResponseError("Custom EQ was not confirmed by the device")
485
+ return
486
+
476
487
  # Resolve against cached device presets first so dynamic/custom labels work.
477
488
  available_presets = [item for item in self.player.eq_presets if item and item != "Off"]
478
489
  normalized_preset = self.player.client._normalize_eq_preset_name(
@@ -103,6 +103,8 @@ class PlayerBase:
103
103
  # firmware after EQLoad, so this name outranks that field (wiim #165).
104
104
  self._eq_band_preset: str | None = None
105
105
  self._eq_is_custom: bool | None = None
106
+ # Graphic EQ is off but an unsaved custom setting is stored (Off + empty Name).
107
+ self._eq_custom_stored: bool = False
106
108
  self._eq_band_reconcile: bool = False
107
109
  self._eq_state_source: str | None = None
108
110
  self._eq_state_revision: int = 0
@@ -5,6 +5,7 @@ from __future__ import annotations
5
5
  import logging
6
6
  from typing import TYPE_CHECKING, Any
7
7
 
8
+ from ..api.constants import OUTPUT_CHANNEL_MAP
8
9
  from ..device_capabilities import filter_plm_inputs, get_device_inputs, get_device_output_modes
9
10
  from ..metadata import is_valid_image_url, is_valid_metadata_value
10
11
  from ..normalize import HARDWARE_SOURCE_KEYS as _HARDWARE_SOURCE_KEYS
@@ -1718,6 +1719,20 @@ class PlayerProperties:
1718
1719
  return False
1719
1720
  return bool(self.player.client.capabilities.get("supports_output_channel", False))
1720
1721
 
1722
+ @property
1723
+ def available_output_channels(self) -> list[str]:
1724
+ """Output channel names ``set_output_channel()`` accepts right now.
1725
+
1726
+ Empty when output channel is unsupported. ``"mono"`` is included only for a solo
1727
+ player that supports the standalone channel mode.
1728
+ """
1729
+ if not self.supports_output_channel:
1730
+ return []
1731
+ channels = list(OUTPUT_CHANNEL_MAP.values())
1732
+ if self.player.is_solo and self.player.client.capabilities.get("supports_output_channel_mode") is True:
1733
+ channels.append("mono")
1734
+ return channels
1735
+
1721
1736
  @property
1722
1737
  def supports_presets(self) -> bool:
1723
1738
  """Whether preset/favorites are supported."""
@@ -412,18 +412,23 @@ class StateManager:
412
412
  self.player._eq_enabled = False
413
413
  self.player._eq_band_preset = None
414
414
  self.player._eq_is_custom = False
415
+ self.player._eq_custom_stored = False
415
416
  self.player._peq_enabled = True
416
417
  name = eq_data.get("Name")
417
418
  self.player._peq_preset = name if isinstance(name, str) and name else None
418
419
  return True
419
420
  self.player._eq_enabled = status == "on"
421
+ name = eq_data.get("Name")
422
+ if name is None:
423
+ name = eq_data.get("name")
420
424
  if status == "off":
421
425
  self.player._eq_band_preset = None
422
426
  self.player._eq_is_custom = False
427
+ # While off, an empty Name means an unsaved custom setting is stored;
428
+ # a non-empty Name is that saved preset, switched off.
429
+ self.player._eq_custom_stored = isinstance(name, str) and not name.strip()
423
430
  return True
424
- name = eq_data.get("Name")
425
- if name is None:
426
- name = eq_data.get("name")
431
+ self.player._eq_custom_stored = False
427
432
  if isinstance(name, str):
428
433
  self.player._eq_is_custom = not bool(name.strip())
429
434
  self.player._eq_band_preset = name.strip() or "Custom"
@@ -482,6 +487,7 @@ class StateManager:
482
487
  self.player._eq_enabled = None
483
488
  self.player._eq_band_preset = None
484
489
  self.player._eq_is_custom = None
490
+ self.player._eq_custom_stored = False
485
491
  self.player._peq_enabled = None
486
492
  self.player._peq_preset = None
487
493
  self.player._last_eq_status_check = 0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pywiim
3
- Version: 3.0.2
3
+ Version: 3.0.3
4
4
  Summary: Python library for WiiM/LinkPlay device communication
5
5
  Author-email: Michael Cumming <mjcumming@gmail.com>
6
6
  License: MIT
@@ -81,4 +81,5 @@ pywiim/upnp/client.py
81
81
  pywiim/upnp/eventer.py
82
82
  pywiim/upnp/health.py
83
83
  pywiim/upnp/metadata.py
84
- pywiim/upnp/playqueue.py
84
+ pywiim/upnp/playqueue.py
85
+ tests/test_release_preflight.py
@@ -0,0 +1,115 @@
1
+ """Release preflight must only reuse a successful check of the same clean tree."""
2
+
3
+ import importlib.util
4
+ import os
5
+ import subprocess
6
+ import tempfile
7
+ import unittest
8
+ from pathlib import Path
9
+ from unittest import mock
10
+
11
+ SCRIPT = Path(__file__).resolve().parents[1] / "scripts" / "prepare_release.py"
12
+ SPEC = importlib.util.spec_from_file_location("prepare_release", SCRIPT)
13
+ assert SPEC and SPEC.loader
14
+ preflight = importlib.util.module_from_spec(SPEC)
15
+ SPEC.loader.exec_module(preflight)
16
+
17
+
18
+ class ReleasePreflightTests(unittest.TestCase):
19
+ def setUp(self):
20
+ self.directory = tempfile.TemporaryDirectory()
21
+ self.addCleanup(self.directory.cleanup)
22
+ self.base = Path(self.directory.name)
23
+ self.repo = self.base / "repo"
24
+ self.repo.mkdir()
25
+ self.run_git("init", "-q")
26
+ (self.repo / "candidate.txt").write_text("first\n", encoding="utf-8")
27
+ self.commit()
28
+ self.environment = mock.patch.dict(
29
+ os.environ,
30
+ {"LOCALAPPDATA": str(self.base / "cache"), "XDG_CACHE_HOME": str(self.base / "cache")},
31
+ )
32
+ self.environment.start()
33
+ self.addCleanup(self.environment.stop)
34
+
35
+ def run_git(self, *args):
36
+ subprocess.run(
37
+ [
38
+ "git",
39
+ "-c",
40
+ "user.name=Preflight Test",
41
+ "-c",
42
+ "user.email=preflight@example.invalid",
43
+ "-c",
44
+ "commit.gpgsign=false",
45
+ "-c",
46
+ f"core.hooksPath={self.base / 'no-hooks'}",
47
+ "-C",
48
+ str(self.repo),
49
+ *args,
50
+ ],
51
+ check=True,
52
+ capture_output=True,
53
+ )
54
+
55
+ def commit(self):
56
+ self.run_git("add", "candidate.txt")
57
+ self.run_git("commit", "-q", "-m", "candidate")
58
+
59
+ def test_success_is_reused_only_for_the_same_tree(self):
60
+ with mock.patch.object(preflight, "run_checks") as checks:
61
+ self.assertTrue(preflight.prepare(self.repo))
62
+ self.assertFalse(preflight.prepare(self.repo))
63
+ self.assertEqual(checks.call_count, 1)
64
+
65
+ (self.repo / "candidate.txt").write_text("second\n", encoding="utf-8")
66
+ self.commit()
67
+ self.assertTrue(preflight.prepare(self.repo))
68
+ self.assertEqual(checks.call_count, 2)
69
+
70
+ def test_dirty_and_untracked_changes_are_rejected(self):
71
+ candidate = self.repo / "candidate.txt"
72
+ with mock.patch.object(preflight, "run_checks") as checks:
73
+ candidate.write_text("dirty\n", encoding="utf-8")
74
+ with self.assertRaisesRegex(RuntimeError, "tracked or untracked"):
75
+ preflight.prepare(self.repo)
76
+ candidate.write_text("first\n", encoding="utf-8")
77
+ (self.repo / "untracked.txt").write_text("untracked\n", encoding="utf-8")
78
+ with self.assertRaisesRegex(RuntimeError, "tracked or untracked"):
79
+ preflight.prepare(self.repo)
80
+ checks.assert_not_called()
81
+
82
+ def test_failure_and_failed_forced_rerun_are_not_cached(self):
83
+ with mock.patch.object(preflight, "run_checks") as checks:
84
+ checks.side_effect = RuntimeError("failed check")
85
+ with self.assertRaisesRegex(RuntimeError, "failed check"):
86
+ preflight.prepare(self.repo)
87
+ checks.side_effect = None
88
+ self.assertTrue(preflight.prepare(self.repo))
89
+ self.assertFalse(preflight.prepare(self.repo))
90
+
91
+ checks.side_effect = RuntimeError("failed forced check")
92
+ with self.assertRaisesRegex(RuntimeError, "failed forced check"):
93
+ preflight.prepare(self.repo, force=True)
94
+ checks.side_effect = None
95
+ self.assertTrue(preflight.prepare(self.repo))
96
+ self.assertEqual(checks.call_count, 4)
97
+
98
+ def test_changed_candidate_is_not_cached(self):
99
+ original_tree = preflight.clean_tree(self.repo)
100
+
101
+ def change_candidate(*_args):
102
+ (self.repo / "candidate.txt").write_text("new tree\n", encoding="utf-8")
103
+ self.commit()
104
+
105
+ with mock.patch.object(preflight, "run_checks", side_effect=change_candidate):
106
+ with self.assertRaisesRegex(RuntimeError, "candidate changed"):
107
+ preflight.prepare(self.repo)
108
+ self.assertFalse(preflight.cache_file(original_tree).exists())
109
+ with mock.patch.object(preflight, "run_checks") as checks:
110
+ self.assertTrue(preflight.prepare(self.repo))
111
+ checks.assert_called_once()
112
+
113
+
114
+ if __name__ == "__main__":
115
+ unittest.main()
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes