def test_update_3():

    core_name = 'temp_core'
    if os.path.exists(core_name):
        os.remove(core_name)
    core_data = db.OD_Scaffold(core_name)

    obs_name = 'temp_observer'
    if os.path.exists(obs_name):
        os.remove(obs_name)
    obs_data = db.OD_Scaffold(obs_name)

    qt1 = nd.Node('cups')
    qt2 = nd.Node('packages')
    core_data.add(qt1)
    core_data.add(qt2)

    QI1 = nd.Quantity_Ingredient(quantity=1, quantity_type='cups', name='ing1')
    QI2 = nd.Quantity_Ingredient(quantity=1,
                                 quantity_type='packages',
                                 name='ing2')

    R1 = nd.Recipe_Node(name='R1')
    R1.QI_list.append(QI1)

    R12 = nd.Recipe_Node(name='R12')
    R12.QI_list.append(QI1)
    R12.QI_list.append(QI2)

    R2 = nd.Recipe_Node(name='R2')
    R2.QI_list.append(QI2)

    obs_data.add(R1)
    obs_data.add(R12)
    obs_data.add(R2)

    assert R1 in obs_data
    assert R12 in obs_data
    assert R2 in obs_data

    obs_data.attach_core(core_data, dbl.process_core_node_db,
                         dbl.process_obs_recipe_qtype)

    core_data.remove(qt1)
    core_data.update_observers()

    assert R1 not in obs_data
    assert R12 not in obs_data
    assert R2 in obs_data

    core_name = 'temp_core'
    if os.path.exists(core_name):
        os.remove(core_name)

    obs_name = 'temp_observer'
    if os.path.exists(obs_name):
        os.remove(obs_name)
    def test_add_1(self):

        fruit_node = nd.Node('fruit')
        dessert_node = nd.Node('dessert')

        self.OD.add(fruit_node)
        self.OD.add(dessert_node)

        assert self.OD.get_node('fruit') == fruit_node
        assert self.OD.get_node('dessert') == dessert_node
def tree_1():

    OD = db.OD_Scaffold('temp')

    fruit_node = nd.Node('fruit')
    dessert_node = nd.Node('dessert')
    meat_node = nd.Node('meat')

    OD.add(fruit_node)
    OD.add(dessert_node)
    OD.add(meat_node)

    return OD
def OD_1():

	filename = 'DAG_temp'
	remove_files(filename)
	
	OD = db.OD_DAG(filename)

	beans = nd.Node('Beans')
	r_beans = nd.Node('Red Beans')
	b_beans = nd.Node('Black Beans')

	OD.add(beans)
	OD.add(r_beans, beans)
	OD.add(b_beans, beans)

	return OD
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.transition = FallOutTransition()
        my_db = db.OD_DAG('ingredients')
        beans = nd.Node('Beans')
        black_beans = nd.Node('Black Beans')
        red_beans = nd.Node('Red Beans')
        my_db.add(beans)
        my_db.add(black_beans, beans)
        my_db.add(red_beans, beans)
        my_db.save()

        path = None

        self.add_widget(Test_Screen(path, self))
        self.add_widget(Test_New_Data_Node())
def test_update_2():

    core_name = 'temp_core.json'
    if os.path.exists(core_name):
        os.remove(core_name)
    core_data = db.OD_Scaffold(core_name)

    obs_name = 'temp_observer.json'
    if os.path.exists(obs_name):
        os.remove(obs_name)
    obs_data = db.OD_Scaffold(obs_name)

    ing1 = nd.Node('ing1')
    ing2 = nd.Node('ing2')
    ing3 = nd.Node('ing3')
    core_data.add(ing1)
    core_data.add(ing2)
    core_data.add(ing3)

    obs_data.add(ing1)
    obs_data.add(ing2)
    obs_data.add(ing3)

    assert ing1 in obs_data
    assert ing2 in obs_data
    assert ing3 in obs_data

    obs_data.attach_core(core_data, dbl.process_core_node_db,
                         dbl.process_obs_node_db)
    core_data.remove(ing1)
    core_data.update_observers()

    assert ing1 not in obs_data
    assert ing2 in obs_data
    assert ing3 in obs_data

    core_name = 'temp_core.json'
    if os.path.exists(core_name):
        os.remove(core_name)

    obs_name = 'temp_observer.json'
    if os.path.exists(obs_name):
        os.remove(obs_name)
    def test_save_1(self):

        fruit_node = nd.Node('fruit')
        dessert_node = nd.Node('dessert')
        self.OD.add(fruit_node)
        self.OD.add(dessert_node)

        assert self.OD.get_node('fruit').name == 'fruit'
        assert self.OD.get_node('dessert').name == 'dessert'

        self.OD.save()
        self.OD = None

        with pytest.raises(Exception):
            self.OD.get_node('fruit')

        self.OD = self.OD_type(self.filename)

        assert self.OD.get_node('fruit').name == 'fruit'
        assert self.OD.get_node('dessert').name == 'dessert'
Exemple #8
0
    def _load_file(self):
        if os.path.exists(self.filename + '_node_data.json'):
            with open(self.filename + '_node_data.json', 'r') as f:
                data = json.load(f)

            for v in data.values():
                curr_node = None

                if v.get('is_node', False):
                    curr_node = nd.Node(json_data=v)
                elif v.get('is_QI', False):
                    curr_node = nd.Quantity_Ingredient(json_data=v)
                elif v.get('is_recipe', False):
                    curr_node = nd.Recipe_Node(json_data=v)

                if curr_node != None:
                    self.add(curr_node)
def test_iter(OD_1):

	beans = OD_1.get_node('Beans')
	r_beans = OD_1.get_node('Red Beans')
	b_beans = OD_1.get_node('Black Beans')
	cherry = nd.Node('Cherry')
	OD_1.add(cherry)

	i = OD_1.__iter__()
	
	next_node_name = i.__next__().name
	assert (next_node_name == beans.name) or (next_node_name == cherry.name)
	next_node_name = i.__next__().name
	assert (next_node_name == beans.name) or (next_node_name == cherry.name)

	next_node_name = i.__next__().name
	assert (next_node_name == r_beans.name) or (next_node_name == b_beans.name)
	next_node_name = i.__next__().name
	assert (next_node_name == r_beans.name) or (next_node_name == b_beans.name)
def test_update_1(OD_1):

	filename = 'DAG_temp_2'
	remove_files(filename)

	b_beans = nd.Node(OD_1.get_node('Black Beans').name)
	r_beans = OD_1.get_node('Red Beans')

	OD_2 = db.OD_DAG(filename)
	OD_2.add(b_beans)
	OD_2.add(r_beans)

	assert b_beans in OD_2
	assert r_beans in OD_2

	OD_2.attach_core(OD_1, process_core=dbl.process_core_node_db)
	OD_1.remove(b_beans)
	OD_1.update_observers()

	assert b_beans not in OD_2
	assert r_beans in OD_2
Exemple #11
0
    def _load_file(self):
        if os.path.exists(self.filename + '_graph.json'):
            with open(self.filename + '_graph.json', 'r') as f:
                graph_json = json.load(f)
                self.graph = json_graph.node_link_graph(graph_json)

        if os.path.exists(self.filename + '_node_data.json'):
            with open(self.filename + '_node_data.json', 'r') as f:
                data = json.load(f)

            for v in data.values():
                curr_node = None

                if v.get('is_node', False):
                    curr_node = nd.Node(json_data=v)
                elif v.get('is_QI', False):
                    curr_node = nd.Quantity_Ingredient(json_data=v)
                elif v.get('is_recipe', False):
                    curr_node = nd.Recipe_Node(json_data=v)

                if curr_node != None:
                    self.data[curr_node.name] = curr_node
 def my_node(self):
     return nd.Node(name=self.pop_layout.data_dict['name'])