Skip to content

Commit

Permalink
Expand tables whenever writing xlsx
Browse files Browse the repository at this point in the history
  • Loading branch information
dalito committed Aug 26, 2023
1 parent 9e5cf77 commit cb4df2a
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
9 changes: 8 additions & 1 deletion src/voc4cat/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions src/voc4cat/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
10 changes: 9 additions & 1 deletion src/voc4cat/transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down Expand Up @@ -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:
Expand Down
10 changes: 8 additions & 2 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit cb4df2a

Please sign in to comment.