def test_parse_config(self):
     config_file = os.path.join(os.getcwd(), 'tests', 'config-test1.ini')
     cp = WeathervaneConfigParser()
     cp.read(config_file)
     observed = cp.parse_config()
     expected_keys = ['extended-error-mode', 'channel', 'frequency', 'library', 'interval', 'source',
                      'stations', 'bits', 'sleep-time', 'test', 'barometric_trend', 'display']
     self.assertEqual(set(observed.keys()), set(expected_keys))
     expected_bits = {str(x): x for x in range(self.NUMBER_OF_EXPECTED_BITS + 1)}
     self.assertEqual(set(expected_bits.keys()), set(observed['bits'].keys()))
Exemplo n.º 2
0
    def test_recursion(self):
        p_end1, p_end2 = Pipe()
        cp = WeathervaneConfigParser()
        config_file = os.path.join(os.getcwd(), "tests", "config-test1.ini")
        cp.read(config_file)
        c = cp.parse_config()
        p = Process(target=fetch_weather_data, args=[p_end1, "6308"], kwargs=c)
        p.start()
        while not p_end2.poll():
            time.sleep(0.1)

        result = p_end2.recv()
Exemplo n.º 3
0
def test_parse_config():
    config_file = os.path.join(os.getcwd(), 'tests', config_file_name)
    cp = WeathervaneConfigParser()
    cp.read(config_file)
    observed = cp.parse_config()
    expected_keys = [
        'extended-error-mode', 'channel', 'frequency', 'library', 'interval',
        'source', 'stations', 'bits', 'sleep-time', 'test', 'barometric_trend',
        'display'
    ]
    assert set(observed.keys()) == set(expected_keys)
    assert len(observed['bits']) == 16
Exemplo n.º 4
0
    def test_recursion(self):
        p_end1, p_end2 = Pipe()
        cp = WeathervaneConfigParser()
        config_file = os.path.join(os.getcwd(), 'tests', 'config-test1.ini')
        cp.read(config_file)
        c = cp.parse_config()
        p = Process(target=fetch_weather_data, args=[p_end1, '6308'], kwargs=c)
        p.start()
        while not p_end2.poll():
            time.sleep(0.1)

        p_end2.recv()
 def test_rain_config(self):
     'Tests if rain configuration is correctly picked up. E.g. bit_13=rain_mm_per_hour,10,0,99.9,0.1'
     config_file = os.path.join(os.getcwd(), 'tests', 'config-test1.ini')
     cp = WeathervaneConfigParser()
     cp.read(config_file)
     observed = cp.parse_config()
     rain_config = observed['bits']['13']
     assert rain_config == {
         'key': 'rain_mm_per_hour',
         'length': '10',
         'min': '0',
         'max': '99.9',
         'step': '0.1'
     }
Exemplo n.º 6
0
def test_rain_config():
    'Tests if rain configuration is correctly picked up. E.g. bit_13=rainFallLastHour,10,0,99.9,0.1'
    config_file = os.path.join(os.getcwd(), 'tests', config_file_name)
    cp = WeathervaneConfigParser()
    cp.read(config_file)
    observed = cp.parse_config()
    rain_config = observed['bits'][13]
    assert rain_config == {
        'key': 'rainFallLastHour',
        'length': '10',
        'min': '0',
        'max': '99.9',
        'step': '0.1'
    }
Exemplo n.º 7
0
def get_configuration(args):
    config_parser = WeathervaneConfigParser()
    config_file = args.config
    config_parser.read(config_file)
    config = config_parser.parse_config()
    return config
 def test_parse_station_numbers(self):
     config_file = os.path.join(os.getcwd(), 'tests', 'config-test1.ini')
     cp = WeathervaneConfigParser()
     cp.read(config_file)
     stations = cp.parse_station_numbers()
     assert stations == [6320, 6308]
Exemplo n.º 9
0
def test_parse_station_numbers():
    config_file = os.path.join(os.getcwd(), 'tests', config_file_name)
    cp = WeathervaneConfigParser()
    cp.read(config_file)
    stations = cp.parse_station_numbers()
    assert stations == [6320, 6308]
Exemplo n.º 10
0
            new_value = new_weatherdata[key]
            if key not in ['error', 'wind_direction', 'wind_direction', 'rain', 'float(weather_data.string)barometric_trend'] and not self.reached:
                try:
                    interpolated_value = float(old_value) + (self.counter * (float(new_value) - float(old_value)) / interval)
                    interpolated_wd[key] = interpolated_value
                except ValueError:
                    interpolated_wd[key] = new_value
                except TypeError:
                    interpolated_wd[key] = new_value
            else:
                interpolated_wd[key] = new_value

        return interpolated_wd


if __name__ == "__main__":
    parser = argparse.ArgumentParser(description="Get weather data from a provider and send it through SPI")
    parser.add_argument('-c', '--config', action='store', default='config.ini',
                        help="get the configuration from a specific configuration file")
    supplied_args = parser.parse_args()

    config_parser = WeathervaneConfigParser()
    config_file_location = os.path.join(os.getcwd(), supplied_args.config)
    config_parser.read(config_file_location)
    config = config_parser.parse_config()

    wv = WeatherVane(**config)
    wv.set_logger()
    logging.info(supplied_args)
    wv.main()
Exemplo n.º 11
0
def get_configuration(args):
    config_parser = WeathervaneConfigParser()
    config_file = args.config
    config_parser.read(config_file)
    config = config_parser.parse_config()
    return config