mirror of
https://github.com/Akkudoktor-EOS/EOS.git
synced 2026-11-13 09:13:30 +01:00
fix: keep tests and doc generators away from the developer's config files
test_docsphinx pointed EOS_DIR/EOS_CONFIG_DIR at an empty temporary directory. EOS then fell back to the config file in the user config directory, migrated it and wrote it back with a timestamped backup. The test now writes an empty config file into the temporary directory, as server_base does. Additional fixes - Decode the Sphinx output in test_sphinx_build as UTF-8; on Windows the default code page failed and the test reported a NoneType error. - Check the user config directory with the app author in --check-config-side-effect, as EOS does; on Windows the check looked at the wrong directory. - Let the doc generators create EOS' config file in a temporary directory. They left an EOS.config.json in the working directory, and a following make test-ci then failed in every test. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
d68f040206
commit
c230d9d9de
@@ -6,6 +6,7 @@ import json
|
|||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
|
import tempfile
|
||||||
import textwrap
|
import textwrap
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Any, Optional, Type, TypeVar, Union, get_args
|
from typing import Any, Optional, Type, TypeVar, Union, get_args
|
||||||
@@ -524,4 +525,9 @@ def main():
|
|||||||
ConfigEOS._force_documentation_mode = False
|
ConfigEOS._force_documentation_mode = False
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
# EOS creates a config file if it finds none. Let it do so in a temporary
|
||||||
|
# directory, not in the working directory (e.g. the repository root).
|
||||||
|
with tempfile.TemporaryDirectory(prefix="eos-docs-") as eos_dir:
|
||||||
|
os.environ["EOS_DIR"] = eos_dir
|
||||||
|
os.environ["EOS_CONFIG_DIR"] = eos_dir
|
||||||
main()
|
main()
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ import argparse
|
|||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
import tempfile
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
# Add the src directory to sys.path so import akkudoktoreos works in all cases
|
# Add the src directory to sys.path so import akkudoktoreos works in all cases
|
||||||
@@ -101,4 +102,9 @@ def main():
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
# EOS creates a config file if it finds none. Let it do so in a temporary
|
||||||
|
# directory, not in the working directory (e.g. the repository root).
|
||||||
|
with tempfile.TemporaryDirectory(prefix="eos-docs-") as eos_dir:
|
||||||
|
os.environ["EOS_DIR"] = eos_dir
|
||||||
|
os.environ["EOS_CONFIG_DIR"] = eos_dir
|
||||||
main()
|
main()
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import argparse
|
|||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
import tempfile
|
||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
import git
|
import git
|
||||||
@@ -318,4 +319,9 @@ def main():
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
# EOS creates a config file if it finds none. Let it do so in a temporary
|
||||||
|
# directory, not in the working directory (e.g. the repository root).
|
||||||
|
with tempfile.TemporaryDirectory(prefix="eos-docs-") as eos_dir:
|
||||||
|
os.environ["EOS_DIR"] = eos_dir
|
||||||
|
os.environ["EOS_CONFIG_DIR"] = eos_dir
|
||||||
main()
|
main()
|
||||||
|
|||||||
+2
-1
@@ -211,7 +211,8 @@ def cfg_non_existent(request):
|
|||||||
# Before test
|
# Before test
|
||||||
from platformdirs import user_config_dir
|
from platformdirs import user_config_dir
|
||||||
|
|
||||||
user_dir = user_config_dir(ConfigEOS.APP_NAME)
|
# The same directory as ConfigEOS uses (app author matters on Windows).
|
||||||
|
user_dir = user_config_dir(ConfigEOS.APP_NAME, ConfigEOS.APP_AUTHOR)
|
||||||
user_config_file = Path(user_dir).joinpath(ConfigEOS.CONFIG_FILE_NAME)
|
user_config_file = Path(user_dir).joinpath(ConfigEOS.CONFIG_FILE_NAME)
|
||||||
cwd_config_file = Path.cwd().joinpath(ConfigEOS.CONFIG_FILE_NAME)
|
cwd_config_file = Path.cwd().joinpath(ConfigEOS.CONFIG_FILE_NAME)
|
||||||
assert not user_config_file.exists(), (
|
assert not user_config_file.exists(), (
|
||||||
|
|||||||
@@ -138,6 +138,9 @@ class TestSphinxDocumentation:
|
|||||||
env = os.environ.copy()
|
env = os.environ.copy()
|
||||||
env["EOS_DIR"] = eos_dir
|
env["EOS_DIR"] = eos_dir
|
||||||
env["EOS_CONFIG_DIR"] = eos_dir
|
env["EOS_CONFIG_DIR"] = eos_dir
|
||||||
|
# An empty config file, so EOS does not fall back to (and migrate) the
|
||||||
|
# user's own config file in the user config directory.
|
||||||
|
Path(eos_dir, "EOS.config.json").write_text("{}", encoding="utf-8")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
process = subprocess.run(
|
process = subprocess.run(
|
||||||
@@ -146,7 +149,10 @@ class TestSphinxDocumentation:
|
|||||||
env=env,
|
env=env,
|
||||||
stdout=subprocess.PIPE,
|
stdout=subprocess.PIPE,
|
||||||
stderr=subprocess.PIPE,
|
stderr=subprocess.PIPE,
|
||||||
text=True,
|
# Sphinx writes UTF-8; the platform default (e.g. cp1252 on
|
||||||
|
# Windows) cannot decode it.
|
||||||
|
encoding="utf-8",
|
||||||
|
errors="replace",
|
||||||
cwd=DIR_PROJECT_ROOT, # use the existing constant
|
cwd=DIR_PROJECT_ROOT, # use the existing constant
|
||||||
)
|
)
|
||||||
output = process.stdout + "\n" + process.stderr
|
output = process.stdout + "\n" + process.stderr
|
||||||
|
|||||||
Reference in New Issue
Block a user