示例#1
0
    def test_get_dtypes_given_header(self):
        """
        test if dtypes with custom header can be returned
        """
        spec = {'name': "nohead", 'type': "csv"}
        cols = [
            "Lat",
            "Lon",
            "Txt",
            "Nam",
            "Add",
            "Job",
        ]
        g = FileInspectorCsvTest._gen_file(name=spec['name'],
                                           header=False,
                                           type=spec['type'])
        g.create()

        c = FileInspector(cfg_path=get_inipath(),
                          file=os.path.join(FILEPATH, (f"{spec['name']}."
                                                       f"{spec['type']}")),
                          seperator="|",
                          type="csv",
                          columns=cols,
                          header=None)

        dtype_key_list = c.get_dtypes().keys()

        g.rm()
        self.assertEqual(sorted(cols), sorted(dtype_key_list))
示例#2
0
    def test_get_dtypes_no_header(self):
        """
        test if dtypes without header can be returned
        """
        spec = {'name': "nohead", 'type': "csv"}
        g = FileInspectorCsvTest._gen_file(name=spec['name'],
                                           header=False,
                                           type=spec['type'])
        g.create()

        c = FileInspector(cfg_path=get_inipath(),
                          file=os.path.join(FILEPATH, (f"{spec['name']}."
                                                       f"{spec['type']}")),
                          seperator="|",
                          type="csv",
                          header=None)

        with self.assertRaises(NoColumnsError):
            c.get_dtypes().keys()
        g.rm()
示例#3
0
    def test_get_dtypes(self):
        """
        test if columns
        """
        c = FileInspector(
            cfg_path=get_inipath(),
            file=os.path.join(FILEPATH,
                              (f"{FileInspectorJsonTest.testfile['name']}."
                               f"{FileInspectorJsonTest.testfile['type']}")),
            type="json",
            orient="split")

        dtype_key_list = c.get_dtypes().keys()

        exp_col = ["Lat", "Lon", "Txt", "Nam", "Add", "Job", "CreatedAt"]

        self.assertEqual(sorted(exp_col), sorted(dtype_key_list))
示例#4
0
    def test_change_dt_to_string(self):
        """
        test if all columns can be changed to string datatype
        """
        c = FileInspector(
            cfg_path=get_inipath(),
            file=os.path.join(FILEPATH,
                              (f"{FileInspectorCsvTest.testfile['name']}."
                               f"{FileInspectorCsvTest.testfile['type']}")),
            seperator="|",
            type="csv")
        c.col_to_str()

        dtype_key_list = c.get_dtypes().values()

        check = all(x.name == "object" for x in dtype_key_list)

        self.assertEqual(check, True)
示例#5
0
    def test_get_dtypes(self):
        """
        test if data types gets returned as a dict
        """
        c = FileInspector(
            cfg_path=get_inipath(),
            file=os.path.join(FILEPATH,
                              (f"{FileInspectorCsvTest.testfile['name']}."
                               f"{FileInspectorCsvTest.testfile['type']}")),
            seperator="|",
            type="csv")
        dtype_key_list = c.get_dtypes().keys()

        exp_col = [
            "Lat",
            "Lon",
            "Txt",
            "Nam",
            "Add",
            "Job",
        ]

        self.assertEqual(sorted(exp_col), sorted(dtype_key_list))