示例#1
0
def test_controllerInstantiate():
    a = stages2beer.s2b(None)
    assert a.getCtrl() is None
    b = stages2beer.s2b(simpleCtrl())
    assert isinstance(b.getCtrl(), dict)
    assert 'genctrl' in b.getCtrl()
    print myname(), "OK"
示例#2
0
def test_getStages():
    """
    Try different input format for stages and read them back.
       json from recipeReader
       json string
       dict
    """
    r1 = recipeReader.jsonStages(simpleStages(), simpleCtrl())
    a1 = stages2beer.s2b(simpleCtrl(), r1.getStages())
    stages1 = a1.getStages()
    assert isinstance(stages1, dict)
    assert '1stage' in stages1
    assert 'name' not in stages1

    a2 = stages2beer.s2b(simpleCtrl(), simpleDict())
    stages2 = a2.getStages()
    assert isinstance(stages2, dict)
    assert '1 stage' in stages2
    assert 'name' not in stages2

    a4 = stages2beer.s2b(simpleCtrl(), timerDict())
    stages4 = a4.getStages()
    assert isinstance(stages4, dict)
    assert '1 stage' in stages4
    assert 'name' not in stages4
    print myname(), "OK"
示例#3
0
def test_runLongTimer():
    a = stages2beer.s2b(timerCtrl(), multiTimerDict())
    a.start()
    assert a.isAlive()
    a.join()
    assert not a.isAlive()
    print myname(), "OK"
示例#4
0
    def __init__(self, controllers, recipelist, server=myserver.myserver(host="0.0.0.0", port=8080)):
        self.count = 0
        self.wapp = Bottle()
        self.controllers = controllers
        self.recipelist = recipelist
        self.server = server
        self.stages = {}
        self.runningRecipeName = ""
        self.selectedRecipeName = ""
        self.recipeObject = None

        self.switchdict = {"lights": True, "camera": False, "sound": True}

        matplotlib.use("Agg")

        # Routing statements
        self.wapp.route("/status", "GET", self.statusPage)
        self.wapp.route("/", "GET", self.indexPage)
        self.wapp.route("/start", "GET", self.commandPage)
        self.wapp.route("/start", "POST", self.doCommand)
        self.wapp.route("/recipelist", "GET", self.recipeliststatusPage)
        self.wapp.route("/recipelist", "POST", self.dorecipeliststatus)
        self.wapp.route("/debugStages", "GET", self.debugStages)
        self.wapp.route("/readrecipes", "GET", self.getTestRecipeList)

        self.wapp.route("/switchlist", "GET", self.switchliststatusPage)
        self.wapp.route("/switchlist", "POST", self.doswitchliststatus)

        self.wapp.route("/temp", "GET", self.tempPage)
        self.wapp.route("/ingredients", "GET", self.ingredientsPage)
        self.wapp.route("/static/<filename>", "GET", self.server_static)

        self.s2b = stages2beer.s2b(controllers, self.stages)
        self.dl = ctrl.datalogger(controllers)
示例#5
0
def test_runStop():
    a = stages2beer.s2b(simpleCtrl(), simpleDict())
    a.start()
    assert a.isAlive()
    a.stop()
    time.sleep(2)
    assert not a.isAlive()
    print myname(), "OK"
示例#6
0
def test_runSkip():
    a = stages2beer.s2b(simpleCtrl(), simpleDict())
    a.start()
    assert a.isAlive()
    a.skip()
    a.join()
    assert not a.isAlive()
    print myname(), "OK"
示例#7
0
def test_basicThread():
    """
    Basic testing that the thread is working
    """
    a = stages2beer.s2b(simpleCtrl(), simpleDict())
    a.start()
    assert a.isAlive()
    a.stop()
    a.join()
    assert not a.isAlive()
    print myname(), "OK"
示例#8
0
def test_runPause():
    a = stages2beer.s2b(timerCtrl(), timerDict())
    a.start()
    assert a.isAlive()
    a.pause()
    time.sleep(2)
    assert a.isAlive()
    a.unpause()
    a.join()
    assert not a.isAlive()
    print myname(), "OK"
示例#9
0
def test_checkStage():
    a = stages2beer.s2b(timerCtrl(), timerDict())
    assert a.getStage() is None
    a.start()
    time.sleep(0.1)
    a.pause()
    assert a.getStage() == "1 stage"
    a.unpause()
    a.join()
    assert not a.isAlive()
    print myname(), "OK"
示例#10
0
    def doCommand(self):
        print "doCommand"
        runStatus = request.forms.get('runStatus')

        if runStatus == 'stop':
            self.s2b.stop()
            self.dl.stop()
            self.s2b.unpause()
        elif runStatus == 'run':
            print "starting"
            print self.s2b.isAlive()
            if not self.s2b.isAlive():
                self.runningRecipeName = self.selectedRecipeName
                self.s2b = stages2beer.s2b(self.controllers, self.stages)
                self.dl = ctrl.datalogger(self.controllers)
                self.s2b.start()
                self.dl.start()

        pauseState = request.forms.get('pauseState')
        if pauseState == "True":
            self.s2b.pause()
        else:
            self.s2b.unpause()

        skipState = request.forms.get('skipState')
        if skipState == "True":
            self.s2b.skip()

        preHeatState = request.forms.get('preHeatState')
        if preHeatState == "True":
            if not self.s2b.isAlive():
                preHeat = {"name": "heat_only", "recipe":
                           {"01": {"waterHeater": 170}}}
                js = recipeReader.jsonStages(preHeat, self.controllers)
                self.s2b = stages2beer.s2b(self.controllers, js.getStages())
                self.s2b.start()
            else:
                print "Already running, can not switch to preheat"

        return(self.commandPage())
示例#11
0
def test_ThreadEdgeCases():
    a = stages2beer.s2b(None, None)
    a.start()
    time.sleep(0.1)
    assert not a.isAlive()

    b = stages2beer.s2b(simpleCtrl(), None)
    b.start()
    time.sleep(0.1)
    assert not b.isAlive()

    c = stages2beer.s2b(simpleCtrl(), {})
    c.start()
    time.sleep(0.1)
    assert not c.isAlive()

    d = stages2beer.s2b(None, simpleDict())
    d.start()
    time.sleep(0.1)
    assert not d.isAlive()

    print myname(), "OK"
示例#12
0
    def __init__(self, controllers, recipelist,
                 server=myserver.myserver(host="0.0.0.0", port=8080)):
        self.count = 0
        self.wapp = Bottle()
        self.controllers = controllers
        self.recipelist = recipelist
        self.server = server
        self.stages = {}
        self.runningRecipeName = ""
        self.selectedRecipeName = ""
        self.recipeObject = None

        self.switchdict = {"lights": True, "camera": False, "sound": True}

        matplotlib.use('Agg')

        # Routing statements
        self.wapp.route('/status', 'GET', self.statusPage)
        self.wapp.route('/', 'GET', self.indexPage)
        self.wapp.route('/start', 'GET', self.commandPage)
        self.wapp.route('/start', 'POST', self.doCommand)
        self.wapp.route('/recipelist', 'GET', self.recipeliststatusPage)
        self.wapp.route('/recipelist', 'POST', self.dorecipeliststatus)
        self.wapp.route('/debugStages', 'GET', self.debugStages)
        self.wapp.route('/readrecipes', 'GET', self.getTestRecipeList)
        self.wapp.route('/gauges', 'GET', self.getGauges)
        self.wapp.route('/apipath/currentstage', 'GET', self.apicurrentstage)

        self.wapp.route('/switchlist', 'GET', self.switchliststatusPage)
        self.wapp.route('/switchlist', 'POST', self.doswitchliststatus)

        self.wapp.route('/temp', 'GET', self.tempPage)
        self.wapp.route('/ingredients', 'GET', self.ingredientsPage)
        self.wapp.route('/apipath/appliance/<appliance>', 'GET', self.applianceWrap)
        self.wapp.route('/static/<filename>', 'GET', self.server_static)
        self.wapp.route('/js/<filename>', 'GET', self.js)

        self.s2b = stages2beer.s2b(controllers, self.stages)
        self.dl = ctrl.datalogger(controllers)
示例#13
0
def statusPage():
    s2b = stages2beer.s2b(timerCtrl(), timerDict())
    s2b.start()
    rs = statusView.statusView(s2b, False, "test recipe")
    s2b.stop()
    return rs
示例#14
0
            logging.error("Error: bad bsmx recipe")
        else:
            recipeName = b.getRecipeName()
            stages = b.getStages()
    else:
        recipeName = ""
        stages = {}

    equipmentchecker = checker.equipment(controllers, stages)
    if not equipmentchecker.check():
        logging.error("Error: equipment vs recipe validation failed")

    logging.info("Running " + recipeName)

    if (stages != {}) and (stages is not None):
        brun = stages2beer.s2b(controllers, stages)
        dl = ctrl.datalogger(controllers)

        if checkonly:
            if brun.check():
                logging.info("Check OK")
            else:
                logging.info("ERROR: Check failed")
                sys.exit(1)
        elif quick:
            if brun.quickRun():
                logging.info("Quick run OK")
            else:
                logging.error("ERROR: Quick run failed")
                sys.exit(1)
        else:
示例#15
0
def test_instantiate():
    a = stages2beer.s2b()
    assert a is not None
    print myname(), "OK"
示例#16
0
def test_simpleStages():
    stages = simpleDict()
    a = stages2beer.s2b(simpleCtrl(), stages)
    a.check()
    print myname(), "OK"
示例#17
0
def test_check():
    r = recipeReader.jsonStages(simpleStages(), simpleCtrl())
    a = stages2beer.s2b(simpleCtrl(), r.getStages())
    assert a.check()
    print myname(), "OK"