Exemplo n.º 1
0
class ExtendedConfigParserTests(unittest.TestCase):
    """
    :type config: toolium.config_parser.ExtendedConfigParser or configparser.ConfigParser
    """

    def setUp(self):
        root_path = os.path.dirname(os.path.realpath(__file__))
        conf_properties_file = os.path.join(root_path, 'conf', 'properties.cfg')
        self.config = ExtendedConfigParser()
        self.config.read(conf_properties_file)

    @data(*optional_values)
    @unpack
    def test_get_optional(self, section, option, default, response):
        if default:
            assert_equal(response, self.config.get_optional(section, option, default))
        else:
            assert_equal(response, self.config.get_optional(section, option))

    @data(*optional_boolean_values)
    @unpack
    def test_getboolean_optional(self, section, option, default, response):
        if default:
            assert_equal(response, self.config.getboolean_optional(section, option, default))
        else:
            assert_equal(response, self.config.getboolean_optional(section, option))

    def test_deepcopy(self):
        section = 'AppiumCapabilities'
        option = 'automationName'
        orig_value = 'Appium'
        new_value = 'Selendroid'

        # Check previous value
        assert_equal(orig_value, self.config.get(section, option))

        # Copy config object and modify a property
        new_config = self.config.deepcopy()
        new_config.set(section, option, new_value)

        # Check that the value has no changed in original config
        assert_equal(orig_value, self.config.get(section, option))
        assert_equal(new_value, new_config.get(section, option))

    def test_update_from_system_properties(self):
        section = 'AppiumCapabilities'
        option = 'platformName'
        orig_value = 'Android'
        new_value = 'iOS'

        # Check previous value
        assert_equal(orig_value, self.config.get(section, option))

        # Change system property and update config
        os.environ[section + '_' + option] = new_value
        self.config.update_from_system_properties()

        # Check the new config value
        assert_equal(new_value, self.config.get(section, option))
Exemplo n.º 2
0
def config():
    root_path = os.path.dirname(os.path.realpath(__file__))
    conf_properties_file = os.path.join(root_path, 'conf', 'properties.cfg')
    config = ExtendedConfigParser()
    config.read(conf_properties_file)

    yield config

    # Remove used environment properties after test
    global environment_properties
    for env_property in environment_properties:
        try:
            del os.environ[env_property]
        except KeyError:
            pass
    environment_properties = []
Exemplo n.º 3
0
def config():
    root_path = os.path.dirname(os.path.realpath(__file__))
    conf_properties_file = os.path.join(root_path, 'conf', 'properties.cfg')
    config = ExtendedConfigParser()
    config.read(conf_properties_file)
    return config
Exemplo n.º 4
0
def config():
    root_path = os.path.dirname(os.path.realpath(__file__))
    conf_properties_file = os.path.join(root_path, 'conf', 'properties.cfg')
    config = ExtendedConfigParser()
    config.read(conf_properties_file)
    return config
Exemplo n.º 5
0
class ExtendedConfigParserTests(unittest.TestCase):
    """
    :type config: toolium.config_parser.ExtendedConfigParser or configparser.ConfigParser
    """
    def setUp(self):
        root_path = os.path.dirname(os.path.realpath(__file__))
        conf_properties_file = os.path.join(root_path, 'conf',
                                            'properties.cfg')
        self.config = ExtendedConfigParser()
        self.config.read(conf_properties_file)

    @data(*optional_values)
    @unpack
    def test_get_optional(self, section, option, default, response):
        if default:
            assert_equal(response,
                         self.config.get_optional(section, option, default))
        else:
            assert_equal(response, self.config.get_optional(section, option))

    @data(*optional_boolean_values)
    @unpack
    def test_getboolean_optional(self, section, option, default, response):
        if default:
            assert_equal(
                response,
                self.config.getboolean_optional(section, option, default))
        else:
            assert_equal(response,
                         self.config.getboolean_optional(section, option))

    def test_deepcopy(self):
        section = 'AppiumCapabilities'
        option = 'automationName'
        orig_value = 'Appium'
        new_value = 'Selendroid'

        # Check previous value
        assert_equal(orig_value, self.config.get(section, option))

        # Copy config object and modify a property
        new_config = self.config.deepcopy()
        new_config.set(section, option, new_value)

        # Check that the value has no changed in original config
        assert_equal(orig_value, self.config.get(section, option))
        assert_equal(new_value, new_config.get(section, option))

    def test_update_from_system_properties(self):
        section = 'AppiumCapabilities'
        option = 'platformName'
        orig_value = 'Android'
        new_value = 'iOS'

        # Check previous value
        assert_equal(orig_value, self.config.get(section, option))

        # Change system property and update config
        os.environ[section + '_' + option] = new_value
        self.config.update_from_system_properties()

        # Check the new config value
        assert_equal(new_value, self.config.get(section, option))