示例#1
0
def test_copy_config():
    cfg = ServerConfig(name='TEST')
    assert cfg.name == 'TEST'

    cfg2 = cfg.copy()
    assert cfg2 is not cfg
    assert cfg2.name == 'TEST'

    cfg.name = 'MUH'
    assert cfg.name != cfg2.name
示例#2
0
def test_inbuilt_dir():
    cfg = ServerConfig(name='TEST')
    valid_keys = ServerConfig._valid_keys
    list_attr = dir(cfg)
    assert isinstance(list_attr, list)
    assert set(dir(object)).issubset(set(list_attr))
    assert set(valid_keys).issubset(set(list_attr))
    assert set(list(cfg.__dict__.keys())).issubset(set(list_attr))
示例#3
0
def test_register_server():
    cfg = ServerConfig(name='TEST')

    assert 'test' not in _server_configs
    register_server(cfg)
    assert 'test' in _server_configs

    del _server_configs['test']
    assert 'test' not in _server_configs
示例#4
0
def test_create_config_basic():
    cfg = ServerConfig(name='TEST')
    valid_keys = ServerConfig._valid_keys
    assert 'name' in valid_keys
    assert 'encoding' in valid_keys
    for k in valid_keys:
        v = getattr(cfg, k)
        if k == 'name':
            assert v == 'TEST'
        elif k == 'encoding':
            assert v == 'latin1'
        else:
            assert v is None
示例#5
0
def test_getset_attr():
    cfg = ServerConfig(name='TEST')
    assert getattr(cfg, 'name') == 'TEST'
    assert getattr(cfg, '__dict__') == {
        '_d': {
            'encoding': 'latin1',
            'name': 'TEST'
        }
    }
    with pytest.raises(AttributeError):
        getattr(cfg, 'foo')
    setattr(cfg, 'name', 'NewTest')
    assert getattr(cfg, 'name') == 'NewTest'
    with pytest.raises(ValueError):
        setattr(cfg, 'name', 123)
    setattr(cfg, '__sizeof__', 127)
    assert getattr(cfg, '__sizeof__') == 127
示例#6
0
def test_register_server_existing():
    assert 'jsoc' in _server_configs
    cfg = ServerConfig(name='jsoc')
    with pytest.raises(RuntimeError):
        register_server(cfg)
    assert 'jsoc' in _server_configs
示例#7
0
def test_create_config_missing_name():
    with pytest.raises(ValueError):
        cfg = ServerConfig()
示例#8
0
def test_query_invalid_server():
    cfg = ServerConfig(name='TEST')
    c = drms.Client(server=cfg)
    with pytest.raises(DrmsOperationNotSupported):
        keys = c.query('hmi.v_45s[2013.07.03_08:42_TAI/3m]', pkeys=True)
示例#9
0
def test_to_dict():
    cfg = ServerConfig(name='TEST')
    _dict = cfg.to_dict()
    assert isinstance(_dict, dict)
    assert _dict == {'encoding': 'latin1', 'name': 'TEST'}
示例#10
0
def test_create_config_invalid_key():
    with pytest.raises(ValueError):
        cfg = ServerConfig(foo='bar')
示例#11
0
def test_query_invalid():
    cfg = ServerConfig(name='TEST')
    with pytest.raises(DrmsOperationNotSupported):
        c = drms.Client(server=cfg, email='*****@*****.**')
示例#12
0
def test_client_custom_config():
    cfg = ServerConfig(name='TEST')
    c = drms.Client(server=cfg)
    assert isinstance(c._server, ServerConfig)
    assert c._server.name == 'TEST'