예제 #1
0
def test_set_not_string():

    dictionary = {'key1': 'value1'}

    patcher = Patcher(dictionary)
    with pytest.raises(exceptions.InvalidValueTypeException):
        patcher.set('key1', 5).finish()
예제 #2
0
def test_set_not_string():

    dictionary = {'key1': 'value1'}

    patcher = Patcher(dictionary)
    with pytest.raises(exceptions.InvalidValueTypeException):
        patcher.set('key1', 5).finish()
예제 #3
0
def test_add_to_non_list():

    dictionary = {'key': 'value1'}

    patcher = Patcher(dictionary)

    with pytest.raises(exceptions.InvalidKeyTypeException):
        patcher.add(key='key', value='value2')
예제 #4
0
def test_delete_non_existing_key():

    dictionary = {'key': 'value'}

    patcher = Patcher(dictionary)

    with pytest.raises(exceptions.KeyNotFoundException):
        patcher.delete('non-existing')
예제 #5
0
def test_add_to_non_list():

    dictionary = {'key': 'value1'}

    patcher = Patcher(dictionary)

    with pytest.raises(exceptions.InvalidKeyTypeException):
        patcher.add(key='key', value='value2')
예제 #6
0
def test_get_compund_object_unsupported_format():

    dictionary = {'key1': ['value1', 'value2']}

    patcher = Patcher(dictionary)

    with pytest.raises(exceptions.UnsupportedFormatException):
        patcher.get('key1', fmt='unsupported')
예제 #7
0
def test_get_non_existing_two_level_complex_key():

    dictionary = {'key1': {'key2': {'key3': 'value1'}}}

    patcher = Patcher(dictionary)

    with pytest.raises(exceptions.KeyNotFoundException):
        patcher.get('key1:key2:key4')
예제 #8
0
def test_delete_non_existing_key():

    dictionary = {'key': 'value'}

    patcher = Patcher(dictionary)

    with pytest.raises(exceptions.KeyNotFoundException):
        patcher.delete('non-existing')
예제 #9
0
def test_set_existing_two_level_complex_key():

    dictionary = {'key1': {'key2': {'key3': 'value1'}}}

    expected_dictionary = {'key1': {'key2': {'key3': 'value2'}}}

    patcher = Patcher(dictionary)
    dictionary = patcher.set('key1:key2:key3', 'value2').finish()

    assert expected_dictionary == dictionary
예제 #10
0
def test_add_to_complex_key():

    dictionary = {'key1': {'key2': ['value1']}}

    expected_dictionary = {'key1': {'key2': ['value1', 'value2']}}

    patcher = Patcher(dictionary)
    patcher.add(key='key1:key2', value='value2')

    assert expected_dictionary == dictionary
예제 #11
0
def test_get_compund_object_unsupported_format():

    dictionary = {
        'key1': ['value1', 'value2']
    }

    patcher = Patcher(dictionary)

    with pytest.raises(exceptions.UnsupportedFormatException):
        patcher.get('key1', fmt='unsupported')
예제 #12
0
def test_delete_complex_key():

    dictionary = {'key1': {'key2': 'value1', 'key3': 'value2'}}

    expected_dictionary = {'key1': {'key2': 'value1'}}

    patcher = Patcher(dictionary)
    dictionary = patcher.delete('key1:key3').finish()

    assert expected_dictionary == dictionary
예제 #13
0
def test_set_complex_key_compound_value():

    dictionary = {'key1': {'key2': 'value1'}}

    expected_dictionary = {'key1': {'key2': {'key3': 'value2'}}}

    patcher = Patcher(dictionary)
    dictionary = patcher.set('key1:key2', '{"key3":"value2"}').finish()

    assert expected_dictionary == dictionary
예제 #14
0
def test_get_dict_as_yaml():

    dictionary = {'key1': {'key2': 'value1'}}

    expected_value = 'key2: value1\n'

    patcher = Patcher(dictionary)
    value = patcher.get('key1', fmt=constants.YAML)

    assert expected_value == value
예제 #15
0
def test_set_unicode():

    dictionary = {'key1': 'value1'}

    expected_dictionary = {'key1': 'value2'}

    patcher = Patcher(dictionary)
    dictionary = patcher.set('key1', u'value2').finish()

    assert expected_dictionary == dictionary
예제 #16
0
def test_get_existing_one_level_complex_key():

    dictionary = {'key1': {'key2': 'value1'}}

    expected_value = 'value1'

    patcher = Patcher(dictionary)
    value = patcher.get('key1:key2')

    assert expected_value == value
예제 #17
0
def test_remove_from_complex_key():

    dictionary = {'key1': {'key2': ['value1', 'value2']}}

    expected_dictionary = {'key1': {'key2': ['value1']}}

    patcher = Patcher(dictionary)
    patcher.remove(key='key1:key2', value='value2')

    assert expected_dictionary == dictionary
예제 #18
0
def test_get_float():

    dictionary = {'key1': 5.5}

    expected_value = '5.5'

    patcher = Patcher(dictionary)
    value = patcher.get('key1')

    assert expected_value == value
예제 #19
0
def test_get_integer():

    dictionary = {'key1': 5}

    expected_value = '5'

    patcher = Patcher(dictionary)
    value = patcher.get('key1')

    assert expected_value == value
예제 #20
0
def test_get_string():

    dictionary = {'key1': 'value1'}

    expected_value = 'value1'

    patcher = Patcher(dictionary)
    value = patcher.get('key1')

    assert expected_value == value
예제 #21
0
def test_delete():

    dictionary = {'key1': 'value1', 'key2': 'value2'}

    expected_dictionary = {'key2': 'value2'}

    patcher = Patcher(dictionary)
    dictionary = patcher.delete('key1').finish()

    assert expected_dictionary == dictionary
예제 #22
0
def test_remove():

    dictionary = {'key1': ['value1', 'value2']}

    expected_dictionary = {'key1': ['value1']}

    patcher = Patcher(dictionary)
    patcher.remove(key='key1', value='value2')

    assert expected_dictionary == dictionary
예제 #23
0
def test_add():

    dictionary = {'key': ['value1']}

    expected_dictionary = {'key': ['value1', 'value2']}

    patcher = Patcher(dictionary)
    patcher.add(key='key', value='value2')

    assert expected_dictionary == dictionary
예제 #24
0
def test_set_list():

    dictionary = {'key1': 'value1'}

    expected_dictionary = {'key1': ['value1', 'value2']}

    patcher = Patcher(dictionary)
    dictionary = patcher.set('key1', '["value1", "value2"]').finish()

    assert expected_dictionary == dictionary
예제 #25
0
def test_delete():

    dictionary = {'key1': 'value1', 'key2': 'value2'}

    expected_dictionary = {'key2': 'value2'}

    patcher = Patcher(dictionary)
    dictionary = patcher.delete('key1').finish()

    assert expected_dictionary == dictionary
예제 #26
0
def test_add():

    dictionary = {'key': ['value1']}

    expected_dictionary = {'key': ['value1', 'value2']}

    patcher = Patcher(dictionary)
    patcher.add(key='key', value='value2')

    assert expected_dictionary == dictionary
예제 #27
0
def test_set_unicode():

    dictionary = {'key1': 'value1'}

    expected_dictionary = {'key1': 'value2'}

    patcher = Patcher(dictionary)
    dictionary = patcher.set('key1', u'value2').finish()

    assert expected_dictionary == dictionary
예제 #28
0
def test_set_float():

    dictionary = {'key1': 'value1'}

    expected_dictionary = {'key1': 5.5}

    patcher = Patcher(dictionary)
    dictionary = patcher.set('key1', '5.5').finish()

    assert expected_dictionary == dictionary
예제 #29
0
def test_set_dict():

    dictionary = {'key1': 'value1'}

    expected_dictionary = {'key1': {'key2': 'value2'}}

    patcher = Patcher(dictionary)
    dictionary = patcher.set('key1', '{"key2":"value2"}').finish()

    assert expected_dictionary == dictionary
예제 #30
0
def test_get_ini_section():

    dictionary = {'section': {'key1': 'key2'}}

    expected_value = writer.dumps(obj={'key1': 'key2'},
                                  fmt=constants.PROPERTIES)

    patcher = Patcher(dictionary)
    value = patcher.get('section', fmt=constants.INI)

    assert expected_value == value
예제 #31
0
def test_get_list_as_yaml():

    dictionary = {'key1': ['value1', 'value2']}

    expected_value = '''- value1
- value2\n'''

    patcher = Patcher(dictionary)
    value = patcher.get('key1', fmt=constants.YAML)

    assert expected_value == value
예제 #32
0
def test_get_float():

    dictionary = {
        'key1': 5.5
    }

    expected_value = '5.5'

    patcher = Patcher(dictionary)
    value = patcher.get('key1')

    assert expected_value == value
예제 #33
0
def test_get_integer():

    dictionary = {
        'key1': 5
    }

    expected_value = '5'

    patcher = Patcher(dictionary)
    value = patcher.get('key1')

    assert expected_value == value
예제 #34
0
def test_get_string():

    dictionary = {
        'key1': 'value1'
    }

    expected_value = 'value1'

    patcher = Patcher(dictionary)
    value = patcher.get('key1')

    assert expected_value == value
예제 #35
0
def test_set_float():

    dictionary = {'key1': 'value1'}

    expected_dictionary = {
        'key1': 5.5
    }

    patcher = Patcher(dictionary)
    dictionary = patcher.set('key1', '5.5').finish()

    assert expected_dictionary == dictionary
예제 #36
0
def test_set_list():

    dictionary = {'key1': 'value1'}

    expected_dictionary = {
        'key1': ['value1', 'value2']
    }

    patcher = Patcher(dictionary)
    dictionary = patcher.set('key1', '["value1", "value2"]').finish()

    assert expected_dictionary == dictionary
예제 #37
0
def test_get_dict_as_json():

    dictionary = {'key1': {'key2': 'value1'}}

    expected_value = '''{
  "key2": "value1"
}'''

    patcher = Patcher(dictionary)
    value = patcher.get('key1')

    assert expected_value == value
예제 #38
0
def test_set_dict():

    dictionary = {'key1': 'value1'}

    expected_dictionary = {
        'key1': {
            'key2': 'value2'
        }}

    patcher = Patcher(dictionary)
    dictionary = patcher.set('key1', '{"key2":"value2"}').finish()

    assert expected_dictionary == dictionary
예제 #39
0
def test_get_list_as_yaml():

    dictionary = {
        'key1': ['value1', 'value2']
    }

    expected_value = '''- value1
- value2\n'''

    patcher = Patcher(dictionary)
    value = patcher.get('key1', fmt=constants.YAML)

    assert expected_value == value
예제 #40
0
def test_remove():

    dictionary = {
        'key1': ['value1', 'value2']
    }

    expected_dictionary = {
        'key1': ['value1']
    }

    patcher = Patcher(dictionary)
    patcher.remove(key='key1', value='value2')

    assert expected_dictionary == dictionary
예제 #41
0
def test_get_existing_one_level_complex_key():

    dictionary = {
        'key1': {
            'key2': 'value1'
        }
    }

    expected_value = 'value1'

    patcher = Patcher(dictionary)
    value = patcher.get('key1:key2')

    assert expected_value == value
예제 #42
0
def test_get_ini_section():

    dictionary = {
        'section': {
            'key1': 'key2'
        }
    }

    expected_value = writer.dumps(obj={'key1': 'key2'}, fmt=constants.PROPERTIES)

    patcher = Patcher(dictionary)
    value = patcher.get('section', fmt=constants.INI)

    assert expected_value == value
예제 #43
0
def test_get_non_existing_two_level_complex_key():

    dictionary = {
        'key1': {
            'key2': {
                'key3': 'value1'
            }
        }
    }

    patcher = Patcher(dictionary)

    with pytest.raises(exceptions.KeyNotFoundException):
        patcher.get('key1:key2:key4')
예제 #44
0
def test_get_dict_as_yaml():

    dictionary = {
        'key1': {
            'key2': 'value1'
        }
    }

    expected_value = 'key2: value1\n'

    patcher = Patcher(dictionary)
    value = patcher.get('key1', fmt=constants.YAML)

    assert expected_value == value
예제 #45
0
def test_get_list_as_json():

    dictionary = {'key1': ['value1', 'value2']}

    expected_value = '''[
"value1",
"value2"
]'''

    patcher = Patcher(dictionary)
    value = patcher.get('key1')

    actual = value.replace(' ', '')

    assert expected_value == actual
예제 #46
0
def configure(ctx, alias):

    repo = ctx.parent.repo

    file_path = repo.path(alias)

    try:
        parsed = parser.load(file_path=file_path, fmt=repo.fmt(alias))
    except exceptions.CorruptFileException as e:
        e.cause = causes.EDITED_MANUALLY
        e.possible_solutions = [
            solutions.edit_manually(),
            solutions.reset_to_latest(alias)
        ]
        raise

    # detect if the file was manually edited since the last command.
    # if so, warn because it means the current version of the file is not
    # under version control and will be lost after the change
    latest = parser.loads(repo.contents(alias=alias, version='latest'),
                          fmt=repo.fmt(alias))
    if latest != parsed:

        exception = click.ClickException(message='Cannot perform operation')
        exception.cause = causes.DIFFER_FROM_LATEST
        exception.possible_solutions = [
            solutions.reset_to_latest(alias),
            solutions.commit(alias)
        ]
        raise exception

    patcher = Patcher(parsed)
    ctx.patcher = patcher
예제 #47
0
def test_get_dict_as_json():

    dictionary = {
        'key1': {
            'key2': 'value1'
        }
    }

    expected_value = '''{
  "key2": "value1"
}'''

    patcher = Patcher(dictionary)
    value = patcher.get('key1')

    assert expected_value == value
예제 #48
0
def test_get_list_as_json():

    dictionary = {
        'key1': ['value1', 'value2']
    }

    expected_value = '''[
"value1",
"value2"
]'''

    patcher = Patcher(dictionary)
    value = patcher.get('key1')

    actual = value.replace(' ', '')

    assert expected_value == actual
예제 #49
0
def test_remove_from_complex_key():

    dictionary = {
        'key1': {
            'key2': ['value1', 'value2']
        }
    }

    expected_dictionary = {
        'key1': {
            'key2': ['value1']
        }
    }

    patcher = Patcher(dictionary)
    patcher.remove(key='key1:key2', value='value2')

    assert expected_dictionary == dictionary
예제 #50
0
def test_set_existing_one_level_complex_key():

    dictionary = {
        'key1': {
            'key2': 'value1'
        }
    }

    expected_dictionary = {
        'key1': {
            'key2': 'value2'
        }
    }

    patcher = Patcher(dictionary)
    dictionary = patcher.set('key1:key2', 'value2').finish()

    assert expected_dictionary == dictionary
예제 #51
0
def test_add_to_complex_key():

    dictionary = {
        'key1': {
            'key2': ['value1']
        }
    }

    expected_dictionary = {
        'key1': {
            'key2': ['value1', 'value2']
        }
    }

    patcher = Patcher(dictionary)
    patcher.add(key='key1:key2', value='value2')

    assert expected_dictionary == dictionary
예제 #52
0
def test_set_complex_key_compound_value():

    dictionary = {
        'key1': {
            'key2': 'value1'
        }
    }

    expected_dictionary = {
        'key1': {
            'key2': {
                'key3': 'value2'
            }
        }}

    patcher = Patcher(dictionary)
    dictionary = patcher.set('key1:key2', '{"key3":"value2"}').finish()

    assert expected_dictionary == dictionary
예제 #53
0
def test_delete_complex_key():

    dictionary = {
        'key1': {
            'key2': 'value1',
            'key3': 'value2'
        }
    }

    expected_dictionary = {
        'key1': {
            'key2': 'value1'
        }
    }

    patcher = Patcher(dictionary)
    dictionary = patcher.delete('key1:key3').finish()

    assert expected_dictionary == dictionary