mirror of
https://github.com/xgi/castero
synced 2024-11-10 15:28:45 +01:00
add basic config migration integrity test
This commit is contained in:
parent
a1e52a1439
commit
2c2aa3f1e8
80
tests/datafiles/working_no_comments.conf
Normal file
80
tests/datafiles/working_no_comments.conf
Normal file
@ -0,0 +1,80 @@
|
||||
[client]
|
||||
delete_feed_confirmation = False
|
||||
|
||||
reload_feeds_threshold = 10
|
||||
|
||||
disable_vertical_borders = False
|
||||
|
||||
disable_default_status = False
|
||||
|
||||
player =
|
||||
|
||||
|
||||
[feeds]
|
||||
reload_on_start = False
|
||||
|
||||
|
||||
[downloads]
|
||||
custom_download_dir =
|
||||
|
||||
|
||||
[colors]
|
||||
color_foreground = yellow
|
||||
|
||||
color_background = black
|
||||
|
||||
color_foreground_alt = white
|
||||
|
||||
color_background_alt = black
|
||||
|
||||
|
||||
[playback]
|
||||
seek_distance = 10
|
||||
|
||||
|
||||
[keys]
|
||||
key_help = h
|
||||
|
||||
key_exit = q
|
||||
|
||||
key_add_feed = a
|
||||
|
||||
key_delete = d
|
||||
|
||||
key_reload = r
|
||||
|
||||
key_save = s
|
||||
|
||||
key_up = UP
|
||||
|
||||
key_right = RIGHT
|
||||
|
||||
key_down = DOWN
|
||||
|
||||
key_left = LEFT
|
||||
|
||||
key_scroll_up = PPAGE
|
||||
|
||||
key_scroll_down = NPAGE
|
||||
|
||||
key_play_selected = ENTER
|
||||
|
||||
key_add_selected = SPACE
|
||||
|
||||
key_clear = c
|
||||
|
||||
key_next = n
|
||||
|
||||
key_invert = i
|
||||
|
||||
key_pause_play = p
|
||||
|
||||
key_pause_play_alt = k
|
||||
|
||||
key_seek_forward = f
|
||||
|
||||
key_seek_forward_alt = l
|
||||
|
||||
key_seek_backward = b
|
||||
|
||||
key_seek_backward_alt = j
|
@ -1,5 +1,8 @@
|
||||
import configparser
|
||||
import os
|
||||
from shutil import copyfile
|
||||
from unittest import mock
|
||||
from unittest.mock import patch, mock_open
|
||||
|
||||
import pytest
|
||||
|
||||
@ -16,54 +19,67 @@ def restore_default_path():
|
||||
config._Config.DEFAULT_PATH = config_default_path
|
||||
|
||||
|
||||
def test_config_default(prevent_modification):
|
||||
def test_config_default():
|
||||
myconfig = config._Config()
|
||||
assert isinstance(myconfig, config._Config)
|
||||
|
||||
|
||||
def test_config_parse_error(prevent_modification):
|
||||
def test_config_parse_error():
|
||||
config._Config.DEFAULT_PATH = my_dir + "/datafiles/parse_error.conf"
|
||||
with pytest.raises(config.ConfigParseError):
|
||||
config._Config()
|
||||
|
||||
|
||||
def test_config_incomplete_migrate(prevent_modification):
|
||||
def test_config_incomplete_migrate():
|
||||
copyfile(my_dir + "/datafiles/incomplete_error.conf", config._Config.PATH)
|
||||
myconfig = config._Config()
|
||||
assert len(myconfig) > 0
|
||||
|
||||
|
||||
def test_config_excessive_migrate(prevent_modification):
|
||||
def test_config_excessive_migrate():
|
||||
copyfile(my_dir + "/datafiles/excessive_error.conf", config._Config.PATH)
|
||||
myconfig = config._Config()
|
||||
assert "this_should_not_be_here" not in myconfig
|
||||
assert "seek_distance" in myconfig
|
||||
|
||||
|
||||
def test_config_length(prevent_modification):
|
||||
def test_config_length():
|
||||
myconfig = config._Config()
|
||||
assert type(len(myconfig) == int) and len(myconfig) > 0
|
||||
|
||||
|
||||
def test_config_iter(prevent_modification):
|
||||
def test_config_iter():
|
||||
myconfig = config._Config()
|
||||
for key in myconfig:
|
||||
assert key in myconfig
|
||||
|
||||
|
||||
def test_config_get_item(prevent_modification):
|
||||
def test_config_get_item():
|
||||
myconfig = config._Config()
|
||||
seek_distance = myconfig["seek_distance"]
|
||||
assert seek_distance is not None
|
||||
|
||||
|
||||
def test_config_try_set_item(prevent_modification):
|
||||
def test_config_try_set_item():
|
||||
myconfig = config._Config()
|
||||
myconfig["fake"] = "value"
|
||||
assert "fake" not in myconfig
|
||||
|
||||
|
||||
def test_config_del_item(prevent_modification):
|
||||
def test_config_del_item():
|
||||
myconfig = config._Config()
|
||||
del myconfig["seek_distance"]
|
||||
assert "seek_distance" not in myconfig
|
||||
|
||||
|
||||
def test_migrate_stability():
|
||||
conf = configparser.ConfigParser()
|
||||
default_conf = configparser.ConfigParser()
|
||||
default_conf.read(config._Config.DEFAULT_PATH)
|
||||
conf.read(my_dir + "/datafiles/working_no_comments.conf")
|
||||
|
||||
conf.read = mock.MagicMock()
|
||||
|
||||
with patch("builtins.open", mock_open(read_data="test")) as mock_file:
|
||||
config.Config.migrate(conf, default_conf)
|
||||
mock_file.assert_called_with(config.Config.DEFAULT_PATH, 'w')
|
||||
|
Loading…
Reference in New Issue
Block a user