def __init__(self):
        """Intializes CsvFileWriter with csv_name, csv_col_names, csv_rows."""

        self.root_node = InternalNode(depth_in_tree=0, parameter_to_value={})

        data = self.root_node.create_child_nodes()
        csv_file_writer = CsvFileWriter(DATASET_FILE_NAME,
                                        ["Metadata", "Data"], data)
        csv_file_writer.write_to_csv()
Beispiel #2
0
def test_post_process_node_many_children():
    b = Builder()
    node = InternalNode([
        LeafNode.build(Variable.build('a')),
        LeafNode.build(Variable.build('b')),
        LeafNode.build(Variable.build('c'))
    ])
    as_list = node.to_list()

    result = b._post_process_node(node, False)
    assert result == [node]
    assert result[0].to_list() == as_list
Beispiel #3
0
def test_build_one_empty_child():
    b = Builder()
    b.add_child(InternalNode.build([]))
    result = b.build()

    assert type(result) is InternalNode
    assert result.get_children() == []
Beispiel #4
0
def test_builder_simplify_times_divide():
    SIMPLEST_STRING = '[a,*,b,/,c]'
    node = NonTerminalSymbol.parse_input(_str_to_token_list('a*b/c'))
    b = InternalNode.Builder()
    b.add_child(node)
    b = b.build()

    assert str(b) == SIMPLEST_STRING
Beispiel #5
0
def test_build_one_child_with_leaf_node_grandchild():
    b = Builder()
    grandchild = LeafNode.build(Variable.build('a'))
    child = InternalNode.build([grandchild])
    b.add_child(child)
    result = b.build()

    assert result is grandchild
Beispiel #6
0
def test_build_many_leaf_node_children():
    b = Builder()
    children = [
        LeafNode.build(Variable.build('a')),
        LeafNode.build(Variable.build('b')),
        LeafNode.build(Variable.build('c'))
    ]
    b.add_child(InternalNode.build(children))
    result = b.build()

    assert type(result) is InternalNode
    assert len(result.get_children()) == len(children)
    for child in children:
        assert child in result.get_children()
Beispiel #7
0
def test_simplify_node_with_many_children():
    b = Builder()
    grandchildren = [
        LeafNode.build(Variable.build('a')),
        LeafNode.build(Variable.build('b')),
        LeafNode.build(Variable.build('c'))
    ]
    for grandchild in grandchildren:
        b.add_child(InternalNode.build([grandchild]))

    result = b.build()

    assert type(result) is InternalNode
    assert len(result.get_children()) == len(grandchildren)
    for grandchild in grandchildren:
        assert grandchild in result.get_children()
class DatasetGeneratorForCreateMessage:
    """Generator of the dataset of requests to createMessage.
    
    Responsible for generating a dataset of message content 
    for sending requests to the createMessage API.

    Attributes:
        root_node: An InternalNode object representing the 
                root of the threading tree for dataset generation.
    """
    def __init__(self):
        """Intializes CsvFileWriter with csv_name, csv_col_names, csv_rows."""

        self.root_node = InternalNode(depth_in_tree=0, parameter_to_value={})

        data = self.root_node.create_child_nodes()
        csv_file_writer = CsvFileWriter(DATASET_FILE_NAME,
                                        ["Metadata", "Data"], data)
        csv_file_writer.write_to_csv()
Beispiel #9
0
def test_simplify_acts_on_all_children():
    b = Builder()
    grandchildren = [
        LeafNode.build(Variable.build('a')),
        LeafNode.build(Variable.build('b')),
        LeafNode.build(Variable.build('c'))
    ]
    children = []
    for grandchild in grandchildren:
        node = InternalNode.build([grandchild])
        b.add_child(node)
        children.append(node)

    b.simplify()

    for grandchild in grandchildren:
        assert grandchild in b._children

    for child in children:
        assert child not in b._children
Beispiel #10
0
    def match(self, token_list):
        # Guard against None token_list
        if token_list is None:
            raise ValueError('SymbolSequence cannot match to None token_list')

        # Track remainder and children
        remainder = token_list
        builder = InternalNode.Builder()

        # Attempt to parse each Token in the list
        for prod_symbol in self._production:
            state = prod_symbol.parse(remainder)

            if state.success():
                builder.add_child(state.node())
                remainder = state.remainder()
            else:
                return FAILURE

        # Return a ParseState containing a new InternalNode for the root and the remainder
        b = builder.build()

        return ParseState.build(b, remainder)
Beispiel #11
0
def test_recurse_on_1_child_str():
    node = InternalNode.build([1])
    assert str(node) == '[1]'
Beispiel #12
0
def test_empty_children_str():
    node = InternalNode.build([])
    assert str(node) == '[]'
Beispiel #13
0
def test_empty_children_list():
    node = InternalNode.build([])
    assert node.to_list() == []
Beispiel #14
0
def test_error_on_none_children():
    with pytest.raises(ValueError):
        InternalNode.build(None)
Beispiel #15
0
def test_build_returns_internal_node():
    node = InternalNode.build([])
    assert type(node) == InternalNode
Beispiel #16
0
def test_add_child_returns_true():
    b = Builder()
    node = InternalNode.build([])
    result = b.add_child(node)

    assert result
Beispiel #17
0
def test_simplify_removes_none_children():
    b = Builder()
    b.add_child(InternalNode.build([]))
    b.simplify()

    assert b._children == []
Beispiel #18
0
def test_post_process_node_no_children():
    b = Builder()
    node = InternalNode.build([])

    assert b._post_process_node(node, False) == []
Beispiel #19
0
def test_post_process_node_one_child():
    b = Builder()
    deep_leaf_node = LeafNode.build(Variable.build('a'))
    node = InternalNode.build([InternalNode.build([deep_leaf_node])])

    assert b._post_process_node(node, False) == [deep_leaf_node]
Beispiel #20
0
def test_recurse_on_many_child_str():
    node = InternalNode.build([1, 2, 3])
    assert str(node) == '[1,2,3]'
Beispiel #21
0
def test_recurse_on_many_child_list():
    node = InternalNode.build([MockNode(), MockNode(), MockNode()])
    assert node.to_list() == [[], [], []]
Beispiel #22
0
def test_add_child_adds_child():
    b = Builder()
    node = InternalNode.build([])
    b.add_child(node)

    assert b._children[0] is node