Exemple #1
0
    def test_execute_ok(self):
        # create test file
        os.makedirs(self._data_dir)
        excel_file = os.path.join(self._data_dir, "test.xlxs")
        workbook = xlsxwriter.Workbook(excel_file)
        workbook.close()

        # set the essential attributes
        instance = ExcelConvert()
        setattr(instance, "src_dir", self._data_dir)
        setattr(instance, "src_pattern", "test.xlxs")
        setattr(instance, "dest_dir", self._data_dir)
        setattr(instance, "dest_pattern", "test.csv")
        instance.execute()

        exists_csv = glob(os.path.join(self._data_dir, "test.csv"))
        shutil.rmtree(self._data_dir)
        assert "test.csv" in exists_csv[0]
Exemple #2
0
    def test_excute_ng_multiple_src(self):
        with pytest.raises(InvalidCount) as execinfo:
            # create test file
            os.makedirs(self._data_dir)
            excel_file = os.path.join(self._data_dir, "test1.xlxs")
            open(excel_file, "w").close()
            excel_file2 = os.path.join(self._data_dir, "test2.xlxs")
            open(excel_file2, "w").close()

            # set the essential attributes
            instance = ExcelConvert()
            setattr(instance, "src_dir", self._data_dir)
            setattr(instance, "src_pattern", "test(.*).xlxs")
            setattr(instance, "dest_dir", self._data_dir)
            setattr(instance, "dest_pattern", "test(.*).xlxs")
            instance.execute()
        shutil.rmtree(self._data_dir)
        assert "must be only one" in str(execinfo.value)
Exemple #3
0
    def test_execute_ng_invalid_extension(self):
        with pytest.raises(InvalidFormat) as execinfo:
            # create test file
            os.makedirs(self._data_dir)
            excel_file = os.path.join(self._data_dir, "test.xlxs")
            open(excel_file, "w").close()
            excel_file2 = os.path.join(self._data_dir, "test.xlxs.bk")
            open(excel_file2, "w").close()

            # set the essential attributes
            instance = ExcelConvert()
            setattr(instance, "src_dir", self._data_dir)
            setattr(instance, "src_pattern", "test.xlxs")
            setattr(instance, "dest_dir", self._data_dir)
            setattr(instance, "dest_pattern", "test.xlxs")
            instance.execute()

        shutil.rmtree(self._data_dir)
        assert "not supported" in str(execinfo.value)
Exemple #4
0
    def test_execute_ok(self):
        try:
            # create test file
            os.makedirs(self._data_dir, exist_ok=True)
            excel_file = os.path.join(self._data_dir, "test.xlxs")
            workbook = xlsxwriter.Workbook(excel_file)
            workbook.close()

            # set the essential attributes
            instance = ExcelConvert()
            Helper.set_property(instance, "logger", LisboaLog.get_logger(__name__))
            Helper.set_property(instance, "src_dir", self._data_dir)
            Helper.set_property(instance, "src_pattern", r"test\.xlxs")
            Helper.set_property(instance, "dest_dir", self._data_dir)
            Helper.set_property(instance, "dest_pattern", "test.csv")
            instance.execute()

            exists_csv = glob(os.path.join(self._data_dir, "test.csv"))
        finally:
            shutil.rmtree(self._data_dir)
        assert "test.csv" in exists_csv[0]
Exemple #5
0
    def test_excute_ng_multiple_src(self):
        with pytest.raises(InvalidCount) as execinfo:
            try:
                # create test file
                os.makedirs(self._data_dir, exist_ok=True)
                excel_file = os.path.join(self._data_dir, "test1.xlxs")
                open(excel_file, "w").close()
                excel_file2 = os.path.join(self._data_dir, "test2.xlxs")
                open(excel_file2, "w").close()

                # set the essential attributes
                instance = ExcelConvert()
                Helper.set_property(instance, "logger", LisboaLog.get_logger(__name__))
                Helper.set_property(instance, "src_dir", self._data_dir)
                Helper.set_property(instance, "src_pattern", r"test(.*)\.xlxs")
                Helper.set_property(instance, "dest_dir", self._data_dir)
                Helper.set_property(instance, "dest_pattern", r"test(.*).xlxs")
                instance.execute()
            finally:
                shutil.rmtree(self._data_dir)
        assert "must be only one" in str(execinfo.value)
Exemple #6
0
    def test_execute_ng_invalid_extension(self):
        with pytest.raises(InvalidFormat) as execinfo:
            try:
                # create test file
                os.makedirs(self._data_dir, exist_ok=True)
                excel_file = os.path.join(self._data_dir, "test.xlxs")
                open(excel_file, "w").close()
                excel_file2 = os.path.join(self._data_dir, "test.xlxs.bk")
                open(excel_file2, "w").close()

                # set the essential attributes
                instance = ExcelConvert()
                Helper.set_property(instance, "logger", LisboaLog.get_logger(__name__))
                Helper.set_property(instance, "src_dir", self._data_dir)
                Helper.set_property(instance, "src_pattern", "test.xlxs")
                Helper.set_property(instance, "dest_dir", self._data_dir)
                Helper.set_property(instance, "dest_pattern", "test.xlxs")
                instance.execute()
            finally:
                shutil.rmtree(self._data_dir)
        assert "not supported" in str(execinfo.value)