Exemple #1
0
def test_set_config():
    config.reset_config()
    previous_stats = config.get_config()['stats'].copy()

    config.set_config({'stats': previous_stats + ['test']})
    assert len(config.get_config()['stats']) == len(previous_stats) + 1
    config.reset_config()
Exemple #2
0
def prompt_password():
    """Prompt the user to set a password."""
    passwords_match = False
    while not passwords_match:
        password = encrypt_password(getpass.getpass('Enter Password: '******'Verify Password: '******'Passwords do not match.')

    config.set_config({
        'password': password
    })
Exemple #3
0
 def remove_stat(self, stat, remove_from_config=True):
     """
     Removes `stat` from the displayed stats and if `remove_from_config`
     is true from the user configuration.
     """
     if remove_from_config:
         stats = config.get_config()['stats'].copy()
         tags = [x['tag'] for x in config.parse_stats(stats)]
         try:
             index = tags.index(stat.tag)
             del stats[index]
         except ValueError:
             logging.error((f'Removing stat {stat.tag} failed. '
                            'Stat might already have been removed.'))
         config.set_config({'stats': stats})
     logging.info(f'Removed stat {stat.tag}')
Exemple #4
0
    def add_stat(self, stat, add_to_config=True):
        """
        Adds `stat` to the displayed stats and if `add_to_config`
        is true to the user configuration.
        """
        if add_to_config:
            stats = config.get_config()['stats'].copy()
            tags = [x['tag'] for x in config.parse_stats(stats)]

            if stat.tag not in tags:
                if stat.settings == stat.default_settings:
                    stats.append(stat.tag)
                else:
                    stats.append({'tag': stat.tag, 'settings': stat.settings})
            config.set_config({'stats': stats})
        logging.info(f'Added stat {stat.tag}')
Exemple #5
0
def test_set_invalid_config():
    with pytest.raises(AssertionError):
        config.set_config({secrets.token_hex(10): 1})