Skip to content

Commit

Permalink
Rework server CLI tests to actually count for coverage (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
pydsigner committed Dec 21, 2023
1 parent dce5e94 commit b3b1fc6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/anchovy/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def serve(port: int, directory: str | pathlib.Path, host: str = 'localhost'):
httpd.serve_forever()


def main():
def main(arguments: list[str] | None = None):
parser = argparse.ArgumentParser()
parser.add_argument('-p', '--port',
help='port to serve from',
Expand All @@ -96,7 +96,7 @@ def main():
help='directory to serve',
type=pathlib.Path,
default='.')
args = parser.parse_args()
args = parser.parse_args(arguments)
serve(args.port, args.directory)


Expand Down
12 changes: 4 additions & 8 deletions test/test_server.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import contextlib
import pathlib
import socket
import subprocess
import sys
import threading

import pytest
import requests

from anchovy.server import ThreadedHTTPServer
from anchovy.server import main, ThreadedHTTPServer
from anchovy.test_harness import run_example


Expand Down Expand Up @@ -36,14 +34,12 @@ def run_server(directory: pathlib.Path, port: int):
@contextlib.contextmanager
def run_server_cli(directory: pathlib.Path, port: int):
args = [
sys.executable, '-m', 'anchovy.server',
'--port', str(port),
'--directory', str(directory)
]
with subprocess.Popen(args) as proc:
yield
proc.terminate()

thread = threading.Thread(target=main, args=(args,), daemon=True)
thread.start()
yield


@pytest.fixture(scope='module', params=[False, True])
Expand Down

0 comments on commit b3b1fc6

Please sign in to comment.