updated test to compare original and saved config file
This commit is contained in:
parent
93ee9fcff1
commit
092581bf32
2 changed files with 19 additions and 23 deletions
|
@ -1,10 +1,10 @@
|
||||||
import os
|
import os
|
||||||
import json
|
import json
|
||||||
|
|
||||||
|
import tempfile
|
||||||
from twisted.trial import unittest
|
from twisted.trial import unittest
|
||||||
from lbrynet import conf
|
from lbrynet import conf
|
||||||
from lbrynet.core.Error import InvalidCurrencyError
|
from lbrynet.core.Error import InvalidCurrencyError
|
||||||
from lbrynet.tests.util import create_conf_file, remove_conf_file
|
|
||||||
|
|
||||||
class SettingsTest(unittest.TestCase):
|
class SettingsTest(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
@ -79,25 +79,29 @@ class SettingsTest(unittest.TestCase):
|
||||||
self.assertEqual(str, type(conf.default_data_dir))
|
self.assertEqual(str, type(conf.default_data_dir))
|
||||||
self.assertEqual(str, type(conf.default_lbryum_dir))
|
self.assertEqual(str, type(conf.default_lbryum_dir))
|
||||||
|
|
||||||
def test_load_save_load_config_file(self):
|
def test_load_save_config_file(self):
|
||||||
conf_entry = 'lbryum_servers: ["localhost:50001", "localhost:50002"]\n'
|
# setup settings
|
||||||
conf_temp = create_conf_file(conf_entry)
|
|
||||||
conf.conf_file = conf_temp
|
|
||||||
adjustable_settings = {'data_dir': (str, conf.default_data_dir),
|
adjustable_settings = {'data_dir': (str, conf.default_data_dir),
|
||||||
'lbryum_servers': (list, [('localhost', 5001)],
|
'lbryum_servers': (list, [('localhost', 5001)],
|
||||||
conf.server_list, conf.server_list_reverse)}
|
conf.server_list, conf.server_list_reverse)}
|
||||||
env = conf.Env(**adjustable_settings)
|
env = conf.Env(**adjustable_settings)
|
||||||
settings = conf.Config({}, adjustable_settings, environment=env)
|
settings = conf.Config({}, adjustable_settings, environment=env)
|
||||||
conf.settings = settings
|
conf.settings = settings
|
||||||
|
# setup tempfile
|
||||||
|
conf_entry = "lbryum_servers: ['localhost:50001', 'localhost:50002']\n"
|
||||||
|
with tempfile.NamedTemporaryFile(suffix='.yml') as conf_file:
|
||||||
|
conf_file.write(conf_entry)
|
||||||
|
conf_file.seek(0)
|
||||||
|
conf.conf_file = conf_file.name
|
||||||
|
# load and save settings from conf file
|
||||||
settings.load_conf_file_settings()
|
settings.load_conf_file_settings()
|
||||||
first = settings.get('lbryum_servers', data_type=conf.TYPE_PERSISTED)
|
|
||||||
settings.save_conf_file_settings()
|
settings.save_conf_file_settings()
|
||||||
try:
|
# test if overwritten entry equals original entry
|
||||||
settings.load_conf_file_settings()
|
# use decoded versions, because format might change without
|
||||||
except Exception, e:
|
# changing the interpretation
|
||||||
remove_conf_file(conf_temp)
|
decoder = conf.settings_decoders['.yml']
|
||||||
raise Exception(e)
|
conf_decoded = decoder(conf_entry)
|
||||||
second = settings.get('lbryum_servers', data_type=conf.TYPE_PERSISTED)
|
conf_entry_new = conf_file.read()
|
||||||
remove_conf_file(conf_temp)
|
conf_decoded_new = decoder(conf_entry_new)
|
||||||
self.assertEqual(first, second)
|
self.assertEqual(conf_decoded, conf_decoded_new)
|
||||||
|
|
||||||
|
|
|
@ -19,14 +19,6 @@ DEFAULT_ISO_TIME = time.mktime(DEFAULT_TIMESTAMP.timetuple())
|
||||||
|
|
||||||
log = logging.getLogger("lbrynet.tests.util")
|
log = logging.getLogger("lbrynet.tests.util")
|
||||||
|
|
||||||
def create_conf_file(entry):
|
|
||||||
with tempfile.NamedTemporaryFile(delete=False, suffix='.yml') as conf:
|
|
||||||
conf.write(entry)
|
|
||||||
return conf.name
|
|
||||||
|
|
||||||
def remove_conf_file(filename):
|
|
||||||
os.remove(filename)
|
|
||||||
|
|
||||||
def mk_db_and_blob_dir():
|
def mk_db_and_blob_dir():
|
||||||
db_dir = tempfile.mkdtemp()
|
db_dir = tempfile.mkdtemp()
|
||||||
blob_dir = tempfile.mkdtemp()
|
blob_dir = tempfile.mkdtemp()
|
||||||
|
|
Loading…
Add table
Reference in a new issue