-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: extract smoketest command from readme (#468)
tests: extract smoketest command from readme Fixes #463 misc.
- Loading branch information
Showing
9 changed files
with
87 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
from collections.abc import Sequence | ||
from pathlib import Path | ||
|
||
import invoke as inv | ||
|
||
from memium.subtasks.graphite import submit_pr # noqa: F401 # type: ignore | ||
|
||
|
||
def get_code_blocks_from_md(md_path: Path) -> Sequence[str]: | ||
md = md_path.read_text() | ||
code_blocks = md.split("```")[1::2] | ||
return code_blocks | ||
|
||
|
||
def create_smoketest_dir() -> Path: | ||
print("💨 Running smoketest") | ||
input_dir = Path.home() / "smoketest_dir" | ||
input_dir.mkdir(exist_ok=True) | ||
|
||
test_file = input_dir / "test.md" | ||
test_file.write_text("Q. Question here\nA. Answer!") | ||
return input_dir | ||
|
||
|
||
@inv.task # type: ignore | ||
def smoketest_docker(c: inv.Context): | ||
input_dir = create_smoketest_dir() | ||
|
||
code_blocks = get_code_blocks_from_md(Path("readme.md")) | ||
docker_block = next(block for block in code_blocks if "docker run" in block) | ||
|
||
# Only keep content after docker line | ||
docker_block = docker_block[docker_block.index("docker run") :] | ||
replaced_input_dir = docker_block.replace("$INPUT_DIR", str(input_dir)) | ||
|
||
smoketest_docker_command = ( | ||
replaced_input_dir + " --dry-run \\\n" + " --skip-sync" | ||
) | ||
|
||
print(smoketest_docker_command) | ||
|
||
c.run("docker build . -t memium:latest -f Dockerfile") | ||
c.run("docker volume create ankidecks") | ||
c.run(smoketest_docker_command) | ||
print("💨🎉 Smoketest complete") | ||
|
||
|
||
@inv.task # type: ignore | ||
def smoketest_cli(c: inv.Context): | ||
smoketest_dir = create_smoketest_dir() | ||
code_blocks = get_code_blocks_from_md(Path("readme.md")) | ||
cli_block = next(block for block in code_blocks if "cli-block" in block) | ||
sanitised_cli_block = cli_block.splitlines()[1].replace("> ", "") | ||
|
||
cli_smoketest_cmd = sanitised_cli_block.replace( | ||
"[YOUR_INPUT_DIR]", str(smoketest_dir) | ||
) | ||
print(cli_smoketest_cmd) | ||
c.run(cli_smoketest_cmd + " --dry-run \\\n" + " --skip-sync") | ||
print("💨🎉 Smoketest complete") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters