Projet

Général

Profil

0004-tests-generalize-site-options.cfg-fixtures-10444.patch

Benjamin Dauvergne, 12 avril 2016 11:06

Télécharger (2,54 ko)

Voir les différences:

Subject: [PATCH 4/7] tests: generalize site-options.cfg fixtures (#10444)

 tests/conftest.py | 28 +++++++++++++++++++---------
 1 file changed, 19 insertions(+), 9 deletions(-)
tests/conftest.py
3 3

  
4 4
import pytest
5 5

  
6

  
6 7
def pytest_addoption(parser):
7 8
    parser.addoption('--without-postgresql-tests', action='store_true',
8
                    help='disable tests requiring postgresql')
9
                     help='disable tests requiring postgresql')
10

  
9 11

  
10 12
def pytest_runtest_setup(item):
11 13
    if 'postgresql' in item.keywords and item.config.option.without_postgresql_tests is True:
12 14
        pytest.skip('skipped (PostgreSQL are disabled on command line)')
13 15

  
14
def variable_url(request, pub, variable, url):
16

  
17
def site_options(request, pub, section, variable, value):
15 18
    config = ConfigParser.ConfigParser()
16 19
    path = os.path.join(pub.app_dir, 'site-options.cfg')
17 20
    if os.path.exists(path):
18 21
        config.read([path])
19
    if not config.has_section('options'):
20
        config.add_section('options')
21
    config.set('options', variable, url)
22
    if not config.has_section(section):
23
        config.add_section(section)
24
    config.set(section, variable, value)
22 25
    with file(path, 'w') as site_option:
23 26
        config.write(site_option)
24 27

  
......
26 29
        config = ConfigParser.ConfigParser()
27 30
        if os.path.exists(path):
28 31
            config.read([path])
29
            config.remove_option('options', variable)
32
            config.remove_option(section, variable)
30 33
            with file(path, 'w') as site_option:
31 34
                config.write(site_option)
32 35
    request.addfinalizer(fin)
33
    return url
36
    return value
37

  
34 38

  
35 39
@pytest.fixture
36 40
def fargo_url(request, pub):
37
    return variable_url(request, pub, 'fargo_url', 'http://fargo.example.net')
41
    return site_options(request, pub, 'options', 'fargo_url', 'http://fargo.example.net')
42

  
43

  
44
@pytest.fixture
45
def fargo_secret(request, pub):
46
    return site_options(request, pub, 'wscall-secrets', 'fargo.example.net', 'xxx')
47

  
38 48

  
39 49
@pytest.fixture
40 50
def welco_url(request, pub):
41
    return variable_url(request, pub, 'welco_url', 'http://welco.example.net')
51
    return site_options(request, pub, 'options', 'welco_url', 'http://welco.example.net')
42
-