コード例 #1
0
ファイル: setup.py プロジェクト: helium876/mdl
    def __init__(self):
        """Function for intializing the class.

        Args:
            None

        Returns:
            None

        """
        # Read configuration into dictionary
        self.directories = general.config_directories()
        self.config = general.read_yaml_files(self.directories)
コード例 #2
0
ファイル: configuration.py プロジェクト: helium876/mdl
    def __init__(self):
        """Function for intializing the class.

        Args:
            None

        Returns:
            None

        """
        # Initialize key variables
        directories = general.config_directories()
        self.config_dict = general.read_yaml_files(directories)
コード例 #3
0
ファイル: test_general.py プロジェクト: helium876/mdl
    def test_read_yaml_files(self):
        """Test function read_yaml_files."""
        # Initialize key variables
        dict_1 = {
            'key1': 1,
            'key2': 2,
            'key3': 3,
            'key4': 4,
        }

        dict_2 = {
            'key6': 6,
            'key7': 7,
        }
        dict_3 = {}

        # Populate a third dictionary with contents of other dictionaries.
        for key in dict_1.keys():
            dict_3[key] = dict_1[key]

        for key in dict_2.keys():
            dict_3[key] = dict_2[key]

        # Create temp file with known data
        directory = tempfile.mkdtemp()
        filenames = {
            ('%s/file_1.yaml') % (directory): dict_1,
            ('%s/file_2.yaml') % (directory): dict_2
        }
        for filename, data_dict in filenames.items():
            with open(filename, 'w') as filehandle:
                yaml.dump(data_dict, filehandle, default_flow_style=False)

        # Get Results
        result = general.read_yaml_files([directory])

        # Clean up
        for key in result.keys():
            self.assertEqual(dict_3[key], result[key])
        filelist = [
            next_file for next_file in os.listdir(directory)
            if next_file.endswith('.yaml')
        ]
        for delete_file in filelist:
            delete_path = ('%s/%s') % (directory, delete_file)
            os.remove(delete_path)
        os.removedirs(directory)