Commit 582fcd3a authored by Matt Traudt's avatar Matt Traudt
Browse files

Stop assuming that the datadir is $dotsbws/datadir and use config

parent 19b68b95
......@@ -4,7 +4,6 @@ from sbws.util.config import get_config
from sbws.lib.resultdump import load_recent_results_in_datadir
from sbws.lib.resultdump import ResultSuccess
from statistics import median
import os
def test_generate_no_dotsbws(tmpdir, parser, log):
......@@ -34,7 +33,7 @@ def test_generate_no_datadir(empty_dotsbws, parser, log):
else:
assert None, 'Should have failed'
lines = [l for l in log.test_get_logged_lines()]
dd = os.path.join(dotsbws.name, 'datadir')
dd = conf['paths']['datadir']
assert '{} does not exist'.format(dd) in lines[-1]
......@@ -71,7 +70,7 @@ def test_generate_single_error(dotsbws_error_result, parser, log):
conf = get_config(args, log.debug)
sbws.commands.generate.main(args, conf, log)
log_lines = [l for l in log.test_get_logged_lines()]
dd = os.path.join(dotsbws.name, 'datadir')
dd = conf['paths']['datadir']
for line in log_lines:
if 'Read 0 lines from {}'.format(dd) in line:
break
......@@ -88,7 +87,7 @@ def test_generate_single_success_noscale(dotsbws_success_result, parser, log,
'-d {} -vvvv generate'.format(dotsbws.name).split())
conf = get_config(args, log.debug)
sbws.commands.generate.main(args, conf, log)
dd = os.path.join(dotsbws.name, 'datadir')
dd = conf['paths']['datadir']
results = load_recent_results_in_datadir(
1, dd, success_only=False, log_fn=log.debug)
assert len(results) == 1, 'There should be one result in the datadir'
......@@ -120,7 +119,7 @@ def test_generate_single_success_scale(dotsbws_success_result, parser, log,
'-d {} -vvvv generate --scale'.format(dotsbws.name).split())
conf = get_config(args, log.debug)
sbws.commands.generate.main(args, conf, log)
dd = os.path.join(dotsbws.name, 'datadir')
dd = conf['paths']['datadir']
results = load_recent_results_in_datadir(
1, dd, success_only=False, log_fn=log.debug)
assert len(results) == 1, 'There should be one result in the datadir'
......
......@@ -9,6 +9,22 @@ from tempfile import TemporaryDirectory
import pytest
import os
import time
import argparse
class _PseudoArguments(argparse.Namespace):
'''
Just enough of the argparse.Namespace (what you get when you do
args = parser.parse_args()) to make get_config() happy
>>> args = _PseudoArguments(directory='/home/matt/.sbws')
>>> args.directory
'/home/matt/.sbws'
'''
def __init__(self, **kw):
for key in kw:
setattr(self, key, kw[key])
class MockPastlyLogger:
......@@ -80,8 +96,10 @@ def empty_dotsbws_datadir(empty_dotsbws):
'''
Creates a ~/.sbws with nothing in it but a config.ini and an empty datadir
'''
dname = os.path.join(empty_dotsbws.name, 'datadir')
os.makedirs(dname, exist_ok=False)
args = _PseudoArguments(directory=empty_dotsbws.name)
conf = get_config(args)
dd = conf['paths']['datadir']
os.makedirs(dd, exist_ok=False)
return empty_dotsbws
......@@ -101,7 +119,9 @@ def dotsbws_error_result(empty_dotsbws_datadir):
t = time.time()
relay = Result.Relay(fp1, nick, relay_ip)
result = ResultError(relay, circ, server_ip, client_nick, t=t, msg=msg)
dd = os.path.join(empty_dotsbws_datadir.name, 'datadir')
args = _PseudoArguments(directory=empty_dotsbws_datadir.name)
conf = get_config(args)
dd = conf['paths']['datadir']
write_result_to_datadir(result, dd)
return empty_dotsbws_datadir
......@@ -124,6 +144,8 @@ def dotsbws_success_result(empty_dotsbws_datadir):
relay = Result.Relay(fp1, nick, relay_ip)
result = ResultSuccess(rtts, downloads, relay, circ, server_ip,
client_nick, t=t)
dd = os.path.join(empty_dotsbws_datadir.name, 'datadir')
args = _PseudoArguments(directory=empty_dotsbws_datadir.name)
conf = get_config(args)
dd = conf['paths']['datadir']
write_result_to_datadir(result, dd)
return empty_dotsbws_datadir
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment