Skip to content

Commit 4243862

Browse files
committed
Improve moin_dir setting to fix tox tests
1 parent e5aa7c3 commit 4243862

File tree

5 files changed

+26
-21
lines changed

5 files changed

+26
-21
lines changed

src/moin/_tests/__init__.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Copyright: 2007 MoinMoin:KarolNowak
22
# Copyright: 2008 MoinMoin:ThomasWaldmann
33
# Copyright: 2008, 2010 MoinMoin:ReimarBauer
4+
# Copyright: 2025 MoinMoin:UlrichB
45
# License: GNU GPL v2 (or any later version), see LICENSE.txt for details.
56

67
"""
@@ -97,14 +98,19 @@ def get_dirs(subdir: str) -> tuple[Path, Path]:
9798
9899
:param subdir: subdirectory for artifacts_dir
99100
:returns: tuple (moin_dir, artifacts_dir)
100-
where moin_dir is the Path to the moin directory (parent of src),
101+
where moin_dir is the Path to the moin directory,
101102
and artifacts_dir is the Path to moin/_test_artifacts/{subdir}
102103
"""
103-
my_dir = Path(__file__).parent.resolve()
104-
moin_dir = my_dir.parents[2]
105-
artifacts_dir = moin_dir / "_test_artifacts" / subdir
104+
my_dir = Path(__file__).parent.resolve().parents[2]
105+
artifacts_dir = my_dir / "_test_artifacts" / subdir
106106
if not artifacts_dir.exists():
107107
artifacts_dir.mkdir(parents=True)
108+
109+
if Path(my_dir / "src").exists:
110+
# in this case we have a development environment
111+
moin_dir = my_dir / "src" / "moin"
112+
else:
113+
moin_dir = my_dir / "moin"
108114
return moin_dir, artifacts_dir
109115

110116

src/moin/cli/_tests/conftest.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Copyright: 2023-2024 MoinMoin project
2+
# Copyright: 2025 MoinMoin:UlrichB
23
# License: GNU GPL v2 (or any later version), see LICENSE.txt for details.
34

45
"""
@@ -22,6 +23,7 @@
2223
import signal
2324
import subprocess
2425
import sys
26+
2527
from time import sleep
2628

2729
from moin._tests import check_connection, get_dirs
@@ -169,7 +171,7 @@ def do_crawl(request, artifact_dir):
169171
crawl_success = False
170172
if server_started:
171173
logging.info("starting crawl")
172-
os.chdir(moin_dir / "src" / "moin" / "cli" / "_tests" / "scrapy")
174+
os.chdir(moin_dir / "cli" / "_tests" / "scrapy")
173175
try:
174176
com = ["scrapy", "crawl", "-a", f"url={settings.CRAWL_START}", "ref_checker"]
175177
with open(get_crawl_log_path(), "wb") as crawl_log:

src/moin/cli/_tests/test_modify_item.py

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Copyright: 2023-2024 MoinMoin project
2+
# Copyright: 2025 MoinMoin:UlrichB
23
# License: GNU GPL v2 (or any later version), see LICENSE.txt for details.
34

45
"""
@@ -39,7 +40,7 @@ def test_welcome(welcome):
3940
def test_dump_help(load_help):
4041
moin_dir, artifact_dir = get_dirs("cli")
4142
help_dir = Path("my_help")
42-
source_help_dir = moin_dir / "src" / "moin" / "help"
43+
source_help_dir = moin_dir / "help"
4344
with open(source_help_dir / "help-en" / "Home.data", newline="") as f:
4445
crlf_option = "--crlf" if "\r\n" in f.read() else "--no-crlf"
4546
for help_subdir in ["help-common", "help-en"]:
@@ -77,16 +78,12 @@ def test_item_get(load_help):
7778
moin_dir, _ = get_dirs("cli")
7879
with open("cat.meta") as f:
7980
meta_cat = json.load(f)
80-
with open(moin_dir / "src" / "moin" / "help" / "help-common" / "cat.jpg.meta") as f:
81+
with open(moin_dir / "help" / "help-common" / "cat.jpg.meta") as f:
8182
meta_cat_expected = json.load(f)
82-
validate_meta(
83-
meta_cat_expected,
84-
meta_cat,
85-
f"{moin_dir / 'src' / 'moin' / 'help' / 'help-common' / 'cat.jpg.meta'} != cat.meta",
86-
)
83+
validate_meta(meta_cat_expected, meta_cat, f"{moin_dir / 'help' / 'help-common' / 'cat.jpg.meta'} != cat.meta")
8784
with open("cat.data", "rb") as f:
8885
cat_bytes = f.read()
89-
with open(moin_dir / "src" / "moin" / "help" / "help-common" / "cat.jpg.data", "rb") as f:
86+
with open(moin_dir / "help" / "help-common" / "cat.jpg.data", "rb") as f:
9087
cat_bytes_expected = f.read()
9188
assert cat_bytes_expected == cat_bytes
9289

@@ -104,7 +101,7 @@ def test_item_put(index_create2):
104101
)
105102
assert item_get_fail.returncode != 0
106103
moin_dir, _ = get_dirs("")
107-
data_dir = moin_dir / "src" / "moin" / "cli" / "_tests" / "data"
104+
data_dir = moin_dir / "cli" / "_tests" / "data"
108105
item_put = run(
109106
["moin", "item-put", "-m", data_dir / f"{page_filename}.meta", "-d", data_dir / f"{page_filename}.data"]
110107
)
@@ -131,7 +128,7 @@ def test_item_rev(index_create2):
131128
* MyPage-v2 has newline at end in storage (size = 18)
132129
* in both cases, item-get will write file with \n at end of file"""
133130
moin_dir, _ = get_dirs("cli2")
134-
data_dir = moin_dir / "src" / "moin" / "cli" / "_tests" / "data"
131+
data_dir = moin_dir / "cli" / "_tests" / "data"
135132
put1 = run(["moin", "item-put", "-m", data_dir / "MyPage-v1.meta", "-d", data_dir / "MyPage-v1.data", "-o"])
136133
assert_p_succcess(put1)
137134
sleep(1.1) # MTIME is stored as int in index file, sleep here to guarntee proper sorting of revs for index_revision
@@ -170,7 +167,7 @@ def test_item_rev(index_create2):
170167

171168
def test_validate_metadata(index_create2):
172169
moin_dir, _ = get_dirs("")
173-
data_dir = moin_dir / "src" / "moin" / "cli" / "_tests" / "data"
170+
data_dir = moin_dir / "cli" / "_tests" / "data"
174171
item_put = run(["moin", "item-put", "-m", data_dir / "MyPage-v1.meta", "-d", data_dir / "MyPage-v1.data", "-o"])
175172
assert_p_succcess(item_put)
176173
sleep(1.1) # MTIME is stored as int in index file, sleep here to guarntee proper sorting of revs for index_revision
@@ -260,7 +257,7 @@ def test_validate_metadata(index_create2):
260257

261258
def test_validate_metadata_missing_rev_num(index_create2):
262259
moin_dir, _ = get_dirs("")
263-
data_dir = moin_dir / "src" / "moin" / "cli" / "_tests" / "data"
260+
data_dir = moin_dir / "cli" / "_tests" / "data"
264261
item_put = run(["moin", "item-put", "-m", data_dir / "MyPage-vblank.meta", "-d", data_dir / "MyPage-v1.data", "-o"])
265262
assert_p_succcess(item_put)
266263
sleep(1.1) # MTIME is stored as int in index file, sleep here to guarntee proper sorting of revs for index_revision

src/moin/cli/_tests/test_serialization.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Copyright: 2023 MoinMoin project
2-
# Copyright: 2024 MoinMoin:UlrichB
2+
# Copyright: 2024-2025 MoinMoin:UlrichB
33
# License: GNU GPL v2 (or any later version), see LICENSE.txt for details.
44

55
"""
@@ -50,7 +50,7 @@ def test_save_default_ns(artifact_dir, save_default):
5050

5151
def test_load_default_ns(artifact_dir, save_default):
5252
moin_dir, _ = get_dirs("")
53-
welcome_dir = moin_dir / "src" / "moin" / "help" / "welcome"
53+
welcome_dir = moin_dir / "help" / "welcome"
5454
expected_metas = {}
5555
for data_fn in welcome_dir.glob("*.meta"):
5656
with open(data_fn) as f:
@@ -105,7 +105,7 @@ def test_load_new_ns(artifact_dir, save_default):
105105

106106
def test_load_corrupt(artifact_dir2, index_create2):
107107
moin_dir, _ = get_dirs("cli")
108-
data_dir = moin_dir / "src" / "moin" / "cli" / "_tests" / "data"
108+
data_dir = moin_dir / "cli" / "_tests" / "data"
109109
# item-put below errors out without the -o, see moin.storage.backends.stores.store
110110
p = run(["moin", "item-put", "-m", data_dir / "Corrupt.meta", "-d", data_dir / "Corrupt.data", "-o"])
111111
assert_p_succcess(p)

src/moin/cli/_tests/test_set_meta.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
def test_set_meta(index_create2):
1414
moin_dir, _ = get_dirs("")
15-
data_dir = moin_dir / "src" / "moin" / "cli" / "_tests" / "data"
15+
data_dir = moin_dir / "cli" / "_tests" / "data"
1616
put = run(["moin", "item-put", "-m", data_dir / "Home.meta", "-d", data_dir / "Home.data", "-o"])
1717
assert_p_succcess(put)
1818
set_meta = run(["moin", "maint-set-meta", "-q", "Home", "-k", NAME, "-v", '["Home", "AnotherName"]'])

0 commit comments

Comments
 (0)