def testOutputfileDefaultValue(self): """ Outputfile should be sys.stdout if missing """ ymlparamsfile = '%s/minimalconfig.yml' % self.fixturesdir params = YamlParamsParser(ymlparamsfile) self.assertEqual(params['outputfilename'], 'sys.stdout')
def testRandomseedDefaultValue(self): """ Randomseed should be None if missing """ ymlparamsfile = '%s/minimalconfig.yml' % self.fixturesdir params = YamlParamsParser(ymlparamsfile) self.assertEqual(params['randomseed'], None)
def testRandomSeedValue(self): """ Randomseed is read correctly """ ymlparamsfile = '%s/fullconfig.yml' % self.fixturesdir params = YamlParamsParser(ymlparamsfile) self.assertEqual(params['randomseed'], 12345678)
def testUniqueByAgentDefaultValue(self): """ unique_by_agent value is True if missing """ ymlparamsfile = '%s/minimalconfig.yml' % self.fixturesdir params = YamlParamsParser(ymlparamsfile) self.assertTrue(params['unique_by_agent'])
def testCsvDelimiterDefaultValue(self): """ csvdelimiter value is ';' if missing """ ymlparamsfile = '%s/minimalconfig.yml' % self.fixturesdir params = YamlParamsParser(ymlparamsfile) self.assertEqual(params['csvdelimiter'], ';')
def testOrdersLogFileDefaultValue(self): """ OrdersLogFile shoud be None if missing """ ymlparamsfile = '%s/minimalconfig.yml' % self.fixturesdir params = YamlParamsParser(ymlparamsfile) self.assertEqual(params['orderslogfilename'], None)
def testExperimentNameValue(self): """ Experiment name is correctly read """ ymlparamsfile = '%s/fullconfig.yml' % self.fixturesdir params = YamlParamsParser(ymlparamsfile) self.assertEqual(params['name'], 'Test Experiment')
def testDaylengthValue(self): """ Daylength is correctly read as an int """ ymlparamsfile = '%s/fullconfig.yml' % self.fixturesdir params = YamlParamsParser(ymlparamsfile) self.assertEqual(params['engines'][0]['daylength'], 10)
def testClearBooksAtEODValue(self): """ Engine's clearbooksateod param is correctly read """ ymlparamsfile = '%s/fullconfig.yml' % self.fixturesdir params = YamlParamsParser(ymlparamsfile) self.assertFalse(params['engines'][0]['clearbooksateod'])
def testDaylengthDefaultValue(self): """ Daylength should be 1 if missing """ ymlparamsfile = '%s/minimalconfig.yml' % self.fixturesdir params = YamlParamsParser(ymlparamsfile) self.assertEqual(params['engines'][0]['daylength'], 1)
def testClearBooksAtEODDefaultValue(self): """ Clear books at end of day if this param is missing """ ymlparamsfile = '%s/minimalconfig.yml' % self.fixturesdir params = YamlParamsParser(ymlparamsfile) self.assertTrue(params['engines'][0]['clearbooksateod'])
def testWorldClassValue(self): """ World class is read correctly """ ymlparamsfile = '%s/minimalconfig.yml' % self.fixturesdir params = YamlParamsParser(ymlparamsfile) self.assertEqual(params['world']['classname'], 'NullWorld')
def testMarketClassValue(self): """ Market param classname is read correctly """ ymlparamsfile = '%s/minimalconfig.yml' % self.fixturesdir params = YamlParamsParser(ymlparamsfile) self.assertEqual(params['engines'][0]['market']['classname'], 'ContinuousOrderDriven')
def testEngineClassValue(self): """ Engine classname is read correctly """ ymlparamsfile = '%s/minimalconfig.yml' % self.fixturesdir params = YamlParamsParser(ymlparamsfile) self.assertEqual(params['engines'][0]['classname'], 'AsynchronousRandWReplace')
def testOuputfileValue(self): """ Outputfile might be read from config """ ymlparamsfile = '%s/fullconfig.yml' % self.fixturesdir params = YamlParamsParser(ymlparamsfile) self.assertEqual(params['outputfilename'], '%s/dummyoutput.csv' % self.fixturesdir)
def testExperimentNameDefaultValue(self): """ Experiment name is built from filename if missing """ ymlparamsfile = '%s/minimalconfig.yml' % self.fixturesdir params = YamlParamsParser(ymlparamsfile) self.assertEqual(params['name'], '%s/minimalconfig.yml experiment' % self.fixturesdir)
def testOrderLogFileValue(self): """ OrdersLogFile might be read from config """ ymlparamsfile = '%s/fullconfig.yml' % self.fixturesdir params = YamlParamsParser(ymlparamsfile) self.assertEqual(params['orderslogfilename'], '%s/dummyoutput.log' % self.fixturesdir)
def _get_params(args, opts): """ Get params from conffile """ logger = logging.getLogger('fms') simconffile = _get_simconffile(args) if os.path.splitext(simconffile)[-1] == '.xml': logger.debug("Calling XmlParamsParser on %s" % simconffile) params = XmlParamsParser(simconffile) else: logger.debug("Calling YamlParamsParser on %s" % simconffile) params = YamlParamsParser(simconffile) params['simconffile'] = simconffile params = _apply_opts(params, opts) params.printparams() return params
else: suite.addTest(doctest.DocFileSuite( os.path.join(os.path.split(root)[1], f), package='fms.contrib.%s' % t, optionflags=+doctest.ELLIPSIS)) else: suite.addTest(doctest.DocFileSuite( os.path.join(os.path.split(root)[1], f), package='fms', optionflags=+doctest.ELLIPSIS)) unittest.TextTestRunner(verbosity=2).run(suite) for simconffile in expList(): logger.info("Running %s" % simconffile) params = YamlParamsParser(simconffile) params['show_books'] = False params['timer'] = False params.outputfile = StringIO() (world, engineslist, agentslist) = fms.core.set_classes(params) for e in engineslist: e['instance'].run(world, agentslist, e['market']['instance']) benchfile = "%s.csv" % simconffile.split('.')[0] benchmark = open(benchfile).read() testresult = params.outputfile.getvalue() if not benchmark == testresult: logger.error("%s failed" % simconffile) print testresult else: logger.info("%s ok" % simconffile) params.close_files(1)