Setup temporary directories to run tests.

This commit is contained in:
Jeff Baskin 2022-06-18 22:15:20 -04:00
parent 217aea7a97
commit f761cbf56c
2 changed files with 10 additions and 2 deletions

1
.gitignore vendored
View File

@ -1,2 +1,3 @@
/target /target
*.swp *.swp
tests/data

View File

@ -2,7 +2,10 @@
from asyncio import create_subprocess_exec, get_event_loop, sleep from asyncio import create_subprocess_exec, get_event_loop, sleep
from pathlib import Path from pathlib import Path
from random import choices
from shutil import rmtree
from socket import gethostname, gethostbyname, socket from socket import gethostname, gethostbyname, socket
from string import ascii_lowercase
class Server: class Server:
@ -10,6 +13,8 @@ class Server:
def __init__(self): def __init__(self):
"""Initialization of a server.""" """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.env = {}
self.process = None self.process = None
self.loop = get_event_loop() self.loop = get_event_loop()
@ -42,9 +47,10 @@ class Server:
async def __start(self): async def __start(self):
"""async start of the server.""" """async start of the server."""
print(self.env)
self.process = await create_subprocess_exec( 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) await sleep(1)
@ -65,6 +71,7 @@ class Server:
def destroy(self): def destroy(self):
"""Removes the server instance.""" """Removes the server instance."""
self.stop() self.stop()
rmtree(self.datadir, ignore_errors=True)
def set_safe_port(self): def set_safe_port(self):
"""Set the server port to something not being used.""" """Set the server port to something not being used."""