Setup temporary directories to run tests.
This commit is contained in:
parent
217aea7a97
commit
f761cbf56c
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,2 +1,3 @@
|
||||
/target
|
||||
*.swp
|
||||
tests/data
|
||||
|
@ -2,7 +2,10 @@
|
||||
|
||||
from asyncio import create_subprocess_exec, get_event_loop, sleep
|
||||
from pathlib import Path
|
||||
from random import choices
|
||||
from shutil import rmtree
|
||||
from socket import gethostname, gethostbyname, socket
|
||||
from string import ascii_lowercase
|
||||
|
||||
|
||||
class Server:
|
||||
@ -10,6 +13,8 @@ class Server:
|
||||
|
||||
def __init__(self):
|
||||
"""Initialization of a server."""
|
||||
self.datadir = Path.cwd().joinpath("tests", "data", "".join(choices(ascii_lowercase, k=5)))
|
||||
self.datadir.mkdir(parents=True)
|
||||
self.env = {}
|
||||
self.process = None
|
||||
self.loop = get_event_loop()
|
||||
@ -42,9 +47,10 @@ class Server:
|
||||
|
||||
async def __start(self):
|
||||
"""async start of the server."""
|
||||
print(self.env)
|
||||
self.process = await create_subprocess_exec(
|
||||
Path.cwd().joinpath("target", "release", "morethantext_web"), env=self.env
|
||||
Path.cwd().joinpath("target", "release", "morethantext_web"),
|
||||
env=self.env,
|
||||
cwd=self.datadir
|
||||
)
|
||||
await sleep(1)
|
||||
|
||||
@ -65,6 +71,7 @@ class Server:
|
||||
def destroy(self):
|
||||
"""Removes the server instance."""
|
||||
self.stop()
|
||||
rmtree(self.datadir, ignore_errors=True)
|
||||
|
||||
def set_safe_port(self):
|
||||
"""Set the server port to something not being used."""
|
||||
|
Loading…
Reference in New Issue
Block a user