Beispiel #1
0
def test_readconfig_duplicate_values():
    configbody = """
[SECTION]
KEY1 = Value1
KEY1 = Value2
    """
    resetconfig()

    with TempConfigMock(configbody) as mock:
        with pytest.raises(DuplicateOptionError):
            config.readconfig(mock)
Beispiel #2
0
def test_readconfig_invalid_environment_specifier():
    configbody = """
[SECTION1]
ENVIRONMENT = DEV

[ENVIRONMENTSPECIFIC]
INVALID_KEY = Value
    """
    resetconfig()

    with TempConfigMock(configbody) as mock:
        with pytest.warns(UserWarning, match=r'not a valid environment.'):
            config.readconfig(mock)
Beispiel #3
0
def test_readconfig_environmentspecific_variable_for_other_environment():
    configbody = """
[SECTION1]
ENVIRONMENT = DEV

[ENVIRONMENTSPECIFIC]
PROD_KEY = Value
    """
    resetconfig()

    with TempConfigMock(configbody) as mock:
        config.readconfig(mock)

        assert "KEY" not in config.CONFIG
Beispiel #4
0
def test_readconfig_valid_environmentspecific_key():
    configbody = """
[SECTION1]
ENVIRONMENT = DEV

[ENVIRONMENTSPECIFIC]
DEV_KEY = Value
    """
    resetconfig()

    with TempConfigMock(configbody) as mock:
        config.readconfig(mock)

        assert "KEY" in config.CONFIG
        assert config.CONFIG["KEY"] == "Value"
Beispiel #5
0
def test_readconfig_valid_config():
    configbody = """
[SECTION1]
KEY1 = Value1

[SECTION2]
KEY2 = Value2
    """
    resetconfig()

    with TempConfigMock(configbody) as mock:
        config.readconfig(mock)

        assert "KEY1" in config.CONFIG
        assert config.CONFIG["KEY1"] == "Value1"

        assert "KEY2" in config.CONFIG
        assert config.CONFIG["KEY2"] == "Value2"
Beispiel #6
0
def test_readconfig_overwriting_value_with_environmenspecific_value():
    configbody = """
[SECTION1]
ENVIRONMENT = DEV

[SECTION2]
KEY = OldValue

[ENVIRONMENTSPECIFIC]
DEV_KEY = NewValue
    """
    resetconfig()

    with TempConfigMock(configbody) as mock:
        with pytest.warns(
                UserWarning,
                match=r'Overwriting the value for the environment-specific'):
            config.readconfig(mock)

        assert "KEY" in config.CONFIG
        assert config.CONFIG["KEY"] == "NewValue"
Beispiel #7
0
import time

import pytest

from source import medid
from source.config import config
from source.crawling import iteration

config.readconfig('config.cfg')

# Set the number of seconds between iterations to 1 second for testing purposes
config.CONFIG['INTERVAL'] = 1

# Monkey-patch the crawling iteration to a lambda function which does nothing
iteration.start = lambda: None


@pytest.mark.parametrize("test_input, expected", [(1, 0), (2, 1)])
def test_crawlloop_various_iterations(test_input: int, expected: int):
    start = time.time()
    medid.crawlloop(0, test_input)
    delta = int(time.time() - start)

    assert delta == pytest.approx(expected)


def test_crawlloop_delayed_start():
    starttime = int(time.time()) + 2
    start = time.time()
    medid.crawlloop(starttime, 1)
    delta = int(time.time() - start)
Beispiel #8
0
def test_readconfig_no_config_file():
    resetconfig()
    with pytest.raises(FileNotFoundError):
        config.readconfig('no file with this name exists')