Beispiel #1
0
    def export(data, f_type, filename):
        """
        Write data dictionary to JSON or CSV.

        Calls public methods found in external modules:

            Export.write_json()
            Export.write_csv()

        Parameters
        ----------
        data: dict
            Dictionary containing frequency data
        f_type: str
            String denoting the file format
        filename: str
            String denoting the filename

        Returns
        -------
        None
        """

        Export.write_json(data, filename) \
            if f_type == "json" \
            else Export.write_csv(data, filename)
Beispiel #2
0
    def test_write_json(self):
        filename = os.path.join(sys.path[0], "test_json_writing.json")
        overview = {
            "test_1": {
                "this": 1, 
                "is": 1, 
                "a": 1, 
                "test": 1
            },
            "test_2": {
                "this": 2, 
                "is": 2, 
                "a": 2, 
                "test": 2
            }
        }

        Export.write_json(overview, filename)

        with open(filename, "r", encoding = "utf-8") as test_json:
            test_dict = json.load(test_json)
            assert test_dict == overview
        
        os.remove(filename)