Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/moin/_tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Copyright: 2007 MoinMoin:KarolNowak
# Copyright: 2008 MoinMoin:ThomasWaldmann
# Copyright: 2008, 2010 MoinMoin:ReimarBauer
# Copyright: 2025 MoinMoin:UlrichB
# License: GNU GPL v2 (or any later version), see LICENSE.txt for details.

"""
Expand Down Expand Up @@ -97,14 +98,19 @@ def get_dirs(subdir: str) -> tuple[Path, Path]:

:param subdir: subdirectory for artifacts_dir
:returns: tuple (moin_dir, artifacts_dir)
where moin_dir is the Path to the moin directory (parent of src),
where moin_dir is the Path to the moin directory,
and artifacts_dir is the Path to moin/_test_artifacts/{subdir}
"""
my_dir = Path(__file__).parent.resolve()
moin_dir = my_dir.parents[2]
artifacts_dir = moin_dir / "_test_artifacts" / subdir
my_dir = Path(__file__).parent.resolve().parents[2]
artifacts_dir = my_dir / "_test_artifacts" / subdir
if not artifacts_dir.exists():
artifacts_dir.mkdir(parents=True)

if Path(my_dir / "src").exists:
# in this case we have a development environment
moin_dir = my_dir / "src" / "moin"
else:
moin_dir = my_dir / "moin"
return moin_dir, artifacts_dir


Expand Down
4 changes: 3 additions & 1 deletion src/moin/cli/_tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Copyright: 2023-2024 MoinMoin project
# Copyright: 2025 MoinMoin:UlrichB
# License: GNU GPL v2 (or any later version), see LICENSE.txt for details.

"""
Expand All @@ -22,6 +23,7 @@
import signal
import subprocess
import sys

from time import sleep

from moin._tests import check_connection, get_dirs
Expand Down Expand Up @@ -169,7 +171,7 @@ def do_crawl(request, artifact_dir):
crawl_success = False
if server_started:
logging.info("starting crawl")
os.chdir(moin_dir / "src" / "moin" / "cli" / "_tests" / "scrapy")
os.chdir(moin_dir / "cli" / "_tests" / "scrapy")
try:
com = ["scrapy", "crawl", "-a", f"url={settings.CRAWL_START}", "ref_checker"]
with open(get_crawl_log_path(), "wb") as crawl_log:
Expand Down
21 changes: 9 additions & 12 deletions src/moin/cli/_tests/test_modify_item.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Copyright: 2023-2024 MoinMoin project
# Copyright: 2025 MoinMoin:UlrichB
# License: GNU GPL v2 (or any later version), see LICENSE.txt for details.

"""
Expand Down Expand Up @@ -39,7 +40,7 @@ def test_welcome(welcome):
def test_dump_help(load_help):
moin_dir, artifact_dir = get_dirs("cli")
help_dir = Path("my_help")
source_help_dir = moin_dir / "src" / "moin" / "help"
source_help_dir = moin_dir / "help"
with open(source_help_dir / "help-en" / "Home.data", newline="") as f:
crlf_option = "--crlf" if "\r\n" in f.read() else "--no-crlf"
for help_subdir in ["help-common", "help-en"]:
Expand Down Expand Up @@ -77,16 +78,12 @@ def test_item_get(load_help):
moin_dir, _ = get_dirs("cli")
with open("cat.meta") as f:
meta_cat = json.load(f)
with open(moin_dir / "src" / "moin" / "help" / "help-common" / "cat.jpg.meta") as f:
with open(moin_dir / "help" / "help-common" / "cat.jpg.meta") as f:
meta_cat_expected = json.load(f)
validate_meta(
meta_cat_expected,
meta_cat,
f"{moin_dir / 'src' / 'moin' / 'help' / 'help-common' / 'cat.jpg.meta'} != cat.meta",
)
validate_meta(meta_cat_expected, meta_cat, f"{moin_dir / 'help' / 'help-common' / 'cat.jpg.meta'} != cat.meta")
with open("cat.data", "rb") as f:
cat_bytes = f.read()
with open(moin_dir / "src" / "moin" / "help" / "help-common" / "cat.jpg.data", "rb") as f:
with open(moin_dir / "help" / "help-common" / "cat.jpg.data", "rb") as f:
cat_bytes_expected = f.read()
assert cat_bytes_expected == cat_bytes

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

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

def test_validate_metadata_missing_rev_num(index_create2):
moin_dir, _ = get_dirs("")
data_dir = moin_dir / "src" / "moin" / "cli" / "_tests" / "data"
data_dir = moin_dir / "cli" / "_tests" / "data"
item_put = run(["moin", "item-put", "-m", data_dir / "MyPage-vblank.meta", "-d", data_dir / "MyPage-v1.data", "-o"])
assert_p_succcess(item_put)
sleep(1.1) # MTIME is stored as int in index file, sleep here to guarntee proper sorting of revs for index_revision
Expand Down
6 changes: 3 additions & 3 deletions src/moin/cli/_tests/test_serialization.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Copyright: 2023 MoinMoin project
# Copyright: 2024 MoinMoin:UlrichB
# Copyright: 2024-2025 MoinMoin:UlrichB
# License: GNU GPL v2 (or any later version), see LICENSE.txt for details.

"""
Expand Down Expand Up @@ -50,7 +50,7 @@ def test_save_default_ns(artifact_dir, save_default):

def test_load_default_ns(artifact_dir, save_default):
moin_dir, _ = get_dirs("")
welcome_dir = moin_dir / "src" / "moin" / "help" / "welcome"
welcome_dir = moin_dir / "help" / "welcome"
expected_metas = {}
for data_fn in welcome_dir.glob("*.meta"):
with open(data_fn) as f:
Expand Down Expand Up @@ -105,7 +105,7 @@ def test_load_new_ns(artifact_dir, save_default):

def test_load_corrupt(artifact_dir2, index_create2):
moin_dir, _ = get_dirs("cli")
data_dir = moin_dir / "src" / "moin" / "cli" / "_tests" / "data"
data_dir = moin_dir / "cli" / "_tests" / "data"
# item-put below errors out without the -o, see moin.storage.backends.stores.store
p = run(["moin", "item-put", "-m", data_dir / "Corrupt.meta", "-d", data_dir / "Corrupt.data", "-o"])
assert_p_succcess(p)
Expand Down
2 changes: 1 addition & 1 deletion src/moin/cli/_tests/test_set_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

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