Added a test for generating the Chapter H placeholder files.

master
Pacman Ghost 5 years ago
parent 3344cdf083
commit 37b02ccb0a
  1. 22
      vasl_templates/tools/make_chapter_h_placeholders.py
  2. 1177
      vasl_templates/tools/tests/fixtures/chapter-h-placeholders.txt
  3. 26
      vasl_templates/tools/tests/test_make_chapter_h_placeholders.py

@ -15,11 +15,22 @@ import click
def main( output_fname ): # pylint: disable=too-many-locals,too-many-branches
"""Create a ZIP file with placeholder files for each Chapter H note and multi-applicable note."""
def log( fmt, *args ): #pylint: disable=missing-docstring
print( fmt.format( *args ) )
return make_chapter_h_placeholders( output_fname, log=log )
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def make_chapter_h_placeholders( output_fname, log=None ): #pylint: disable=too-many-locals,too-many-branches
"""Create a ZIP file with placeholder files for each Chapter H note and multi-applicable note."""
# initialize
if not output_fname:
raise RuntimeError( "Output ZIP file not specified." )
if os.path.isfile( output_fname ):
raise RuntimeError( "Output ZIP file exists." )
if not log:
def log_nothing( fmt, *args ): #pylint: disable=missing-docstring,unused-argument
pass
log = log_nothing
results = {}
# load the vehicle/ordnance data files
@ -50,14 +61,14 @@ def main( output_fname ): # pylint: disable=too-many-locals,too-many-branches
nats = sorted( results.keys() )
for nat in nats: #pylint: disable=too-many-nested-blocks
for vo_type in ("vehicles","ordnance"):
print( "Generating {} {}...".format( nat, vo_type ) )
log( "Generating {} {}...", nat, vo_type )
for note_type in ("notes","ma_notes"):
# get the next set of note ID's
vals = results[nat].get( vo_type, {} ).get( note_type )
if not vals:
continue
print( "- {}: {}".format( note_type, ", ".join( str(v) for v in vals ) ) )
log( "- {}: {}", note_type, ", ".join( str(v) for v in vals ) )
for val in vals:
@ -76,8 +87,7 @@ def main( output_fname ): # pylint: disable=too-many-locals,too-many-branches
# add the placeholder file to the ZIP
zip_file.writestr( fname, b"" )
print()
log( "" )
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

File diff suppressed because it is too large Load Diff

@ -0,0 +1,26 @@
"""Test generating the Chapter H placeholder files."""
import os
from zipfile import ZipFile
from vasl_templates.tools.make_chapter_h_placeholders import make_chapter_h_placeholders
from vasl_templates.webapp.utils import TempFile
# ---------------------------------------------------------------------
def test_make_chapter_h_placeholders():
"""Test generating the Chapter H placeholder files."""
with TempFile() as temp_file:
# generate the Chapter H placeholder files
make_chapter_h_placeholders( temp_file.name )
# get the expected results
fname = os.path.join( os.path.split(__file__)[0], "fixtures/chapter-h-placeholders.txt" )
expected = [ line.strip() for line in open(fname,"r") ]
# check the results
with ZipFile( temp_file.name, "r" ) as zip_file:
zip_fnames = sorted( zip_file.namelist() )
assert zip_fnames == expected
Loading…
Cancel
Save