Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
F
fact_pdf_report
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
fact-depend
fact_pdf_report
Commits
5d77c76b
Commit
5d77c76b
authored
Jul 27, 2020
by
Jörg Stucke
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
review changes + refactoring
parent
9ac7f0ee
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
33 additions
and
21 deletions
+33
-21
docker_entry.py
docker_entry.py
+2
-1
generator.py
pdf_generator/generator.py
+8
-3
test_docker_entry.py
test/test_docker_entry.py
+17
-12
test_generator.py
test/unit/test_generator.py
+6
-5
No files found.
docker_entry.py
View file @
5d77c76b
...
...
@@ -20,8 +20,9 @@
import
json
import
shutil
from
pathlib
import
Path
from
tempfile
import
TemporaryDirectory
from
sys
import
exit
as
sys_exit
from
tempfile
import
TemporaryDirectory
from
pdf_generator.generator
import
compile_pdf
,
create_templates
...
...
pdf_generator/generator.py
View file @
5d77c76b
import
os
import
shutil
import
sys
from
pathlib
import
Path
from
common_helper_process
import
execute_shell_command
from
common_helper_process
import
execute_shell_command_get_return_code
from
pdf_generator.tex_generation.template_engine
import
(
LOGO_FILE
,
MAIN_TEMPLATE
,
META_TEMPLATE
,
CUSTOM_TEMPLATE_CLASS
,
TemplateEngine
CUSTOM_TEMPLATE_CLASS
,
LOGO_FILE
,
MAIN_TEMPLATE
,
META_TEMPLATE
,
TemplateEngine
)
PDF_NAME
=
Path
(
MAIN_TEMPLATE
)
.
with_suffix
(
'.pdf'
)
.
name
...
...
@@ -13,7 +15,10 @@ PDF_NAME = Path(MAIN_TEMPLATE).with_suffix('.pdf').name
def
execute_latex
(
tmp_dir
):
current_dir
=
os
.
getcwd
()
os
.
chdir
(
tmp_dir
)
execute_shell_command
(
'env buf_size=1000000 pdflatex {}'
.
format
(
MAIN_TEMPLATE
))
output
,
return_code
=
execute_shell_command_get_return_code
(
'env buf_size=1000000 pdflatex {}'
.
format
(
MAIN_TEMPLATE
))
if
return_code
!=
0
:
print
(
f
'Error when trying to build PDF:
\n
{output}'
)
sys
.
exit
(
1
)
os
.
chdir
(
current_dir
)
...
...
test/test_docker_entry.py
View file @
5d77c76b
from
pathlib
import
Path
import
shutil
import
PyPDF2
from
docker_entry
import
main
as
main_docker_entry
import
pathlib
import
shutil
# pylint: disable=redefined-outer-name
INTERFACE_DIR
=
Path
(
'/tmp/interface'
)
OUTPUT_FILE
=
INTERFACE_DIR
/
'pdf'
/
'A_devices_name_analysis_report.pdf'
TEST_META_DATA
=
Path
(
__file__
)
.
parent
/
'data'
/
'meta.json'
TEST_ANALYSIS_DATA
=
Path
(
__file__
)
.
parent
/
'data'
/
'analysis.json'
def
test_docker_entry
(
template_style
=
'default'
):
pathlib
.
Path
(
"/tmp/interface/data"
)
.
mkdir
(
parents
=
True
,
exist_ok
=
True
)
pathlib
.
Path
(
"/tmp/interface/pdf"
)
.
mkdir
(
parents
=
True
,
exist_ok
=
True
)
shutil
.
copyfile
(
'data/analysis.json'
,
'/tmp/interface/data/
analysis.json'
)
shutil
.
copyfile
(
'data/meta.json'
,
'/tmp/interface/data/
meta.json'
)
def
test_docker_entry
():
(
INTERFACE_DIR
/
'data'
)
.
mkdir
(
parents
=
True
,
exist_ok
=
True
)
(
INTERFACE_DIR
/
'pdf'
)
.
mkdir
(
parents
=
True
,
exist_ok
=
True
)
shutil
.
copyfile
(
TEST_ANALYSIS_DATA
,
INTERFACE_DIR
/
'data'
/
'
analysis.json'
)
shutil
.
copyfile
(
TEST_META_DATA
,
INTERFACE_DIR
/
'data'
/
'
meta.json'
)
output
=
main_docker_entry
()
assert
output
==
0
,
'LaTeX PDF build unsuccessful'
assert
OUTPUT_FILE
.
is_file
()
try
:
PyPDF2
.
PdfFileReader
(
open
(
'/tmp/interface/pdf/A_devices_name_analysis_report.pdf'
,
"rb"
))
PyPDF2
.
PdfFileReader
(
open
(
str
(
OUTPUT_FILE
),
'rb'
))
except
PyPDF2
.
utils
.
PdfReadError
:
assert
False
assert
pathlib
.
Path
(
'/tmp/interface/pdf/A_devices_name_analysis_report.pdf'
)
.
exists
()
assert
output
==
0
assert
False
,
'PDF could not be read'
test/unit/test_generator.py
View file @
5d77c76b
...
...
@@ -2,11 +2,11 @@ import json
from
pathlib
import
Path
import
pytest
from
pdf_generator.generator
import
(
LOGO_FILE
,
MAIN_TEMPLATE
,
META_TEMPLATE
,
copy_fact_image
,
create_report_filename
,
create_templates
,
execute_latex
copy_fact_image
,
create_report_filename
,
create_templates
,
execute_latex
,
LOGO_FILE
,
MAIN_TEMPLATE
,
META_TEMPLATE
)
from
test.data.test_dict
import
TEST_DICT
,
META
_DICT
from
test.data.test_dict
import
META_DICT
,
TEST
_DICT
class
MockEngine
:
...
...
@@ -15,7 +15,7 @@ class MockEngine:
@staticmethod
def
render_main_template
(
analysis
):
return
'{}'
.
format
(
json
.
dumps
(
analysis
)
)
return
json
.
dumps
(
analysis
)
@staticmethod
def
render_meta_template
(
meta_data
):
...
...
@@ -32,10 +32,11 @@ class MockEngine:
def
exec_mock
(
*
_
,
**
__
):
Path
(
'test'
)
.
write_text
(
'works'
)
return
''
,
0
def
test_execute_latex
(
monkeypatch
,
tmpdir
):
monkeypatch
.
setattr
(
'pdf_generator.generator.execute_shell_command'
,
exec_mock
)
monkeypatch
.
setattr
(
'pdf_generator.generator.execute_shell_command
_get_return_code
'
,
exec_mock
)
execute_latex
(
str
(
tmpdir
))
assert
Path
(
str
(
tmpdir
),
'test'
)
.
exists
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment