def test_parse_time_string(self): """Testing parsing string representing time to a Time namedtuple""" self.assertEqual(utils.parse_time_string('7:00'), utils.Time(hour=7, minute=0)) self.assertEqual(utils.parse_time_string('0:0'), utils.Time(hour=0, minute=0)) self.assertEqual(utils.parse_time_string('000000001:00000'), utils.Time(hour=1, minute=0)) self.assertEqual(utils.parse_time_string('18:00000001'), utils.Time(hour=18, minute=1)) self.assertEqual(utils.parse_time_string('22:59'), utils.Time(hour=22, minute=59)) self.assertEqual(utils.parse_time_string('1:45'), utils.Time(hour=1, minute=45)) self.assertEqual(utils.parse_time_string('0000002:000003'), utils.Time(hour=2, minute=3)) with self.assertRaises(utils.InvalidTimeError): utils.parse_time_string('12') with self.assertRaises(utils.InvalidTimeError): utils.parse_time_string('1:2:3;4') with self.assertRaises(utils.InvalidTimeError): utils.parse_time_string('34:') with self.assertRaises(utils.InvalidTimeError): utils.parse_time_string(':5') with self.assertRaises(utils.InvalidTimeError): utils.parse_time_string(':') with self.assertRaises(utils.InvalidTimeError): utils.parse_time_string('not an int:but nice try') with self.assertRaises(utils.InvalidTimeError): utils.parse_time_string('34:00') with self.assertRaises(utils.InvalidTimeError): utils.parse_time_string('00:65') with self.assertRaises(utils.InvalidTimeError): utils.parse_time_string('-46:00') with self.assertRaises(utils.InvalidTimeError): utils.parse_time_string('00:-34')
def load_config(path): """ Load the configuration file from path and set defaults if not given. The configuration is set to the CONFIG global variable. :type path: str :param path: path to the conf file """ global CONFIG conf = configparser.ConfigParser() conf.read(path) CONFIG = { 'basic': { 'dm_errors': conf['basic'].getboolean('dm_errors', True), 'units': conf['basic'].get('units', 'us'), 'tweet_location': conf['basic'].getboolean('tweet_location', True), 'hashtag': conf['basic'].get('hashtag', '#MorrisWeather'), 'refresh': conf['basic'].getint('refresh', 3), 'strings': conf['basic'].get('strings', 'strings.yml') }, 'scheduled_times': { 'forecast': utils.parse_time_string(conf['scheduled times'].get('forecast', '6:00')), 'conditions': utils.get_times(conf['scheduled times'].get('conditions', '7:00\n12:00\n15:00\n18:00\n22:00')) }, 'default_location': models.WeatherLocation(lat=conf['default location'].getfloat('lat', 45.585), lng=conf['default location'].getfloat('lng', -95.91), name=conf['default location'].get('name', 'Morris, MN')), 'variable_location': { 'enabled': conf['variable location'].getboolean('enabled', False), 'user': conf['variable location'].get('user', 'BrianMitchL'), 'unnamed_location_name': conf['variable location'].get('unnamed_location_name', 'The Wilderness') }, 'log': { 'enabled': conf['log'].getboolean('enabled', True), 'log_path': conf['log'].get('log_path', os.path.expanduser('~') + '/weatherBot.log') }, 'throttles': { 'default': conf['throttles'].getint('default', 120), 'wind-chill': conf['throttles'].getint('wind-chill', 120), 'medium-wind': conf['throttles'].getint('medium-wind', 180), 'heavy-wind': conf['throttles'].getint('heavy-wind', 120), 'fog': conf['throttles'].getint('fog', 180), 'cold': conf['throttles'].getint('cold', 120), 'hot': conf['throttles'].getint('hot', 120), 'dry': conf['throttles'].getint('dry', 120), 'heavy-rain': conf['throttles'].getint('heavy-rain', 60), 'moderate-rain': conf['throttles'].getint('moderate-rain', 60), 'light-rain': conf['throttles'].getint('light-rain', 90), 'very-light-rain': conf['throttles'].getint('very-light-rain', 120), 'heavy-snow': conf['throttles'].getint('heavy-snow', 60), 'moderate-snow': conf['throttles'].getint('moderate-snow', 60), 'light-snow': conf['throttles'].getint('light-snow', 90), 'very-light-snow': conf['throttles'].getint('very-light-snow', 120), 'heavy-sleet': conf['throttles'].getint('heavy-sleet', 45), 'moderate-sleet': conf['throttles'].getint('moderate-sleet', 60), 'light-sleet': conf['throttles'].getint('light-sleet', 90), 'very-light-sleet': conf['throttles'].getint('very-light-sleet', 120), 'heavy-hail': conf['throttles'].getint('heavy-hail', 15), 'moderate-hail': conf['throttles'].getint('moderate-hail', 15), 'light-hail': conf['throttles'].getint('light-hail', 20), 'very-light-hail': conf['throttles'].getint('very-light-hail', 30) } }
def load_config(path): """ Load the configuration file from path and set defaults if not given. The configuration is set to the CONFIG global variable. :type path: str :param path: path to the conf file """ global CONFIG conf = configparser.ConfigParser() conf.read(path) CONFIG = { 'basic': { 'dm_errors': conf['basic'].getboolean('dm_errors', True), 'units': conf['basic'].get('units', 'us'), 'tweet_location': conf['basic'].getboolean('tweet_location', True), 'hashtag': conf['basic'].get('hashtag', '#MorrisWeather'), 'refresh': conf['basic'].getint('refresh', 3), 'strings': conf['basic'].get('strings', 'strings.yml') }, 'scheduled_times': { 'forecast': utils.parse_time_string(conf['scheduled times'].get('forecast', '6:00')), 'conditions': utils.get_times(conf['scheduled times'].get('conditions', '7:00\n12:00\n15:00\n18:00\n22:00')) }, 'default_location': models.WeatherLocation(lat=conf['default location'].getfloat('lat', 45.585), lng=conf['default location'].getfloat('lng', -95.91), name=conf['default location'].get('name', 'Morris, MN')), 'variable_location': { 'enabled': conf['variable location'].getboolean('enabled', False), 'user': conf['variable location'].get('user', 'BrianMitchL') }, 'log': { 'enabled': conf['log'].getboolean('enabled', True), 'log_path': conf['log'].get('log_path', os.path.expanduser('~') + '/weatherBot.log') }, 'throttles': { 'default': conf['throttles'].getint('default', 120), 'wind-chill': conf['throttles'].getint('wind-chill', 120), 'medium-wind': conf['throttles'].getint('medium-wind', 180), 'heavy-wind': conf['throttles'].getint('heavy-wind', 120), 'fog': conf['throttles'].getint('fog', 180), 'cold': conf['throttles'].getint('cold', 120), 'hot': conf['throttles'].getint('hot', 120), 'dry': conf['throttles'].getint('dry', 120), 'heavy-rain': conf['throttles'].getint('heavy-rain', 60), 'moderate-rain': conf['throttles'].getint('moderate-rain', 60), 'light-rain': conf['throttles'].getint('light-rain', 90), 'very-light-rain': conf['throttles'].getint('very-light-rain', 120), 'heavy-snow': conf['throttles'].getint('heavy-snow', 60), 'moderate-snow': conf['throttles'].getint('moderate-snow', 60), 'light-snow': conf['throttles'].getint('light-snow', 90), 'very-light-snow': conf['throttles'].getint('very-light-snow', 120), 'heavy-sleet': conf['throttles'].getint('heavy-sleet', 45), 'moderate-sleet': conf['throttles'].getint('moderate-sleet', 60), 'light-sleet': conf['throttles'].getint('light-sleet', 90), 'very-light-sleet': conf['throttles'].getint('very-light-sleet', 120), 'heavy-hail': conf['throttles'].getint('heavy-hail', 15), 'moderate-hail': conf['throttles'].getint('moderate-hail', 15), 'light-hail': conf['throttles'].getint('light-hail', 20), 'very-light-hail': conf['throttles'].getint('very-light-hail', 30) } }