Пример #1
0
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)
Пример #2
0
class Test_OD_interface_1():

    filename = 'temp'
    OD = db.OD_Scaffold('temp')
    OD_type = db.OD_Scaffold

    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 test_remove_1(self, tree_1):

        assert tree_1.get_node('fruit').name == 'fruit'
        assert tree_1.get_node('dessert').name == 'dessert'
        assert tree_1.get_node('meat').name == 'meat'

        tree_1.remove(tree_1.get_node('meat'))

        with pytest.raises(Exception):
            tree_1.get_node('meat')

    def test_iter_1(self, tree_1):

        tree_names = set()

        for tree_node in tree_1:
            tree_names.add(tree_node.name)

        assert tree_names == {'fruit', 'dessert', 'meat'}

    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'
Пример #3
0
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)
Пример #4
0
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
Пример #5
0
	def __init__(self, **kwargs):
		super().__init__(**kwargs)
		self.transition = FallOutTransition()

		ingredient_data = db.OD_Scaffold('ingredients.json')
		self.add_widget(ig.Ingredients_Screen(ingredient_data, self))
		
		quantities_data = db.OD_Scaffold('quantities.json')
		self.add_widget(qt.Quantities_Screen(quantities_data, self))

		cookbook_data = db.OD_Scaffold('cookbook.json')

		cookbook_data.attach_core(ingredient_data, dbl.process_core_node_db, dbl.process_obs_recipe_ing)
		cookbook_data.attach_core(quantities_data, dbl.process_core_node_db, dbl.process_obs_recipe_qtype)
		
		shop_cook_filename = 'shopping_cookbook.json'
		if os.path.exists(shop_cook_filename):
			os.remove(shop_cook_filename)
		shopping_cookbook_data = db.OD_Scaffold(shop_cook_filename)

		RM = rm.Recipe_Manager(cookbook_data)

		self.add_widget(cb.Cookbook_Home_Screen(RM, cookbook_data, shopping_cookbook_data, self))

		self.add_widget(arm.Recipe_Home_Screen(self, RM))

		self.add_widget(ari.Ingredients_Select_Screen(ingredient_data, self, RM))

		self.add_widget(arq.Quantity_Select_Screen(quantities_data, self, RM))

		shop_quantity_filename = 'shopping_quantity.json'
		if os.path.exists(shop_quantity_filename):
			os.remove(shop_quantity_filename)
		shop_quantity_data = db.OD_Scaffold(shop_quantity_filename)

		self.add_widget(sc.Shopping_Cookbook_Screen(shopping_cookbook_data, shop_quantity_data, self))

		self.add_widget(sq.Shopping_Quantity_Screen(shop_quantity_data, self))
Пример #6
0
    def __init__(self):
        super().__init__()
        ingredient_data = db.OD_Scaffold('ingredients')

        # kwargs = {'pos_hint': {'top': 0.9}}
        VD = view.View_Nodes_Scaffold(ingredient_data)
        # VD.pos_hint['y'] = 0.5
        # VD.do_layout()
        self.add_widget(VD)
        self.VD = VD

        kwargs = {'pos_hint': {'top': 1}, 'size_hint': (1, 0.1)}
        B = Button(text='Move Down', **kwargs)
        self.add_widget(B)
        B.bind(on_press=self.B_press)
Пример #7
0
	def __init__(self, path=None, **view_kwargs):
		'''
		Path must point a directory with data files that are all of the same data
		'''
		self.filename2dag = {}
		self.filename2dag_view = {}
		self.db_scaffold = None
		self.view_scaffold = None

		if path == None:
			path = os.getcwd()

		for file in os.listdir(path):
			if file.endswith('_graph.json'):
				filename = str(file).split('_graph.json')[0]
				currDB = db.OD_DAG(filename)
				self.filename2dag[filename] = currDB 
				self.filename2dag_view[filename] = view.View_Nodes_Scroll(currDB, **view_kwargs)

		if self.filename2dag != {}:
			self.db_scaffold = db.OD_Scaffold(filename)
			self.view_scaffold = view.View_Nodes_Scroll(self.db_scaffold, **view_kwargs)