Tightened up the VASSAL tests.

master
Pacman Ghost 4 years ago
parent 46724dff85
commit 720e1540b1
  1. 1
      vasl_templates/webapp/static/vassal.js
  2. 8
      vasl_templates/webapp/tests/test_vassal.py
  3. 12
      vasl_templates/webapp/vassal.py
  4. BIN
      vassal-shim/release/vassal-shim.jar
  5. 24
      vassal-shim/src/vassal_shim/VassalShim.java

@ -26,6 +26,7 @@ function _do_update_vsav( vsav_data, fname )
filename: fname,
vsav_data: vsav_data,
players: [ get_player_nat(1), get_player_nat(2) ],
testMode: !! getUrlParam( "store_msgs" ),
snippets: snippets
} ;
$.ajax( {

@ -354,9 +354,7 @@ def test_dump_vsav( webapp, webdriver ):
"""Test dumping a scenario."""
# initialize
control_tests = init_webapp( webapp, webdriver,
reset = lambda ct: ct.set_data_dir( dtype="real" )
)
control_tests = init_webapp( webapp, webdriver )
def do_test(): #pylint: disable=missing-docstring
@ -686,9 +684,7 @@ def test_analyze_vsav_hip_concealed( webapp, webdriver ):
"""Test analyzing a scenario that contains HIP and concealed units."""
# initialize
control_tests = init_webapp( webapp, webdriver, vsav_persistence=1, scenario_persistence=1,
reset = lambda ct: ct.set_data_dir( dtype="real" )
)
control_tests = init_webapp( webapp, webdriver, vsav_persistence=1, scenario_persistence=1 )
def do_test(): #pylint: disable=missing-docstring

@ -36,6 +36,7 @@ def update_vsav(): #pylint: disable=too-many-statements,too-many-locals
vsav_filename = request.json[ "filename" ]
players = request.json[ "players" ]
snippets = request.json[ "snippets" ]
test_mode = request.json.get( "testMode" )
# initialize
logger = logging.getLogger( "update_vsav" )
@ -61,7 +62,7 @@ def update_vsav(): #pylint: disable=too-many-statements,too-many-locals
with TempFile() as snippets_file:
# save the snippets in a temp file
xml = _save_snippets( snippets, players, snippets_file, logger )
xml = _save_snippets( snippets, players, snippets_file, test_mode, logger )
snippets_file.close( delete=False )
fname = app.config.get( "UPDATE_VSAV_SNIPPETS" ) # nb: for diagnosing problems
if fname:
@ -115,7 +116,7 @@ def update_vsav(): #pylint: disable=too-many-statements,too-many-locals
},
} )
def _save_snippets( snippets, players, fp, logger ): #pylint: disable=too-many-locals
def _save_snippets( snippets, players, fp, test_mode, logger ): #pylint: disable=too-many-locals
"""Save the snippets in a file.
NOTE: We save the snippets as XML because Java :-/
@ -136,6 +137,13 @@ def _save_snippets( snippets, players, fp, logger ): #pylint: disable=too-many-l
ET.SubElement( root, "player1", nat=players[0] )
ET.SubElement( root, "player2", nat=players[1] )
# FUDGE! Some of the VASSAL tests update a scenario and check what labels were updated, but this can fail
# if we're using the real data files, and make a change to e.g. the common CSS (since it will cause labels
# to update unexpectedly). To work-around this, if we are running tests, we do tell the VASSAL shim to do
# "fuzzy" comparisons (and ignore un-important content) when deciding if a label needs to be updated.
if test_mode:
root.set( "fuzzyLabelCompares", "true" )
# add the snippets
for snippet_id,snippet_info in snippets.items():

@ -344,7 +344,8 @@ public class VassalShim
// load the snippets supplied to us by the web server
String[] players = new String[2] ;
Map<String,Snippet> snippets = new HashMap<String,Snippet>() ;
parseSnippets( snippetsFilename, players, snippets ) ;
AppBoolean fuzzyLabelCompares = new AppBoolean( false ) ;
parseSnippets( snippetsFilename, players, snippets, fuzzyLabelCompares ) ;
// load the scenario
configureBoards() ;
@ -392,7 +393,7 @@ public class VassalShim
}
// update the labels from the snippets
Map< String, ArrayList<ReportNode> > labelReport = processSnippets( ourLabels, otherLabels, snippets ) ;
Map< String, ArrayList<ReportNode> > labelReport = processSnippets( ourLabels, otherLabels, snippets, fuzzyLabelCompares ) ;
// save the scenario
saveScenario( saveFilename ) ;
@ -406,7 +407,7 @@ public class VassalShim
// any possible problems caused by reusing the current session (e.g. there might be some saved state somewhere).
}
private void parseSnippets( String snippetsFilename, String[] players, Map<String,Snippet> snippets ) throws IOException, ParserConfigurationException, SAXException, XPathExpressionException
private void parseSnippets( String snippetsFilename, String[] players, Map<String,Snippet> snippets, AppBoolean fuzzyLabelCompares ) throws IOException, ParserConfigurationException, SAXException, XPathExpressionException
{
logger.info( "Loading snippets: {}", snippetsFilename ) ;
@ -415,6 +416,9 @@ public class VassalShim
DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder() ;
Document doc = docBuilder.parse( new File( snippetsFilename ) ) ;
doc.getDocumentElement().normalize() ;
fuzzyLabelCompares.setVal(
doc.getDocumentElement().getAttribute( "fuzzyLabelCompares" ).equals( "true" )
) ;
// get the player details
NodeList nodes = doc.getElementsByTagName( "player1" ) ;
@ -537,7 +541,7 @@ public class VassalShim
}
private Map< String, ArrayList<ReportNode> >
processSnippets( Map<String,GamePieceLabelFields> ourLabels, ArrayList<GamePieceLabelFields> otherLabels, Map<String,Snippet> snippets )
processSnippets( Map<String,GamePieceLabelFields> ourLabels, ArrayList<GamePieceLabelFields> otherLabels, Map<String,Snippet> snippets, AppBoolean fuzzyLabelCompares )
{
// initialize
Map< String, ArrayList<ReportNode> > labelReport = new HashMap<String,ArrayList<ReportNode>>() ;
@ -574,9 +578,11 @@ public class VassalShim
}
// we've match the snippet to a label, update the label content
String currState = labelFields.gamePiece().getState() ;
String currStateCmp = fuzzyLabelCompares.getVal() ? adjustLabelContent( currState ) : currState ;
String snippetContent = snippet.content.replace( "\n", " " ) ;
String newState = labelFields.getNewGamePieceState( snippetContent ) ;
if ( currState.equals( newState ) ) {
String newStateCmp = fuzzyLabelCompares.getVal() ? adjustLabelContent( newState ) : newState ;
if ( currStateCmp.equals( newStateCmp ) ) {
logger.info( "- Skipping label (unchanged): {}", snippetId ) ;
labelReport.get( "unchanged" ).add( new ReportNode( snippetId, null ) ) ;
} else {
@ -921,6 +927,14 @@ public class VassalShim
Utils.saveXml( doc, reportFilename ) ;
}
private String adjustLabelContent( String val )
{
// remove content we want to ignore when comparing labels
Pattern pattern = Pattern.compile( "<style>.*?</style>" ) ;
val = pattern.matcher( val ).replaceAll( "{{{STYLE}}}" ) ;
return val ;
}
public void takeScreenshot( String scenarioFilename, String outputFilename )
throws IOException, InterruptedException
{

Loading…
Cancel
Save