class Test_plugin(unittest.TestCase): def setUp(self): # work around logger self.stream_handler = logging.StreamHandler(sys.stdout) logger.addHandler(self.stream_handler) logging.getLogger().info("# set up test for dwd") self.plugin = BasePlugin() #plugin() config = configparser.ConfigParser() config.read_file(codecs.open(r"./test/my_config.ini", encoding="utf-8")) self.dwd = self.readAndCreate(config, CONFIG_SECTION_MY) self.plugin.dwd = self.dwd def tearDown(self): logging.getLogger().info("# tear down: test for dwd") if self.plugin: self.plugin = None # remove logger logger.removeHandler(self.stream_handler) def test_A_onStart(self): logging.getLogger().info("#fake start of plugin") #TODO call: self.plugin.onStart() def test_B_onHeartbeat(self): logging.getLogger().info("#fake heart beat") #TODO call: self.plugin.onStart() self.plugin.onHeartbeat() def test_C_onStop(self): logging.getLogger().info("#fake stop") #TODO call: self.plugin.onStop() def readAndCreate(self, aConfig, aSection): """creates a dwd object based on config Args: aConfig ([type]): [configuration holding the settings] Returns: [dwd]: [dwd object] """ self.assertTrue( aConfig.has_section(aSection), "we need this set up: " + aSection, ) cellId = aConfig.get(aSection, "cellId") region = aConfig.get(aSection, "region") Parameters['Mode1'] = cellId Parameters['Mode2'] = region Parameters['Mode3'] = "event" rT: RegionType = RegionType.getByName(region) aDwd = Dwd(dwdWarnCellId=cellId, regionType=rT) return aDwd
def runtest(): fakeDomoticz.Start() plugin = BasePlugin() plugin.onStart() # plugin.onCommand(1, '', '', '') plugin.onHeartbeat() plugin.onHeartbeat() plugin.onStop()
class Test_plugin(unittest.TestCase): def setUp(self): # work around logger self.stream_handler = logging.StreamHandler(sys.stdout) logger.addHandler(self.stream_handler) logging.getLogger().info("# set up test for bsr") self.plugin = BasePlugin() #plugin() config = configparser.ConfigParser() config.read_file(codecs.open(r"./test/my_config.ini", encoding="utf-8")) self.bsr = self.readAndCreate(config, CONFIG_SECTION_MY) self.plugin.bsr = self.bsr def tearDown(self): logging.getLogger().info("# tear down: test for bsr") if self.plugin: self.plugin = None # remove logger logger.removeHandler(self.stream_handler) def test_onStart(self): logging.getLogger().info("#fake start of plugin") #TODO call: self.plugin.onStart() def test_onHeartbeat(self): logging.getLogger().info("#fake heart beat") #TODO call: self.plugin.onHeartbeat() def test_onStop(self): logging.getLogger().info("#fake stop") #TODO call: self.plugin.onStop() def readAndCreate( self, aConfig, aSection, showHouseholdWaste: bool = True, showRecycleWaste: bool = True, showBioWaste: bool = True, showXmasWaste: bool = False, debugResponse: bool = False, ): """creates a bsr object based on config Args: aConfig ([type]): [configuration holding the address] Returns: [Bsr]: [bsr object] """ self.assertTrue( aConfig.has_section(aSection), "we need this set up: " + aSection, ) str = aConfig.get(aSection, "street") zip = aConfig.get(aSection, "zip") nr = aConfig.get(aSection, "nr") aBsr = Bsr( street=str, zipCode=zip, houseNumber=nr, ) return aBsr