Ejemplo n.º 1
0
def test_get_type_null():
    """
    Test that a None maps to an eve 'null'.

    :return:
    """
    source = None
    eg = EveGenie(data=simple_test_data)
    assert(eg.get_type(source) == 'null')
Ejemplo n.º 2
0
def test_get_type_intrange():
    """
    Test that an integer range string maps to an eve 'integer'

    :return:
    """
    source = "1-10"
    eg = EveGenie(data=simple_test_data)
    assert(eg.get_type(source) == 'integer')
Ejemplo n.º 3
0
def test_get_type_floatrange():
    """
    Test that a float range string maps to an eve 'float'

    :return:
    """
    source = "0.0-1.0"
    eg = EveGenie(data=simple_test_data)
    assert(eg.get_type(source) == 'float')
Ejemplo n.º 4
0
def test_get_type_list():
    """
    Test that a list maps to an eve 'list'

    :return:
    """
    source = [1, 2, 3]
    eg = EveGenie(data=simple_test_data)
    assert(eg.get_type(source) == 'list')
Ejemplo n.º 5
0
def test_get_type_objectid():
    """
    Test that an objectid string maps to an eve 'objectid'

    :return:
    """
    source = 'objectid:test'
    eg = EveGenie(data=simple_test_data)
    assert(eg.get_type(source) == 'objectid')
Ejemplo n.º 6
0
def test_get_type_dict():
    """
    Test that a dict maps to an eve 'dict'

    :return:
    """
    source = {'a':'b'}
    eg = EveGenie(data=simple_test_data)
    assert(eg.get_type(source) == 'dict')
Ejemplo n.º 7
0
def test_get_type_ordereddict():
    """
    Test that a OrderedDict maps to an eve 'dict'

    :return:
    """
    source = OrderedDict([('a','b')])
    eg = EveGenie(data=simple_test_data)
    assert(eg.get_type(source) == 'dict')
Ejemplo n.º 8
0
def test_get_type_int():
    """
    Test that an int maps to an eve 'integer'

    :return:
    """
    source = 42
    eg = EveGenie(data=simple_test_data)
    assert(eg.get_type(source) == 'integer')
Ejemplo n.º 9
0
def test_get_type_float():
    """
    Test that a float maps to an eve 'float'

    :return:
    """
    source = 4.2
    eg = EveGenie(data=simple_test_data)
    assert(eg.get_type(source) == 'float')
Ejemplo n.º 10
0
def test_get_type_bool():
    """
    Test that a bool maps to an eve 'boolean'

    :return:
    """
    source = True
    eg = EveGenie(data=simple_test_data)
    assert(eg.get_type(source) == 'boolean')
Ejemplo n.º 11
0
def test_get_type_str():
    """
    Test that a str maps to an eve 'string'

    :return:
    """
    source = 'snowman'
    eg = EveGenie(data=simple_test_data)
    assert(eg.get_type(source) == 'string')
Ejemplo n.º 12
0
def test_get_type_unicode():
    """
    Test that a unicode string maps to an eve 'string'

    :return:
    """
    source = '☃'
    eg = EveGenie(data=simple_test_data)
    assert(eg.get_type(source) == 'string')
Ejemplo n.º 13
0
def test_get_type_dict():
    """
    Test that a dict maps to an eve 'dict'

    :return:
    """
    source = {'a': 'b'}
    eg = EveGenie(data=simple_test_data)
    assert (eg.get_type(source) == 'dict')
Ejemplo n.º 14
0
def test_get_type_float():
    """
    Test that a float maps to an eve 'float'

    :return:
    """
    source = 4.2
    eg = EveGenie(data=simple_test_data)
    assert (eg.get_type(source) == 'float')
Ejemplo n.º 15
0
def test_endpoint_format():
    """
    Test whether the formatted output for an endpoint is as expected

    :return:
    """
    eg = EveGenie(data=simple_test_data)
    endpoint = eg['user']
    assert(eg.format_endpoint(endpoint) == format_endpoint_test)
Ejemplo n.º 16
0
def test_get_type_int():
    """
    Test that an int maps to an eve 'integer'

    :return:
    """
    source = 42
    eg = EveGenie(data=simple_test_data)
    assert (eg.get_type(source) == 'integer')
Ejemplo n.º 17
0
def test_get_type_str():
    """
    Test that a str maps to an eve 'string'

    :return:
    """
    source = 'snowman'
    eg = EveGenie(data=simple_test_data)
    assert (eg.get_type(source) == 'string')
Ejemplo n.º 18
0
def test_get_type_bool():
    """
    Test that a bool maps to an eve 'boolean'

    :return:
    """
    source = True
    eg = EveGenie(data=simple_test_data)
    assert (eg.get_type(source) == 'boolean')
Ejemplo n.º 19
0
def test_get_type_ordereddict():
    """
    Test that a OrderedDict maps to an eve 'dict'

    :return:
    """
    source = OrderedDict([('a', 'b')])
    eg = EveGenie(data=simple_test_data)
    assert (eg.get_type(source) == 'dict')
Ejemplo n.º 20
0
def test_get_type_unicode():
    """
    Test that a unicode string maps to an eve 'string'

    :return:
    """
    source = '☃'
    eg = EveGenie(data=simple_test_data)
    assert (eg.get_type(source) == 'string')
Ejemplo n.º 21
0
def test_get_type_list():
    """
    Test that a list maps to an eve 'list'

    :return:
    """
    source = [1, 2, 3]
    eg = EveGenie(data=simple_test_data)
    assert (eg.get_type(source) == 'list')
Ejemplo n.º 22
0
def test_endpoint_format():
    """
    Test whether the formatted output for an endpoint is as expected

    :return:
    """
    eg = EveGenie(data=simple_test_data)
    endpoint = eg['user']
    assert (eg.format_endpoint(endpoint) == format_endpoint_test)
Ejemplo n.º 23
0
def test_get_type_objectid():
    """
    Test that an objectid string maps to an eve 'objectid'

    :return:
    """
    source = 'objectid:test'
    eg = EveGenie(data=simple_test_data)
    assert (eg.get_type(source) == 'objectid')
Ejemplo n.º 24
0
def test_get_type_intrange():
    """
    Test that an integer range string maps to an eve 'integer'

    :return:
    """
    source = "1-10"
    eg = EveGenie(data=simple_test_data)
    assert (eg.get_type(source) == 'integer')
Ejemplo n.º 25
0
def test_get_type_floatrange():
    """
    Test that a float range string maps to an eve 'float'

    :return:
    """
    source = "0.0-1.0"
    eg = EveGenie(data=simple_test_data)
    assert (eg.get_type(source) == 'float')
Ejemplo n.º 26
0
def test_get_type_null():
    """
    Test that a None maps to an eve 'null'.

    :return:
    """
    source = None
    eg = EveGenie(data=simple_test_data)
    assert (eg.get_type(source) == 'null')
Ejemplo n.º 27
0
def test_get_type_fail():
    """
    Test that type correctly errors when an invalid type is passed.

    :return:
    """
    source = deque('abc')
    eg = EveGenie(data=simple_test_data)
    with pytest.raises(TypeError):
        eg.get_type(source)
Ejemplo n.º 28
0
def test_get_type_fail():
    """
    Test that type correctly errors when an invalid type is passed.

    :return:
    """
    source = deque('abc')
    eg = EveGenie(data=simple_test_data)
    with pytest.raises(TypeError):
        eg.get_type(source)
Ejemplo n.º 29
0
def main(filename):
    """
    Create an instance of EveGenie from a json file. Then write it to file.

    :param filename: input filename
    :return:
    """
    print 'converting contents of {}'.format(filename)
    eg = EveGenie(filename=filename)
    outfile = '{}.settings.py'.format(filename.split('.')[0])
    eg.write_file(outfile)
    print 'settings file written to {}'.format(outfile)
Ejemplo n.º 30
0
def test_evegenie_len():
    """
    Test that an EveGenie object correctly reports its length.

    :return:
    """
    eg = EveGenie(data=simple_test_data)
    assert (len(eg) == 1)
Ejemplo n.º 31
0
def test_input_both_inputs():
    """
    Make sure when both data types are passed the data is still parsed as expected.

    :return:
    """
    eg = EveGenie(data=test_data, filename='test.json')
    assert (OrderedDict(eg) == test_data_answer)
Ejemplo n.º 32
0
def test_input_string():
    """
    Make sure data loaded from string is parsed as expected.

    :return:
    """
    eg = EveGenie(data=json.dumps(test_data))
    assert (OrderedDict(eg) == test_data_answer)
Ejemplo n.º 33
0
def test_evegenie_no_data():
    """
    Test that attempting to initilaize EveGenie object with no data errors.

    :return:
    """
    with pytest.raises(TypeError):
        eg = EveGenie()
Ejemplo n.º 34
0
def test_input_dict():
    """
    Make sure data loaded as a dict is parsed as expected.

    :return:
    """
    eg = EveGenie(data=test_data)
    assert (OrderedDict(eg) == test_data_answer)
Ejemplo n.º 35
0
def test_input_file():
    """
    Make sure data loaded from file is parsed as expected.

    :return:
    """
    eg = EveGenie(filename=parent_dir + '/tests/test.json')
    assert (OrderedDict(eg) == test_data_answer)
Ejemplo n.º 36
0
def test_output_file():
    """
    Tests writing schema to file and compares the files output to a control.

    :return:
    """
    outfile = parent_dir + '/tests/test_output'
    controlfile = parent_dir + '/tests/test.output.py'
    eg = EveGenie(data=test_data)

    with open(controlfile, 'r') as ifile:
        control = ifile.read()

    eg.write_file(outfile)
    with open(outfile, 'r') as ifile:
        test_schema = ifile.read()

    os.remove(outfile)
    assert(test_schema == control)
Ejemplo n.º 37
0
def test_output_file():
    """
    Tests writing schema to file and compares the files output to a control.

    :return:
    """
    outfile = parent_dir + '/tests/test_output'
    controlfile = parent_dir + '/tests/test.output.py'
    eg = EveGenie(data=test_data)

    with open(controlfile, 'r') as ifile:
        control = ifile.read()

    eg.write_file(outfile)
    with open(outfile, 'r') as ifile:
        test_schema = ifile.read()

    os.remove(outfile)
    assert (test_schema == control)
Ejemplo n.º 38
0
def test_simple_endpoint_validation():
    """
    Test that the endpoint schema generated will validate when used in Eve.

    :return:
    """
    eg = EveGenie(data=simple_test_data)
    data = OrderedDict(eg)
    for endpoint in data:
        v = Validator(data[endpoint]['schema'])
        assert (v.validate(simple_test_data[endpoint]))