<commit_before>import os

from collections import UserDict

import yaml


class Config(UserDict):

    def __init__(self,
                 initialdata={},
                 path=os.path.join(os.environ['HOME'], '.photoshell.yaml')):
        super(Config, self).__init__(initialdata)

        self.path = path
        self.load()

    def load(self):
        if os.path.isfile(self.path):
            with open(self.path, 'r') as config_file:
                self.update(yaml.load(config_file))

    def flush(self):
        with open(self.path, 'w+') as config_file:
            yaml.dump(self.data, config_file, default_flow_style=False)

    def exists(self):
        os.path.exists(self.path)<commit_msg>Add tests for config (and fix bugs; yay tests)<commit_after>import os

from collections import UserDict

import yaml


class Config(UserDict):

    def __init__(self,
                 initialdata={},
                 path=os.path.join(os.environ['HOME'], '.photoshell.yaml')):
        super(Config, self).__init__(initialdata)

        self.path = path
        self.load()

    def load(self):
        if os.path.isfile(self.path):
            with open(self.path, 'r') as config_file:
                try:
                    self.update(yaml.load(config_file))
                except:
                    pass

    def flush(self):
        with open(self.path, 'w+') as config_file:
            yaml.dump(self.data, config_file, default_flow_style=False)

    def exists(self):
        return os.path.exists(self.path)
{'fraction_non_alphanumeric': 0.11861074705111402, 'fraction_numerical': 0.0, 'mean_word_length': 2.1226993865030677, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6096234', 'n_tokens_mistral': 470, 'n_tokens_neox': 446, 'n_words': 97}