Stop two tests failing on what is around them

The macOS path test set XDG_CONFIG_HOME to "/c" and asserted that "/c" was nowhere in the answer, but the home these run under is a mkdtemp path, so any TMPDIR with a "/c" in it failed the test. macOS is exactly where that happens: its temporary directories are /var/folders/<two letters>/, and one letter in thirty-six starts with c. The needle is now a word no directory can be called.

The other is the `ask` verb reading what was piped into it. Nothing was, but the runner's own stdin is not nothing either, so the verb read whatever the runner left there. It now reads an empty stream, whichever runner is in use.
This commit is contained in:
2026-09-05 09:47:50 +03:00
parent fff9cd1c55
commit fb80d85332
2 changed files with 10 additions and 2 deletions
+5
View File
@@ -9,6 +9,7 @@ socket is faked, and everything that runs locally runs for real.
import contextlib import contextlib
import io import io
import json import json
import sys
import unittest import unittest
import webbrowser import webbrowser
from typing import ClassVar from typing import ClassVar
@@ -668,7 +669,11 @@ class WithoutAnInstance(DikteTest):
def run_verb(self, argv): def run_verb(self, argv):
# launch_gui replaces this process with the application, so it never # launch_gui replaces this process with the application, so it never
# comes back in real use and must not be allowed to here. # comes back in real use and must not be allowed to here.
# `ask` with no text reads what was piped in, and the runner's own
# stdin is not that: under pytest it is an object that refuses to be
# read at all.
with mock.patch.object(ipc, "send", return_value=None), \ with mock.patch.object(ipc, "send", return_value=None), \
mock.patch.object(sys, "stdin", io.StringIO()), \
mock.patch.object(cli, "launch_gui") as launch, \ mock.patch.object(cli, "launch_gui") as launch, \
captured() as (out, err): captured() as (out, err):
code = cli.run(argv) code = cli.run(argv)
+5 -2
View File
@@ -42,9 +42,12 @@ class Directories(unittest.TestCase):
def test_a_mac_does_not_read_the_xdg_variables(self): def test_a_mac_does_not_read_the_xdg_variables(self):
"""A Mac with them set from some other tool still stores in one place.""" """A Mac with them set from some other tool still stores in one place."""
with mock.patch.dict(os.environ, {"XDG_CONFIG_HOME": "/c"}): # Something no temporary directory can be called: the home this runs
# under is a mkdtemp path, and a two-letter needle matched the "/c" in
# somebody's TMPDIR rather than the variable being read.
with mock.patch.dict(os.environ, {"XDG_CONFIG_HOME": "/xdg-elsewhere"}):
config_dir, _ = paths.directories("darwin") config_dir, _ = paths.directories("darwin")
self.assertNotIn("/c", config_dir.as_posix()) self.assertNotIn("xdg-elsewhere", config_dir.as_posix())
def test_windows_keeps_the_models_out_of_the_roaming_profile(self): def test_windows_keeps_the_models_out_of_the_roaming_profile(self):
"""Settings roam with the account; several gigabytes must not.""" """Settings roam with the account; several gigabytes must not."""