Exemplo n.º 1
0
    def test_it_should_returns_a_list_of_str_when_asked_to(self):
        r = getlist('a key', section='lists')
        expect(r).to.be.a(list)
        expect(r).to.be.empty

        set_setting('a key', ['one', 'two'], section='lists')

        r = getlist('a key', section='lists')
        expect(r).to.be.a(list)
        expect(r).to.equal(['one', 'two'])

        expect(
            getlist('a key',
                    section='lists',
                    additional_lookup={
                        'LISTS_A_KEY': 'a,b,c',
                    })).to.equal(['a', 'b', 'c'])
Exemplo n.º 2
0
    def test_it_should_retrieve_the_env_var_which_takes_precedence_if_any(
            self):

        set_setting('a_key', 'a value', section='envs')

        expect(get('a_key', section='envs')).to.equal('a value')

        os.environ['ENVS_A_KEY'] = 'an env value'

        expect(get('a_key', section='envs')).to.equal('an env value')

        expect(
            get('a_key',
                section='envs',
                additional_lookup={
                    'ENVS_A_KEY': 'an added env value',
                })).to.equal('an added env value')
Exemplo n.º 3
0
    def test_it_should_returns_a_float_when_asked_to(self):
        r = getfloat('a key', section='floats')
        expect(r).to.be.a(float)
        expect(r).to.equal(0.0)

        set_setting('a key', 1337.2, section='floats')

        r = getfloat('a key', section='floats')
        expect(r).to.be.a(float)
        expect(r).to.equal(1337.2)

        expect(
            getfloat('a key',
                     section='floats',
                     additional_lookup={
                         'FLOATS_A_KEY': '42.2',
                     })).to.equal(42.2)
Exemplo n.º 4
0
    def test_it_should_returns_an_int_when_asked_to(self):
        r = getint('a key', section='ints')
        expect(r).to.be.a(int)
        expect(r).to.equal(0)

        set_setting('a key', 1337, section='ints')

        r = getint('a key', section='ints')
        expect(r).to.be.a(int)
        expect(r).to.equal(1337)

        expect(
            getint('a key',
                   section='ints',
                   additional_lookup={
                       'INTS_A_KEY': '42',
                   })).to.equal(42)
Exemplo n.º 5
0
    def test_it_should_returns_an_absolute_path_when_asked_to(self):
        r = getpath('a key', section='paths')
        expect(r).to.be.none

        r = getpath('a key', 'default/path', section='paths')
        expect(r).to.equal(os.path.abspath('default/path'))

        set_setting('a key', 'something', section='paths')

        r = getpath('a key', section='paths')
        expect(r).to.equal(os.path.abspath('something'))

        expect(
            getpath('a key',
                    section='paths',
                    additional_lookup={
                        'PATHS_A_KEY': 'var/data',
                    })).to.equal(os.path.abspath('var/data'))
Exemplo n.º 6
0
    def test_it_should_returns_a_boolean_when_asked_to(self):
        r = getbool('a key', section='bools')
        expect(r).to.be.a(bool)
        expect(r).to.be.false

        set_setting('a key', 1, section='bools')

        r = getbool('a key', section='bools')
        expect(r).to.be.a(bool)
        expect(r).to.be.true

        set_setting('another key', True, section='bools')

        r = getbool('another key', section='bools')
        expect(r).to.be.a(bool)
        expect(r).to.be.true

        expect(
            getbool('another key',
                    section='bools',
                    additional_lookup={
                        'BOOLS_ANOTHER_KEY': 'True',
                    })).to.be.true
Exemplo n.º 7
0
    def test_it_should_retrieve_a_string_value(self):
        set_setting('key', 'value', section='strings')

        expect(get('key', section='strings')).to.equal('value')
Exemplo n.º 8
0
    def test_it_should_set_the_setting_even_if_the_section_does_not_exists_yet(
            self):
        set_setting('my_key', 'a value', section='my_section')

        expect(config.get('my_section', 'my_key')).to.equal('a value')