Exemple #1
0
def test_merge_regular_environment():
    "Environment.update() Should update a regular environment with data from another one"

    # Given that I load variables to my env from a folder
    environment = Environment()

    # When I merge another environment into the current one that *does
    # not* have the variable CITY
    environment.update(Environment(storage={'CITY': 'Porto Alegre'}))

    # Then I see that the old value was overwritten
    environment.get('CITY').should.equal('Porto Alegre')
Exemple #2
0
def test_merge_regular_environment_with_non_string_values():
    "Environment.update() Should convert all the values before setting them back to the original environment"

    # Given that I load variables to my env from a folder
    environment = Environment()

    # When I merge another environment into the current one that *does
    # not* have the variable `age`, I set it as an integer
    environment.update(Environment(storage={'age': 27}))

    # Then I see that the value was converted to a string
    environment.get('age').should.equal('27')

    # And then I see it's not a unicode string, but a bytes sequence
    environment.get('age').should.be.a(bytes)
Exemple #3
0
def test_milieu_helper_methods():
    # Given that I have an environment with some variables set
    data = {
        'str': 'I heard you like variables',
        'int': '42',
        'float': '3.14',
        'bool0': 'True',
        'bool1': 'true',
        'bool2': '1',
        'bool3': '2',
        'bool4': 'False',
        'bool5': 'false',
        'bool6': '0',
    }
    env = Environment(storage=data)

    # Let's retrieve things with their correct types
    env.get_int('int').should.equal(42)
    env.get_float('float').should.equal(3.14)
    env.get_bool('bool0').should.be.true
    env.get_bool('bool1').should.be.true
    env.get_bool('bool2').should.be.true
    env.get_bool('bool3').should.be.true
    env.get_bool('bool4').should.be.false
    env.get_bool('bool5').should.be.false
    env.get_bool('bool6').should.be.false

    # Sanity checks
    env.get_int.when.called_with('str').should.throw(ValueError)
    env.get_float.when.called_with('str').should.throw(ValueError)
    env.get_bool('str').should.be.false

    # Testing default values
    env.get('i-dont-exist', 'blah').should.equal('blah')
    env.get_int('i-dont-exist', 2).should.equal(2)
    env.get_float('i-dont-exist', 2.5).should.equal(2.5)
    env.get_bool('i-dont-exist', True).should.be.true
Exemple #4
0
def test_milieu_environment_get():
    # Given that I have an environment
    env = Environment({'val1': 'yo'})

    # When I set something
    env.get('val1').should.equal('yo')