Source

pida-hacks / tests / core / test_options.py

Full commit
import pytest
from mock import Mock
from pida.core.environment import settings_dir, workspace_name
from pida.core.options import OptionsConfig, workspace_dir, list_workspaces


def test_opt():
    svc = Mock()
    svc.get_name.return_value = 'test'
    options = OptionsConfig(svc)
    options.dump(workspace=False)
    fp = settings_dir(options.name)

    assert fp.check()
    assert fp.read() == '{}'

    options.create_option(
        name='test',
        type=str,
        label='test',
        default='test',
        doc='test',
    )

    options.create_option(
        name='test_workspace',
        type=str,
        label='test2',
        default='test',
        doc='test',
        workspace=True,
    )

    options.dump(workspace=False)
    assert fp.read() == '{\n  "test": "test"\n}'
    options.set_value('test', 'tset')
    assert fp.read() == '{\n  "test": "tset"\n}'

    options.dump(workspace=True)
    content = workspace_dir(options.name).read()
    assert content == '{\n  "test_workspace": "test"\n}'


def test_list_workspaces():
    workspace_dir()
    assert list_workspaces() == ['default']
    settings_dir('workspaces').ensure('test', dir=1)
    assert list_workspaces() == ['default', 'test']

def test_workspace_dir():
    s = settings_dir()
    w = workspace_dir()
    assert w == s/'workspaces'/workspace_name()