def test_log_write(): l = Log('test.log') msg = 'Hello' l.message(msg) # Re-open file in read mode l.file = open('test.log', 'r') # Test for message with a newline appended assert l.file.readline() == msg + '\n'
def main(mode, competition, model, batch, season, start): settings = Settings(mode, competition, model, batch, season, start) # Reflect back the configuration being used click.echo(settings.output()) # Initialize tooling click.echo('Initializing tooling...') filename = date.today().strftime("%y%m%d") + '-' + mode + '-' + model log = Log('logs/' + filename + '.log') log.message('Started') output = Log('output/' + filename + '.csv') db = Database() db.connect() log.message('Database connected') # Initialize data click.echo('Initializing data...') league = League() league.connectDB() league.lookupTeamsBySeason(settings.values['season'], settings.values['competition'], settings.values['start'], log) game = Game() game.connectDB() game.lookupGamesBySeason(settings.values['season'], settings.values['competition'], settings.values['start'], log) # Output the starting point for simulation, including the standings. click.echo(league.printStandings()) log.message(league.printStandings()) # Write top lines of output/labels once output.message(league.outputLine('Conference', league.teams)) output.message(league.outputLine('Abbv', league.teams)) # Iterate over games for i in range(settings.values['batch']): log.message("Season " + str(i)) league.simulateSeason(game, settings.values['model'], log) output.message(league.outputLine('Points', league.standings)) # Teardown click.echo('Finishing...') db.disconnect() log.message('Database disconnected') log.end()