From cb4df2a1d14d52fba882b14f9af62ec86ebfac74 Mon Sep 17 00:00:00 2001 From: David Linke Date: Sat, 26 Aug 2023 15:27:04 +0200 Subject: [PATCH] Expand tables whenever writing xlsx --- src/voc4cat/check.py | 9 ++++++++- src/voc4cat/convert.py | 3 +++ src/voc4cat/transform.py | 10 +++++++++- tests/test_cli.py | 10 ++++++++-- 4 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/voc4cat/check.py b/src/voc4cat/check.py index aa86e7d..2a168e4 100644 --- a/src/voc4cat/check.py +++ b/src/voc4cat/check.py @@ -14,7 +14,12 @@ ) from voc4cat.convert import validate_with_profile from voc4cat.transform import join_split_turtle -from voc4cat.utils import EXCEL_FILE_ENDINGS, RDF_FILE_ENDINGS, is_supported_template +from voc4cat.utils import ( + EXCEL_FILE_ENDINGS, + RDF_FILE_ENDINGS, + adjust_length_of_tables, + is_supported_template, +) logger = logging.getLogger(__name__) @@ -82,6 +87,8 @@ def check_xlsx(fpath: Path, outfile: Path) -> int: if failed_checks: wb.save(outfile) logger.info("-> Saved file with highlighted errors as %s", outfile) + # Extend size (length) of tables in all sheets + adjust_length_of_tables(outfile) return logger.info("-> xlsx check passed for file: %s", fpath) diff --git a/src/voc4cat/convert.py b/src/voc4cat/convert.py index d79fbec..5bf96c8 100644 --- a/src/voc4cat/convert.py +++ b/src/voc4cat/convert.py @@ -24,6 +24,7 @@ EXCEL_FILE_ENDINGS, RDF_FILE_ENDINGS, ConversionError, + adjust_length_of_tables, has_file_in_multiple_formats, is_supported_template, load_template, @@ -440,3 +441,5 @@ def convert(args): output_file_path = outfile.with_suffix(".xlsx") rdf_to_excel(file, output_file_path, template_file_path=args.template) logger.info("-> successfully converted to %s", output_file_path) + # Extend size (length) of tables in all sheets + adjust_length_of_tables(output_file_path) diff --git a/src/voc4cat/transform.py b/src/voc4cat/transform.py index ec131c6..f321f1b 100644 --- a/src/voc4cat/transform.py +++ b/src/voc4cat/transform.py @@ -20,7 +20,12 @@ dag_to_node_levels, get_concept_and_level_from_indented_line, ) -from voc4cat.utils import EXCEL_FILE_ENDINGS, RDF_FILE_ENDINGS, is_supported_template +from voc4cat.utils import ( + EXCEL_FILE_ENDINGS, + RDF_FILE_ENDINGS, + adjust_length_of_tables, + is_supported_template, +) logger = logging.getLogger(__name__) @@ -430,6 +435,9 @@ def _transform_xlsx(file, args): else: logger.debug("-> nothing to do for xlsx files!") + # Extend size (length) of tables in all sheets + adjust_length_of_tables(outfile) + def _transform_rdf(file, args): if args.split: diff --git a/tests/test_cli.py b/tests/test_cli.py index fcc6dbe..d3efabe 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -86,12 +86,18 @@ def test_nonexisting_config(monkeypatch, datadir, caplog): @mock.patch.dict(os.environ, {"LOGLEVEL": "DEBUG"}) -def test_valid_config(monkeypatch, datadir, caplog, temp_config): +def test_valid_config(monkeypatch, datadir, caplog, tmp_path, temp_config): # Don't remove "temp_config". The fixture avoid global config change. + shutil.copy(datadir / CS_SIMPLE, tmp_path / CS_SIMPLE) monkeypatch.chdir(datadir) with caplog.at_level(logging.DEBUG): main_cli( - ["transform", "--config", str(datadir / "valid_idranges.toml"), CS_SIMPLE] + [ + "transform", + "--config", + str(datadir / "valid_idranges.toml"), + str(tmp_path / CS_SIMPLE), + ] ) assert "Config loaded from" in caplog.text