diff --git a/vasl_templates/webapp/static/vassal.js b/vasl_templates/webapp/static/vassal.js index 61878ba..c0f2d9f 100644 --- a/vasl_templates/webapp/static/vassal.js +++ b/vasl_templates/webapp/static/vassal.js @@ -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( { diff --git a/vasl_templates/webapp/tests/test_vassal.py b/vasl_templates/webapp/tests/test_vassal.py index 63b1aad..05909e7 100644 --- a/vasl_templates/webapp/tests/test_vassal.py +++ b/vasl_templates/webapp/tests/test_vassal.py @@ -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 diff --git a/vasl_templates/webapp/vassal.py b/vasl_templates/webapp/vassal.py index aafae72..fe1abe1 100644 --- a/vasl_templates/webapp/vassal.py +++ b/vasl_templates/webapp/vassal.py @@ -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(): diff --git a/vassal-shim/release/vassal-shim.jar b/vassal-shim/release/vassal-shim.jar index a0226e8..73e2971 100644 Binary files a/vassal-shim/release/vassal-shim.jar and b/vassal-shim/release/vassal-shim.jar differ diff --git a/vassal-shim/src/vassal_shim/VassalShim.java b/vassal-shim/src/vassal_shim/VassalShim.java index 8ff6e48..7742668 100644 --- a/vassal-shim/src/vassal_shim/VassalShim.java +++ b/vassal-shim/src/vassal_shim/VassalShim.java @@ -344,7 +344,8 @@ public class VassalShim // load the snippets supplied to us by the web server String[] players = new String[2] ; Map snippets = new HashMap() ; - 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 > labelReport = processSnippets( ourLabels, otherLabels, snippets ) ; + Map< String, ArrayList > 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 snippets ) throws IOException, ParserConfigurationException, SAXException, XPathExpressionException + private void parseSnippets( String snippetsFilename, String[] players, Map 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 > - processSnippets( Map ourLabels, ArrayList otherLabels, Map snippets ) + processSnippets( Map ourLabels, ArrayList otherLabels, Map snippets, AppBoolean fuzzyLabelCompares ) { // initialize Map< String, ArrayList > labelReport = new HashMap>() ; @@ -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( "" ) ; + val = pattern.matcher( val ).replaceAll( "{{{STYLE}}}" ) ; + return val ; + } + public void takeScreenshot( String scenarioFilename, String outputFilename ) throws IOException, InterruptedException {