Beispiel #1
0
    def test_specific_default(self):
        """
        Checks the default values of the specific options in the parser.
        """
        _args = configuration_parser()

        self.assertEqual(self._default_interval, _args.htu_interval)
        self.assertEqual(self._default_interval, _args.hkp_interval)
        self.assertEqual(self._default_i2c_bus, _args.i2c_bus)
Beispiel #2
0
    def test_specific_arguments(self):
        """
        Checks the presence of the specific options in the parser.
        """
        _args = configuration_parser()

        self.assertIn('htu_interval', _args)
        self.assertIn('hkp_interval', _args)
        self.assertIn('i2c_bus', _args)
Beispiel #3
0
    def test_specific_options(self):
        """
        Tests the parsing of the options in the specific section.
        """
        _cmd_line = ['-c', self._config_file]
        _args = configuration_parser(_cmd_line)

        self.assertEqual(self._test_interval, _args.htu_interval)
        self.assertEqual(self._test_interval, _args.hkp_interval)
        self.assertEqual(self._test_i2c_bus, _args.i2c_bus)
Beispiel #4
0
    def test_general_default(self):
        """
        Checks the defaults of the GENERAL section in the parser.
        """
        _cmd_line = []
        _args = configuration_parser(_cmd_line)

        self.assertEqual(self._default.mqtt_local_host, _args.mqtt_local_host)
        self.assertEqual(self._default.mqtt_local_port, _args.mqtt_local_port)
        self.assertEqual(self._default.logging_level, _args.logging_level)
        self.assertEqual(self._default.influxdb_host, _args.influxdb_host)
        self.assertEqual(self._default.influxdb_port, _args.influxdb_port)
        self.assertEqual(self._default.gps_location, _args.gps_location)
Beispiel #5
0
    def test_general_arguments(self):
        """
        Checks the presence of the GENERAL section in the parser.
        """
        _cmd_line = []
        _args = configuration_parser(_cmd_line)

        self.assertIn('mqtt_local_host', _args)
        self.assertIn('mqtt_local_port', _args)
        self.assertIn('logging_level', _args)
        self.assertIn('influxdb_host', _args)
        self.assertIn('influxdb_port', _args)
        self.assertIn('gps_location', _args)
Beispiel #6
0
    def test_command_line_long_override(self):
        """"
        Tests if the command line options override the settings in the
        configuration file (long options).
        """
        _cmd_line = []

        _cmd_line.extend(['--config-file', str(self._config_file)])
        _cmd_line.extend(
            ['--mqtt-host',
             str(self._test_options.mqtt_local_host)])
        _cmd_line.extend(
            ['--mqtt-port',
             str(self._test_options.mqtt_local_port)])
        _cmd_line.extend(
            ['--influxdb-host',
             str(self._test_options.influxdb_host)])
        _cmd_line.extend(
            ['--influxdb-port',
             str(self._test_options.influxdb_port)])
        _cmd_line.extend(
            ['--logging-level',
             str(self._test_options.logging_level)])
        _cmd_line.extend(
            ['--gps-location',
             str(self._test_options.gps_location)])
        _cmd_line.extend(
            ['--htu-interval',
             str(self._test_options.htu_interval)])
        _cmd_line.extend(
            ['--hkp-interval',
             str(self._test_options.hkp_interval)])
        _cmd_line.extend(['--i2c-bus', str(self._test_options.i2c_bus)])

        _args = configuration_parser(_cmd_line)

        self.assertEqual(self._test_options.mqtt_local_host,
                         _args.mqtt_local_host)
        self.assertEqual(self._test_options.mqtt_local_port,
                         _args.mqtt_local_port)
        self.assertEqual(self._test_options.logging_level, _args.logging_level)
        self.assertEqual(self._test_options.influxdb_host, _args.influxdb_host)
        self.assertEqual(self._test_options.influxdb_port, _args.influxdb_port)
        self.assertEqual(self._test_options.gps_location, _args.gps_location)
        self.assertEqual(self._test_options.htu_interval, _args.htu_interval)
        self.assertEqual(self._test_options.hkp_interval, _args.hkp_interval)
        self.assertEqual(self._test_options.i2c_bus, _args.i2c_bus)
Beispiel #7
0
    def test_command_line_long_partial_override(self):
        """"
        Tests if the command line options override the settings in the
        configuration file (long options).
        """
        for _opt, _par in COMMANDLINE_PARAMETERS.items():
            _cmd_line = ['--config-file', str(self._config_file)]
            _cmd_line.extend(
                [_par['cmdline'],
                 str(getattr(self._test_options, _opt))])

            _args = configuration_parser(_cmd_line)

            self.assertEqual(getattr(_args, _opt),
                             getattr(self._test_options, _opt))

            for _cfg, _val in COMMANDLINE_PARAMETERS.items():
                if _cfg == _opt:
                    continue
                self.assertEqual(getattr(_args, _cfg),
                                 getattr(self._test_configuration, _cfg))
Beispiel #8
0
    def test_general_options(self):
        """
        Tests the parsing of the options in the GENERAL section.
        """
        _cmd_line = ['-c', self._config_file]
        _args = configuration_parser(_cmd_line)

        self.assertEqual(self._test.mqtt_local_host, _args.mqtt_local_host)
        self.assertEqual(self._test.mqtt_local_port, _args.mqtt_local_port)
        self.assertEqual(self._test.logging_level, _args.logging_level)
        self.assertEqual(self._test.influxdb_host, _args.influxdb_host)
        self.assertEqual(self._test.influxdb_port, _args.influxdb_port)
        self.assertEqual(self._test.gps_location, _args.gps_location)

        self.assertNotEqual(_args.mqtt_local_host,
                            self._default.mqtt_local_host)
        self.assertNotEqual(_args.mqtt_local_port,
                            self._default.mqtt_local_port)
        self.assertNotEqual(_args.logging_level, self._default.logging_level)
        self.assertNotEqual(_args.influxdb_host, self._default.influxdb_host)
        self.assertNotEqual(_args.influxdb_port, self._default.influxdb_port)
        self.assertNotEqual(_args.gps_location, self._default.gps_location)
Beispiel #9
0
    def test_general_override_options(self):
        """
        Tests if the options in the GENERAL section are overridden by the same
        options in the specific section.
        """
        _config_specific_override_file = '/tmp/override_config.ini'

        _f = open(_config_specific_override_file, "w")
        _f.write("[GENERAL]\n")
        _f.write("mqtt_local_host = {}\n".format(self._test.mqtt_local_host))
        _f.write("mqtt_local_port = {}\n".format(self._test.mqtt_local_port))
        _f.write("influxdb_host = {}\n".format(self._test.influxdb_host))
        _f.write("influxdb_port = {}\n".format(self._test.influxdb_port))
        _f.write("logging_level = {}\n".format(self._test.logging_level))
        _f.write("gps_location  = {}\n".format(self._test.gps_location))
        _f.write("[{:s}]\n".format(APPLICATION_NAME))
        _f.write("mqtt_local_host = {}\n".format(
            self._override.mqtt_local_host))
        _f.write("mqtt_local_port = {}\n".format(
            self._override.mqtt_local_port))
        _f.write("influxdb_host = {}\n".format(self._override.influxdb_host))
        _f.write("influxdb_port = {}\n".format(self._override.influxdb_port))
        _f.write("logging_level = {}\n".format(self._override.logging_level))
        _f.write("gps_location  = {}\n".format(self._override.gps_location))
        _f.close()

        _cmd_line = ['-c', _config_specific_override_file]
        _args = configuration_parser(_cmd_line)

        self.assertEqual(self._override.mqtt_local_host, _args.mqtt_local_host)
        self.assertEqual(self._override.mqtt_local_port, _args.mqtt_local_port)
        self.assertEqual(self._override.logging_level, _args.logging_level)
        self.assertEqual(self._override.influxdb_host, _args.influxdb_host)
        self.assertEqual(self._override.influxdb_port, _args.influxdb_port)
        self.assertEqual(self._override.gps_location, _args.gps_location)

        os.remove(_config_specific_override_file)