Esempio n. 1
0
def test_ctxrc_save(open_mock):
    file = mock.MagicMock()
    open_mock.return_value = file
    file.__enter__ = mock.MagicMock()
    write_fn = mock.MagicMock()
    file.__enter__.return_value = write_fn

    ctxrc = CtxRc({})
    ctxrc.save('/some/path')

    open_mock.assert_called_once_with('/some/path', 'w')
    write_fn.write.assert_called_once_with('{}')
Esempio n. 2
0
def test_ctxrc_from_path_no_file(open_mock):
    open_mock.side_effect = FileNotFoundError()

    ctxrc = CtxRc.from_path('/some/path')
    assert ctxrc.ctxrc_dict['version'] == 1
    assert ctxrc.ctxrc_dict['types'] == {}
    assert ctxrc.available_types == set()
Esempio n. 3
0
def test_ctxrc_from_path(open_mock):
    file = mock.MagicMock()
    open_mock.return_value = file
    file.__enter__ = mock.MagicMock()
    read_fn = mock.MagicMock()
    file.__enter__.return_value = read_fn
    read_fn.read.return_value = JSON_STR

    ctxrc = CtxRc.from_path('/some/path')
    open_mock.assert_called_once_with('/some/path', 'r')
    assert ctxrc.get_type_argv('type1') == ['something']
    assert ctxrc.ctxrc_dict['version'] == 1
    assert ctxrc.available_types == {'type1'}
Esempio n. 4
0
def test_ctxrc_available_types_no_types():
    ctxrc = CtxRc({})
    assert ctxrc.available_types == set()
Esempio n. 5
0
def test_ctxrc_available_types_no_dict():
    ctxrc = CtxRc(None)
    assert ctxrc.available_types == set()
Esempio n. 6
0
def test_ctxrc_add_type():
    ctxrc = CtxRc({})
    ctxrc.add_type('type', ['args'])
    assert ctxrc.get_type_argv('type') == ['args']
    assert ctxrc.available_types == {'type'}
Esempio n. 7
0
def test_ctxrc_type_doesnt_exist():
    ctxrc = CtxRc({})
    with pytest.raises(TypeArgDoesNotExistException):
        ctxrc.get_type_argv('not_existent')