Beispiel #1
0
def test_integration_errors():
    markdown_broken = """
        name {label:"VARCHAR(255)"}
    [child]
        *id {label:"INTEGER"}
        parent_id {label:"INTEGER"}
    parent *--? child
    """
    with pytest.raises(ParsingException):
        line_iterator_to_intermediary(markdown_broken.split("\n"))
Beispiel #2
0
def test_integration_errors():
    markdown_broken = \
    """
        name {label:"VARCHAR(255)"}
    [child]
        *id {label:"INTEGER"}
        parent_id {label:"INTEGER"}
    parent *--? child
    """
    with pytest.raises(ParsingException):
        line_iterator_to_intermediary(markdown_broken.split('\n'))
Beispiel #3
0
def all_to_intermediary(filename_or_input, schema=None):
    """ Dispatch the filename_or_input to the different function to produce the intermediary syntax.
    All the supported classes names are in `swich_input_class_to_method`.
    The input can also be a list of strings in markdown format or a filename finishing by '.er' containing markdown
    format.
    """
    # Try to convert from the name of the class
    input_class_name = filename_or_input.__class__.__name__
    try:
        this_to_intermediary = switch_input_class_to_method[input_class_name]
        tables, relationships = this_to_intermediary(filename_or_input)
        return tables, relationships
    except KeyError:
        pass

    # try to read markdown file.
    if isinstance(filename_or_input, basestring):
        if filename_or_input.split('.')[-1] == 'er':
            return markdown_file_to_intermediary(filename_or_input)

    # try to read a markdown in a string
    if not isinstance(filename_or_input, basestring):
        if all(isinstance(e, basestring) for e in filename_or_input):
            return line_iterator_to_intermediary(filename_or_input)

    # try to read DB URI.
    try:
        make_url(filename_or_input)
        return database_to_intermediary(filename_or_input, schema=schema)
    except ArgumentError:
        pass

    msg = 'Cannot process filename_or_input {}'.format(input_class_name)
    raise ValueError(msg)
Beispiel #4
0
def all_to_intermediary(filename_or_input, schema=None):
    """ Dispatch the filename_or_input to the different function to produce the intermediary syntax.
    All the supported classes names are in `swich_input_class_to_method`.
    The input can also be a list of strings in markdown format or a filename finishing by '.er' containing markdown
    format.
    """
    # Try to convert from the name of the class
    input_class_name = filename_or_input.__class__.__name__
    try:
        this_to_intermediary = switch_input_class_to_method[input_class_name]
        tables, relationships = this_to_intermediary(filename_or_input)
        return tables, relationships
    except KeyError:
        pass

    # try to read markdown file.
    if isinstance(filename_or_input, basestring):
        if filename_or_input.split('.')[-1] == 'er':
            return markdown_file_to_intermediary(filename_or_input)

    # try to read a markdown in a string
    if not isinstance(filename_or_input, basestring):
        if all(isinstance(e, basestring) for e in filename_or_input):
            return line_iterator_to_intermediary(filename_or_input)

    # try to read DB URI.
    try:
        make_url(filename_or_input)
        return database_to_intermediary(filename_or_input, schema=schema)
    except ArgumentError:
        pass

    msg = 'Cannot process filename_or_input {}'.format(input_class_name)
    raise ValueError(msg)
def test_generate_and_parse():
    markdown = _intermediary_to_markdown(c.tables, [c.relation])
    tables, relations = line_iterator_to_intermediary(markdown.split('\n'))
    c.assert_lst_equal(tables, c.tables)
    c.assert_lst_equal(relations, [c.relation])
def test_integration_parser():
    tables, relations = line_iterator_to_intermediary(c.markdown.split('\n'))
    c.assert_lst_equal(tables, c.tables)
    c.assert_lst_equal(relations, [c.relation, c.exclude_relation])
Beispiel #7
0
def test_generate_and_parse():
    markdown = _intermediary_to_markdown(c.tables, [c.relation])
    tables, relations = line_iterator_to_intermediary(markdown.split('\n'))
    c.assert_lst_equal(tables, c.tables)
    c.assert_lst_equal(relations, [c.relation])
Beispiel #8
0
def test_integration_parser():
    tables, relations = line_iterator_to_intermediary(c.markdown.split('\n'))
    c.assert_lst_equal(tables, c.tables)
    c.assert_lst_equal(relations, [c.relation, c.exclude_relation])