Skip to content

Commit

Permalink
fix: Use .tex file attr for BytesIO added to tar.
Browse files Browse the repository at this point in the history
This must be ensured even when the input filename is, e.g., 'main.fls'.

Add test for the case when fls file present in source dir.
  • Loading branch information
badshah400 committed Feb 17, 2024
1 parent 2bc7479 commit 5785f36
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/tartex/tartex.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,9 +385,14 @@ def _do_tar(self, tar_obj):
tinfo = tar_obj.tarinfo(fpath.name)
tinfo.size = len(byt)
tinfo.mtime = int(time.time())

# Copy user/group names from main.tex file
tinfo.uname = tar_obj.getmember(self.main_file.name).uname
tinfo.gname = tar_obj.getmember(self.main_file.name).gname
tinfo.uname = tar_obj.getmember(
self.main_file.with_suffix(".tex").name
).uname
tinfo.gname = tar_obj.getmember(
self.main_file.with_suffix(".tex").name
).gname

tar_obj.addfile(tinfo, BytesIO(byt))

Expand Down
24 changes: 24 additions & 0 deletions tests/test_fls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# vim:set et sw=4 ts=4:

"""
Tests for when source dir has .fls file
"""

import pytest

from tartex.tartex import TarTeX


def test_fls_main_arg(datadir, capsys):
"""User passes a .fls filename as input"""
fls_name = "main.fls"
t = TarTeX(
[str(datadir / fls_name), "-o", str(datadir), "-x", "*.bbl", "-bs"],
)
assert t.tar_file.name == fls_name.replace(".fls", ".tar")
# Note that this will throw because the .bbl file marked as INPUT in
# pre-generated .fls file does not exist in source dir
with pytest.raises(FileNotFoundError) as exc:
t.tar_files()

assert exc.match("No such file or directory:")
72 changes: 72 additions & 0 deletions tests/test_fls/main.fls
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
PWD /home/badshah/Utilities/tartex/tests/test_fls
INPUT /etc/texmf/web2c/texmf.cnf
INPUT /usr/share/texmf/web2c/texmf.cnf
INPUT /var/lib/texmf/web2c/pdftex/pdflatex.fmt
INPUT main.tex
OUTPUT main.log
INPUT /usr/share/texmf/tex/latex/base/article.cls
INPUT /usr/share/texmf/tex/latex/base/article.cls
INPUT /usr/share/texmf/tex/latex/base/article.cls
INPUT /usr/share/texmf/tex/latex/base/article.cls
INPUT /usr/share/texmf/tex/latex/base/article.cls
INPUT /usr/share/texmf/tex/latex/base/article.cls
INPUT /usr/share/texmf/tex/latex/base/article.cls
INPUT /usr/share/texmf/tex/latex/base/article.cls
INPUT /usr/share/texmf/tex/latex/base/article.cls
INPUT /usr/share/texmf/tex/latex/base/article.cls
INPUT /usr/share/texmf/tex/latex/base/article.cls
INPUT /usr/share/texmf/tex/latex/base/size11.clo
INPUT /usr/share/texmf/tex/latex/base/size11.clo
INPUT /usr/share/texmf/tex/latex/base/size11.clo
INPUT /usr/share/texmf/tex/latex/base/size11.clo
INPUT /usr/share/texmf/fonts/map/fontname/texfonts.map
INPUT /usr/share/texmf/fonts/tfm/public/cm/cmr10.tfm
INPUT /usr/share/texmf/tex/latex/l3backend/l3backend-pdftex.def
INPUT /usr/share/texmf/tex/latex/l3backend/l3backend-pdftex.def
INPUT /usr/share/texmf/tex/latex/l3backend/l3backend-pdftex.def
INPUT /usr/share/texmf/tex/latex/l3backend/l3backend-pdftex.def
INPUT /usr/share/texmf/tex/latex/l3backend/l3backend-pdftex.def
INPUT /usr/share/texmf/tex/latex/l3backend/l3backend-pdftex.def
INPUT /usr/share/texmf/tex/latex/l3backend/l3backend-pdftex.def
INPUT /usr/share/texmf/tex/latex/l3backend/l3backend-pdftex.def
INPUT /usr/share/texmf/tex/latex/l3backend/l3backend-pdftex.def
INPUT /usr/share/texmf/tex/latex/l3backend/l3backend-pdftex.def
INPUT /usr/share/texmf/tex/latex/l3backend/l3backend-pdftex.def
INPUT ./main.aux
INPUT main.aux
INPUT main.aux
OUTPUT main.aux
INPUT /usr/share/texmf/fonts/tfm/public/cm/cmr17.tfm
INPUT /usr/share/texmf/fonts/tfm/public/cm/cmr12.tfm
INPUT /usr/share/texmf/fonts/tfm/public/cm/cmr8.tfm
INPUT /usr/share/texmf/fonts/tfm/public/cm/cmr6.tfm
INPUT /usr/share/texmf/fonts/tfm/public/cm/cmmi12.tfm
INPUT /usr/share/texmf/fonts/tfm/public/cm/cmmi8.tfm
INPUT /usr/share/texmf/fonts/tfm/public/cm/cmmi6.tfm
INPUT /usr/share/texmf/fonts/tfm/public/cm/cmsy10.tfm
INPUT /usr/share/texmf/fonts/tfm/public/cm/cmsy8.tfm
INPUT /usr/share/texmf/fonts/tfm/public/cm/cmsy6.tfm
INPUT /usr/share/texmf/fonts/tfm/public/cm/cmr12.tfm
INPUT /usr/share/texmf/fonts/tfm/public/cm/cmbx12.tfm
INPUT ./main.toc
INPUT main.toc
INPUT main.toc
INPUT /usr/share/texmf/fonts/tfm/public/cm/cmbx10.tfm
INPUT /usr/share/texmf/fonts/tfm/public/cm/cmmi10.tfm
INPUT /usr/share/texmf/fonts/tfm/public/cm/cmsy10.tfm
OUTPUT main.toc
INPUT /usr/share/texmf/fonts/tfm/public/cm/cmbx12.tfm
INPUT ./main.bbl
INPUT main.bbl
INPUT ./main.bbl
INPUT main.bbl
INPUT /usr/share/texmf/fonts/tfm/public/cm/cmti10.tfm
OUTPUT main.pdf
INPUT /var/lib/texmf/fonts/map/pdftex/updmap/pdftex.map
INPUT main.aux
INPUT /usr/share/texmf/fonts/type1/public/amsfonts/cm/cmbx10.pfb
INPUT /usr/share/texmf/fonts/type1/public/amsfonts/cm/cmbx12.pfb
INPUT /usr/share/texmf/fonts/type1/public/amsfonts/cm/cmr10.pfb
INPUT /usr/share/texmf/fonts/type1/public/amsfonts/cm/cmr12.pfb
INPUT /usr/share/texmf/fonts/type1/public/amsfonts/cm/cmr17.pfb
INPUT /usr/share/texmf/fonts/type1/public/amsfonts/cm/cmti10.pfb
19 changes: 19 additions & 0 deletions tests/test_fls/main.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
\documentclass[11pt,a4paper]{article}

\author{No Author}
\title{Test bib}
\date{\today}
\begin{document}
\maketitle
\tableofcontents

\section{Only Section}

This is a test document with a single citation \cite{testarticle}.

\subsection{Empty subsection}

\bibliographystyle{plain}
\bibliography{refs}

\end{document}
8 changes: 8 additions & 0 deletions tests/test_fls/refs.bib
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
@ARTICLE{testarticle,
author = {No Name},
title = {No Title},
journal = {No Journal},
year = {2024},
otherinfo = {Purely for testing}
}

0 comments on commit 5785f36

Please sign in to comment.