initialise repo
[debian/make-magic.git] / tests / junktest.py
1 #! /usr/bin/env python
2 from core.deptools import *
3 from breakfast import *
4
5 # Pure python defined item test code
6 #
7 # Tests that we can define items in pure python code and have the marshallers
8 # convert it back and forth several times to simple dicts and JSON without
9 # any loss of information
10 #
11 # THIS IS NOT AN EXAMPLE OF GENERAL USAGE!
12 #
13 # TODO: Move this into unit testing
14
15 coffee_drinker = breakfast_task_factory.task_from_requirements( ('coffee','hugs') )
16 caffeine_free = breakfast_task_factory.task_from_requirements( ('hugs',) )
17
18 ds = DigraphDependencyStrategy
19
20 print coffee_drinker
21 for item in ds.iterate_item_dependencies(coffee_drinker.goal):
22         print item
23
24 print
25 print caffeine_free
26 for item in ds.iterate_item_dependencies(caffeine_free.goal):
27         print item
28
29 # Marshalling
30
31 import core.marshal
32 import lib.loaders
33 import json
34
35 print "\nconverting breakfast task to json:"
36 ic = core.marshal.ItemConverter()
37 objitems = map(ic.itemclass_to_itemdict, breakfast_task_factory.classes)
38
39 jsondata = json.dumps(objitems)
40 print jsondata
41
42
43 print "\nimporting back in"
44 task_factory = lib.loaders.JSONItemLoader.load_item_classes_from_string(jsondata)
45 for c in task_factory.classes:
46         print c()
47
48 print "\nand back again"
49 objitems = map(ic.itemclass_to_itemdict, breakfast_task_factory.classes)
50 jsondata = json.dumps(objitems)
51 task_factory = lib.loaders.JSONItemLoader.load_item_classes_from_string(jsondata)
52
53 print "\nNow trying another pruning example:"
54 another_caffeine_free = task_factory.task_from_requirements( [] )
55 for item in ds.iterate_item_dependencies(another_caffeine_free.goal):
56         print item