Esempio n. 1
0
 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')
Esempio n. 2
0
    def test_config(self):
        """Testing config file handling"""
        equal = {
            'basic': {
                'dm_errors': False,
                'units': 'si',
                'tweet_location': False,
                'hashtag': '',
                'refresh': 300,
                'strings': 'fake_path.yml'
            },
            'scheduled_times': {
                'forecast': utils.Time(hour=6, minute=0),
                'conditions': [utils.Time(hour=7, minute=0),
                               utils.Time(hour=12, minute=0),
                               utils.Time(hour=15, minute=0),
                               utils.Time(hour=18, minute=0),
                               utils.Time(hour=22, minute=0)]
            },
            'default_location': models.WeatherLocation(-79.0, 12.0, 'Just a Test'),
            'variable_location': {
                'enabled': True,
                'user': '******',
                'unnamed_location_name': 'Somewhere in deep space'
            },
            'log': {
                'enabled': False,
                'log_path': '/tmp/weatherBotTest.log'
            },
            'throttles': {
                'default': 24,
                'wind-chill': 23,
                'medium-wind': 22,
                'heavy-wind': 21,
                'fog': 20,
                'cold': 19,
                'hot': 18,
                'dry': 17,
                'heavy-rain': 16,
                'moderate-rain': 15,
                'light-rain': 14,
                'very-light-rain': 13,
                'heavy-snow': 12,
                'moderate-snow': 11,
                'light-snow': 10,
                'very-light-snow': 9,
                'heavy-sleet': 8,
                'moderate-sleet': 7,
                'light-sleet': 6,
                'very-light-sleet': 5,
                'heavy-hail': 4,
                'moderate-hail': 3,
                'light-hail': 2,
                'very-light-hail': 1
            }
        }

        conf = configparser.ConfigParser()
        conf['basic'] = {
            'dm_errors': 'off',
            'units': 'si',
            'tweet_location': 'no',
            'hashtag': '',
            'refresh': '300',
            'strings': 'fake_path.yml'
        }
        conf['scheduled times'] = {
            'forecast': '6:00',
            'conditions': '7:00\n12:00\n15:00\n18:00\n22:00'
        }
        conf['default location'] = {
            'lat': '-79',
            'lng': '12',
            'name': 'Just a Test'
        }
        conf['variable location'] = {
            'enabled': 'yes',
            'user': '******',
            'unnamed_location_name': 'Somewhere in deep space'
        }
        conf['log'] = {
            'enabled': '0',
            'log_path': '/tmp/weatherBotTest.log'
        }
        conf['throttles'] = {
            'default': '24',
            'wind-chill': '23',
            'medium-wind': '22',
            'heavy-wind': '21',
            'fog': '20',
            'cold': '19',
            'hot': '18',
            'dry': '17',
            'heavy-rain': '16',
            'moderate-rain': '15',
            'light-rain': '14',
            'very-light-rain': '13',
            'heavy-snow': '12',
            'moderate-snow': '11',
            'light-snow': '10',
            'very-light-snow': '9',
            'heavy-sleet': '8',
            'moderate-sleet': '7',
            'light-sleet': '6',
            'very-light-sleet': '5',
            'heavy-hail': '4',
            'moderate-hail': '3',
            'light-hail': '2',
            'very-light-hail': '1'
        }
        with open(os.getcwd() + '/weatherBotTest.conf', 'w') as configfile:
            conf.write(configfile)
        weatherBot.load_config(os.path.abspath('weatherBotTest.conf'))
        self.assertDictEqual(weatherBot.CONFIG, equal)
        os.remove(os.path.abspath('weatherBotTest.conf'))
Esempio n. 3
0
 def test_get_times(self):
     """Testing converting a string of times into a list of Time namedtuples"""
     raw_simple = '7:00\n12:00\n15:00\n18:00\n22:00'
     raw_complex = '0:0\n00000000001:00000\n18:00000001\n22:59\n23:00\n1:45\n00:00\n23:59\n1:01\n01:00\n01:02\n11:32'
     list_simple = [utils.Time(hour=7, minute=0),
                    utils.Time(hour=12, minute=0),
                    utils.Time(hour=15, minute=0),
                    utils.Time(hour=18, minute=0),
                    utils.Time(hour=22, minute=0)]
     list_complex = [utils.Time(hour=0, minute=0),
                     utils.Time(hour=0, minute=0),
                     utils.Time(hour=1, minute=0),
                     utils.Time(hour=1, minute=0),
                     utils.Time(hour=1, minute=1),
                     utils.Time(hour=1, minute=2),
                     utils.Time(hour=1, minute=45),
                     utils.Time(hour=11, minute=32),
                     utils.Time(hour=18, minute=1),
                     utils.Time(hour=22, minute=59),
                     utils.Time(hour=23, minute=0),
                     utils.Time(hour=23, minute=59)]
     self.assertEqual(utils.get_times(raw_simple), list_simple)
     self.assertEqual(utils.get_times(raw_complex), list_complex)
Esempio n. 4
0
we_p = open(weekend_poi, 'w')
time_dict = {}
weekday_dict = {}
u_p = open(user_poi)
for line in u_p.readlines():
    if utils.key_in_dic(line.split()[1].split('T')[0][:7], time_dict):
        if utils.key_in_dic(line.split()[1].split('T')[0], weekday_dict):
            wd_p.write(line)
        else:
            we_p.write(line)
    else:
        time_dict[line.split()[1].split('T')[0][:7]] = ''
        my_date = line.split()[1].split('T')[0] + ' ' + line.split()[1].split(
            'T')[1].split('Z')[0]

        my_time = utils.Time(my_date)
        # obtain all weekdays
        weekday_dict = my_time.getDateByDateTime()
        # record the weekdays down
        if utils.key_in_dic(line.split()[1].split('T')[0], weekday_dict):
            wd_p.write(line)
        else:
            we_p.write(line)
u_p.close()
wd_p.close()
we_p.close()

poi_filter = '../data/poi_filter2.txt'
p_f = open(poi_filter, 'w')

wd_p = open(weekday_poi)