From 881c6a099be11108b04ff7446204dfc0623fb0b2 Mon Sep 17 00:00:00 2001 From: hansonr Date: Thu, 9 May 2019 13:24:30 -0500 Subject: [PATCH] JAL-3253/JAL-3257 working on getting TestNG working with singletons check for null property file in Cache.setProperty to avoid error message in testng; fixes problems with FeatureFileTest and FeatureFile with mixed or unconsidered line endings --- src/jalview/bin/Cache.java | 2 +- src/jalview/io/FeaturesFile.java | 3 +- test/jalview/io/FeaturesFileTest.java | 68 +++++++++++++++++++++++---------- 3 files changed, 50 insertions(+), 23 deletions(-) diff --git a/src/jalview/bin/Cache.java b/src/jalview/bin/Cache.java index 09f8de7..ee97b7f 100755 --- a/src/jalview/bin/Cache.java +++ b/src/jalview/bin/Cache.java @@ -708,7 +708,7 @@ public class Cache try { oldValue = applicationProperties.setProperty(key, obj); - if (andSave && !propsAreReadOnly) + if (andSave && !propsAreReadOnly && propertiesFile != null) { FileOutputStream out = new FileOutputStream(propertiesFile); applicationProperties.store(out, "---JalviewX Properties File---"); diff --git a/src/jalview/io/FeaturesFile.java b/src/jalview/io/FeaturesFile.java index d51da33..1fb45bc 100755 --- a/src/jalview/io/FeaturesFile.java +++ b/src/jalview/io/FeaturesFile.java @@ -890,7 +890,8 @@ public class FeaturesFile extends AlignFile implements FeaturesSourceI StringBuilder out = new StringBuilder(256); - out.append(String.format("%s %d\n", GFF_VERSION, gffVersion == 0 ? 2 : gffVersion)); + out.append(String.format("%s %d" + newline, GFF_VERSION, + gffVersion == 0 ? 2 : gffVersion)); if (!includeNonPositionalFeatures && (visibleColours == null || visibleColours.isEmpty())) diff --git a/test/jalview/io/FeaturesFileTest.java b/test/jalview/io/FeaturesFileTest.java index fdef53d..a56a0de 100644 --- a/test/jalview/io/FeaturesFileTest.java +++ b/test/jalview/io/FeaturesFileTest.java @@ -491,7 +491,9 @@ public class FeaturesFileTest + "ENDGROUP\tuniprot\n\n" + "desc1\tFER_CAPAN\t-1\t0\t0\tPfam\t1.3\n\n" + "desc3\tFER1_SOLLC\t-1\t0\t0\tPfam\n"; // NaN is not output - assertEquals(expected, exported); + assertEquals( + expected.replace("\n", System.getProperty("line.separator")), + exported); /* * set METAL (in uniprot group) and GAMMA-TURN visible, but not Pfam @@ -506,7 +508,7 @@ public class FeaturesFileTest + "Turn\tFER_CAPAA\t-1\t36\t38\tGAMMA-TURN\t0.0\n" + "Iron\tFER_CAPAA\t-1\t39\t39\tMETAL\t0.0\n" + "ENDGROUP\tuniprot\n"; - assertEquals(expected, exported); + assertEquals(fixLineEnd(expected), exported); /* * now set Pfam visible @@ -528,7 +530,7 @@ public class FeaturesFileTest // null / empty group features are output after named groups + "\ndesc2\tFER_CAPAN\t-1\t4\t9\tPfam\n" + "\ndesc4\tFER1_SOLLC\t-1\t5\t8\tPfam\t-2.6\n"; - assertEquals(expected, exported); + assertEquals(fixLineEnd(expected), exported); /* * hide uniprot group @@ -540,7 +542,7 @@ public class FeaturesFileTest + "\ndesc4\tFER1_SOLLC\t-1\t5\t8\tPfam\t-2.6\n"; exported = featuresFile.printJalviewFormat(al.getSequencesArray(), fr, false); - assertEquals(expected, exported); + assertEquals(fixLineEnd(expected), exported); /* * include non-positional (overrides group not shown) @@ -556,7 +558,7 @@ public class FeaturesFileTest + "desc2\tFER_CAPAN\t-1\t4\t9\tPfam\n" + "\ndesc3\tFER1_SOLLC\t-1\t0\t0\tPfam\n" + "desc4\tFER1_SOLLC\t-1\t5\t8\tPfam\t-2.6\n"; - assertEquals(expected, exported); + assertEquals(fixLineEnd(expected), exported); } @Test(groups = { "Functional" }) @@ -575,10 +577,14 @@ public class FeaturesFileTest String exported = featuresFile.printGffFormat(al.getSequencesArray(), fr, false); String gffHeader = "##gff-version 2\n"; - assertEquals(gffHeader, exported); + assertEquals( + fixLineEnd(gffHeader), + exported); exported = featuresFile.printGffFormat(al.getSequencesArray(), fr, true); - assertEquals(gffHeader, exported); + assertEquals( + fixLineEnd(gffHeader), + exported); /* * add some features @@ -615,7 +621,9 @@ public class FeaturesFileTest */ exported = featuresFile.printGffFormat(al.getSequencesArray(), fr, false); - assertEquals(gffHeader, exported); + assertEquals( + fixLineEnd(gffHeader), + exported); /* * include non-positional features @@ -626,7 +634,9 @@ public class FeaturesFileTest true); String expected = gffHeader + "FER_CAPAA\tUniprot\tDomain\t0\t0\t0.0\t.\t.\n"; - assertEquals(expected, exported); + assertEquals( + fixLineEnd(expected), + exported); /* * set METAL (in uniprot group) and GAMMA-TURN visible, but not Pfam @@ -638,7 +648,9 @@ public class FeaturesFileTest false); // METAL feature has null group: description used for column 2 expected = gffHeader + "FER_CAPAA\tCath\tMETAL\t39\t39\t1.2\t.\t.\n"; - assertEquals(expected, exported); + assertEquals( + expected.replace("\n", System.getProperty("line.separator")), + exported); /* * set s3dm group visible @@ -649,7 +661,9 @@ public class FeaturesFileTest // METAL feature has null group: description used for column 2 expected = gffHeader + "FER_CAPAA\tCath\tMETAL\t39\t39\t1.2\t.\t.\n" + "FER_CAPAN\ts3dm\tGAMMA-TURN\t36\t38\t2.1\t.\t.\n"; - assertEquals(expected, exported); + assertEquals( + expected.replace("\n", System.getProperty("line.separator")), + exported); /* * now set Pfam visible @@ -662,7 +676,14 @@ public class FeaturesFileTest + "FER_CAPAA\tCath\tMETAL\t39\t39\t1.2\t.\t.\n" + "FER_CAPAN\ts3dm\tGAMMA-TURN\t36\t38\t2.1\t.\t.\n" + "FER_CAPAN\tUniprot\tPfam\t20\t20\t0.0\t+\t2\tx=y;black=white\n"; - assertEquals(expected, exported); + assertEquals( + expected.replace("\n", System.getProperty("line.separator")), + exported); + } + + private String fixLineEnd(String s) + { + return s.replace("\n", System.getProperty("line.separator")); } /** @@ -737,7 +758,7 @@ public class FeaturesFileTest visible.put("foobar", new FeatureColour(Color.blue)); ff.outputFeatureFilters(sb, visible, featureFilters); String expected = "\nSTARTFILTERS\nfoobar\tLabel Present\npfam\t(CSQ:PolyPhen Present) AND (Score LE -2.4)\nENDFILTERS\n"; - assertEquals(expected, sb.toString()); + assertEquals(fixLineEnd(expected), sb.toString()); } /** @@ -774,7 +795,8 @@ public class FeaturesFileTest String expected = gffHeader + "FER_CAPAA\tCath\tMETAL\t39\t39\t1.2\t.\t.\n" + "FER_CAPAA\tCath\tMETAL\t41\t41\t0.6\t.\t.\n"; - assertEquals(expected, exported); + assertEquals( + fixLineEnd(expected), exported); /* * now threshold to Score > 1.1 - should exclude sf2 @@ -787,7 +809,7 @@ public class FeaturesFileTest exported = featuresFile.printGffFormat(al.getSequencesArray(), fr, false); expected = gffHeader + "FER_CAPAA\tCath\tMETAL\t39\t39\t1.2\t.\t.\n"; - assertEquals(expected, exported); + assertEquals(fixLineEnd(expected), exported); /* * remove threshold and check sf2 is exported @@ -797,7 +819,7 @@ public class FeaturesFileTest false); expected = gffHeader + "FER_CAPAA\tCath\tMETAL\t39\t39\t1.2\t.\t.\n" + "FER_CAPAA\tCath\tMETAL\t41\t41\t0.6\t.\t.\n"; - assertEquals(expected, exported); + assertEquals(fixLineEnd(expected), exported); /* * filter on (clin_sig contains Benign) - should include sf2 and exclude sf1 @@ -809,7 +831,7 @@ public class FeaturesFileTest exported = featuresFile.printGffFormat(al.getSequencesArray(), fr, false); expected = gffHeader + "FER_CAPAA\tCath\tMETAL\t41\t41\t0.6\t.\t.\n"; - assertEquals(expected, exported); + assertEquals(fixLineEnd(expected), exported); } /** @@ -849,7 +871,9 @@ public class FeaturesFileTest + "ENDGROUP\tgrp1\n\nSTARTGROUP\tgrp2\n" + "Cath\tFER_CAPAA\t-1\t41\t41\tMETAL\t0.6\n" + "ENDGROUP\tgrp2\n"; - assertEquals(expected, exported); + assertEquals( + fixLineEnd(expected), + exported); /* * now threshold to Score > 1.1 - should exclude sf2 @@ -866,7 +890,9 @@ public class FeaturesFileTest + "STARTGROUP\tgrp1\n" + "Cath\tFER_CAPAA\t-1\t39\t39\tMETAL\t1.2\n" + "ENDGROUP\tgrp1\n"; - assertEquals(expected, exported); + assertEquals( + expected.replace("\n", System.getProperty("line.separator")), + exported); /* * remove threshold and check sf2 is exported @@ -880,7 +906,7 @@ public class FeaturesFileTest + "ENDGROUP\tgrp1\n\nSTARTGROUP\tgrp2\n" + "Cath\tFER_CAPAA\t-1\t41\t41\tMETAL\t0.6\n" + "ENDGROUP\tgrp2\n"; - assertEquals(expected, exported); + assertEquals(fixLineEnd(expected), exported); /* * filter on (clin_sig contains Benign) - should include sf2 and exclude sf1 @@ -897,6 +923,6 @@ public class FeaturesFileTest + "STARTGROUP\tgrp2\n" + "Cath\tFER_CAPAA\t-1\t41\t41\tMETAL\t0.6\n" + "ENDGROUP\tgrp2\n"; - assertEquals(expected, exported); + assertEquals(fixLineEnd(expected), exported); } } -- 1.7.10.2