X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=test%2Fjalview%2Fbin%2Fargparser%2FArgParserTest.java;h=3ba096e6a54b9e155edd4732f903babd91564455;hb=96f727b57ac588f9307116b79a7f1ab67dbff39b;hp=8d4540a3be4817c1ab97c111348dd996d769c18d;hpb=91581a29a66a51e9c2f3039fd2df8c8870acd606;p=jalview.git diff --git a/test/jalview/bin/argparser/ArgParserTest.java b/test/jalview/bin/argparser/ArgParserTest.java index 8d4540a..3ba096e 100644 --- a/test/jalview/bin/argparser/ArgParserTest.java +++ b/test/jalview/bin/argparser/ArgParserTest.java @@ -7,10 +7,12 @@ import java.util.Properties; import org.testng.Assert; import org.testng.annotations.AfterClass; +import org.testng.annotations.AfterMethod; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; import jalview.bin.Cache; +import jalview.gui.Desktop; @Test(singleThreaded = true) public class ArgParserTest @@ -21,6 +23,13 @@ public class ArgParserTest Cache.loadProperties("test/jalview/testProps.jvprops"); } + @AfterMethod(alwaysRun = true) + public void tearDown() + { + if (Desktop.instance != null) + Desktop.instance.closeAll_actionPerformed(null); + } + @Test(groups = "Functional", dataProvider = "argLines") public void parseArgsTest(String commandLineArgs, Arg a, String other) { @@ -35,7 +44,7 @@ public class ArgParserTest { String[] args = commandLineArgs.split("\\s+"); ArgParser argparser = new ArgParser(args); - ArgValuesMap avm = argparser.linkedArgs(linkedId); + ArgValuesMap avm = argparser.getLinkedArgs(linkedId); ArgValue av = avm.getArgValue(a); SubVals sv = av.getSubVals(); String testString = null; @@ -63,11 +72,11 @@ public class ArgParserTest public void parseAutoIndexAndSubstitutionsTest(String commandLineArgs, String linkedId, Arg a, String filename) { - // { "--append=filename0 --newframe --append=filename1", "JALVIEW:1", + // { "--append=filename0 --new --append=filename1", "JALVIEW:1", // Arg.OPEN, "filename1" }, String[] args = commandLineArgs.split("\\s+"); ArgParser argparser = new ArgParser(args); - ArgValuesMap avm = argparser.linkedArgs(linkedId); + ArgValuesMap avm = argparser.getLinkedArgs(linkedId); ArgValue av = avm.getArgValue(a); Assert.assertEquals(av.getValue(), filename); } @@ -81,14 +90,14 @@ public class ArgParserTest Assert.assertTrue(b.contains(a)); if (a == Arg.PROPS) { - Properties bP = Cache.bootstrapProperties(b.get(Arg.PROPS)); + Properties bP = Cache.bootstrapProperties(b.getValue(Arg.PROPS)); Assert.assertNotNull(bP); Assert.assertTrue(other.equals(bP.get(Cache.BOOTSTRAP_TEST))); Assert.assertFalse(bP.contains("NOT" + Cache.BOOTSTRAP_TEST)); } else if (a == Arg.ARGFILE) { - List filenames = b.getList(a); + List filenames = b.getValueList(a); boolean found = false; for (String s : filenames) { @@ -121,7 +130,7 @@ public class ArgParserTest Assert.assertFalse(b.contains(Arg.APPEND)); if (a == Arg.PROPS) { - Properties bP = Cache.bootstrapProperties(b.get(Arg.PROPS)); + Properties bP = Cache.bootstrapProperties(b.getValue(Arg.PROPS)); Assert.assertTrue("true".equals(bP.get(Cache.BOOTSTRAP_TEST))); } } @@ -175,9 +184,12 @@ public class ArgParserTest @DataProvider(name = "argSubValsAndLinkedIds") public Object[][] argSubValsAndLinkedIds() { - return new Object[][] { { - "--debug --append=[hi]test/jalview/bin/argparser/testfiles/test1.fa", - "JALVIEW:0", Arg.APPEND, "hi", "true", true }, + return new Object[][] { + // + /* + */ + { "--debug --append=[hi]test/jalview/bin/argparser/testfiles/test1.fa", + "JALVIEW:0", Arg.APPEND, "hi", "true", true }, { "--append[linkedId1]=[new,hello=world,1]test/jalview/bin/argparser/testfiles/test1.fa --headless", "linkedId1", Arg.APPEND, "new", "true", true }, { "--append[linkedId2]=[new,hello=world,1]test/jalview/bin/argparser/testfiles/test1.fa --headless", @@ -189,7 +201,11 @@ public class ArgParserTest { "--append[linkedId5]=[new,hello=worlddomination,1]test/jalview/bin/argparser/testfiles/test1.fa --append[linkedId2]=[new;hello=world;1]test/jalview/bin/argparser/testfiles/test1.fa --headless", "linkedId5", Arg.APPEND, "hello", "world", false }, { "--append[linkedId6]=[new,hello=world,0]test/jalview/bin/argparser/testfiles/test1.fa --append[linkedId7]=[new;hello=world;1]test/jalview/bin/argparser/testfiles/test1.fa --headless", - "linkedId7", Arg.APPEND, "GETINDEX", "0", false }, }; + "linkedId7", Arg.APPEND, "GETINDEX", "0", false }, + /* + */ + // + }; } @DataProvider(name = "argAutoIndexAndSubstitutions") @@ -201,12 +217,12 @@ public class ArgParserTest */ { "--append=filename0 --append=filename1", "JALVIEW:0", Arg.APPEND, "filename0" }, - { "--append=filename0 --newframe --append=filename1", "JALVIEW:1", + { "--append=filename0 --new --append=filename1", "JALVIEW:1", Arg.APPEND, "filename1" }, - { "--append=filename0 --newframe --newframe --append=filename2", - "JALVIEW:0", Arg.APPEND, "filename0" }, - { "--append=filename0 --newframe --newframe --append=filename2", - "JALVIEW:2", Arg.APPEND, "filename2" }, + { "--append=filename0 --new --new --append=filename2", "JALVIEW:0", + Arg.APPEND, "filename0" }, + { "--append=filename0 --new --new --append=filename2", "JALVIEW:2", + Arg.APPEND, "filename2" }, { "--append[linkA-{n}]=filenameA0 --append[linkA-{++n}]=filenameA1", "linkA-0", Arg.APPEND, "filenameA0" }, { "--append[linkB-{n}]=filenameB0 --append[linkB-{++n}]=filenameB1", @@ -223,14 +239,14 @@ public class ArgParserTest "linkG-1", Arg.IMAGE, "outputG{n}.txt" }, { "--append[linkH-{n}]=filenameH0 --substitutions --image[linkH-{n}]=output-H{n}.txt --nil[{++n}] --nosubstitutions --image[linkH-{n}]=outputH{n}.txt", "linkH-0", Arg.IMAGE, "output-H0.txt" }, - { "--open=filename0 --append=filename1", "JALVIEW:1", Arg.OPEN, + { "--open=filename0 --append=filename1", "JALVIEW:0", Arg.OPEN, "filename0" }, - { "--open=filename0 --newframe --append=filename1", "JALVIEW:2", + { "--open=filename0 --new --append=filename1", "JALVIEW:1", Arg.APPEND, "filename1" }, - { "--open=filename0 --newframe --newframe --append=filename2", - "JALVIEW:1", Arg.OPEN, "filename0" }, - { "--open=filename0 --newframe --newframe --append=filename2", - "JALVIEW:3", Arg.APPEND, "filename2" }, + { "--open=filename0 --new --new --append=filename2", "JALVIEW:0", + Arg.OPEN, "filename0" }, + { "--open=filename0 --new --new --append=filename2", "JALVIEW:2", + Arg.APPEND, "filename2" }, { "--open[linkA-{n}]=filenameA0 --append[linkA-{++n}]=filenameA1", "linkA-0", Arg.OPEN, "filenameA0" }, { "--open[linkB-{n}]=filenameB0 --append[linkB-{++n}]=filenameB1", @@ -247,6 +263,8 @@ public class ArgParserTest "linkG-1", Arg.IMAGE, "outputG{n}.txt" }, { "--open[linkH-{n}]=filenameH0 --substitutions --image[linkH-{n}]=output-H{n}.txt --nil[{++n}] --nosubstitutions --image[linkH-{n}]=outputH{n}.txt", "linkH-0", Arg.IMAGE, "output-H0.txt" }, + /* + */ // }; @@ -260,24 +278,158 @@ public class ArgParserTest Arg.ARGFILE, "test/jalview/bin/argfiles/testfiles/test1.fa" } }; } - @DataProvider(name = "allLinkedIdData") - public Object[][] allLinkedIdData() + @Test(groups = "Functional", dataProvider = "allLinkedIdsData") + public void allLinkedIdsTest(String pwd, String commandLineArgs, Arg a, + String[] values, String[] nonvalues) + { + String userDir = System.getProperty("user.dir"); + if (pwd != null) + { + File pwdFile = new File(pwd); + System.setProperty("user.dir", pwdFile.getAbsolutePath()); + } + String[] args = commandLineArgs.split("\\s+"); + ArgParser argparser = new ArgParser(args); + + int num = values.length; + List linkedIds = argparser.getLinkedIds(); + Assert.assertEquals(linkedIds.size(), num, + "Wrong number of linkedIds: " + linkedIds.toString()); + for (int i = 0; i < num; i++) + { + String value = values[i]; + String linkedId = linkedIds.get(i); + ArgValuesMap avm = argparser.getLinkedArgs(linkedId); + if (value == null) + { + Assert.assertTrue(avm.containsArg(a), + "Arg value for " + a.argString() + + " not applied correctly to linkedId '" + linkedId + + "'"); + } + else + { + ArgValues avs = avm.getArgValues(a); + ArgValue av = avs.getArgValue(); + String v = av.getValue(); + value = new File(value).getPath(); + Assert.assertEquals(v, value, "Arg value for " + a.argString() + + " not applied correctly to linkedId '" + linkedId + "'"); + } + } + + System.setProperty("user.dir", userDir); + } + + @DataProvider(name = "allLinkedIdsData") + public Object[][] allLinkedIdsData() { return new Object[][] { // - { "--open=test/jalview/bin/argparser/testfiles/*.fa --substitutions --all --output={dirname}/{basename}.stk --close", + /* + */ + { null, + "--open=test/jalview/bin/argparser/testfiles/*.fa --substitutions --all --image={dirname}/{basename}.png --close", + Arg.CLOSE, new String[] + { null, null, null }, + null }, + { null, + "--open=test/jalview/bin/argparser/testfiles/*.fa --substitutions --all --output={dirname}/{basename}.stk --close", Arg.OUTPUT, new String[] - { "test/jalview/bin/argfiles/testfiles/test1.stk", - "test/jalview/bin/argfiles/testfiles/test2.stk", - "test/jalview/bin/argfiles/testfiles/test3.stk", } }, - { "--open=test/jalview/bin/argparser/testfiles/*.fa --substitutions --all --image={dirname}/{basename}.png --close", + { "test/jalview/bin/argparser/testfiles/test1.stk", + "test/jalview/bin/argparser/testfiles/test2.stk", + "test/jalview/bin/argparser/testfiles/test3.stk", }, + null }, + { null, + "--open=test/jalview/bin/argparser/testfiles/*.fa --substitutions --all --image={dirname}/{basename}.png --close", Arg.IMAGE, new String[] - { "test/jalview/bin/argfiles/testfiles/test1.png", - "test/jalview/bin/argfiles/testfiles/test2.png", - "test/jalview/bin/argfiles/testfiles/test3.png", } }, - { "--open=test/jalview/bin/argparser/testfiles/*.fa --substitutions --all --image={dirname}/{basename}.png --close", - Arg.CLOSE, null }, + { "test/jalview/bin/argparser/testfiles/test1.png", + "test/jalview/bin/argparser/testfiles/test2.png", + "test/jalview/bin/argparser/testfiles/test3.png", }, + null }, + /* + * Find a way to change pwd reliably -- need to match "*.fa" against some files! + { "test/jalview/bin/argparser/testfiles", + + "--open=*.fa --image={dirname}/{basename}.png --close", + Arg.IMAGE, new String[] + { "./test1.png", "./test2.png", "./test3.png", }, null }, + */ + // + }; + } + + @Test(groups = "Functional", dataProvider = "bootstrapArgsData") + public void bootstrapArgsValuesAndHeadlessModeTest(String commandLineArgs, + Arg a, String valS, boolean valB, boolean headlessValue) + { + String[] args = commandLineArgs.split("\\s+"); + BootstrapArgs bsa = BootstrapArgs.getBootstrapArgs(args); + if (a != null) + { + if (valS != null) + { + Assert.assertEquals(bsa.getValue(a), valS, + "BootstrapArg " + a.argString() + + " value does not match expected '" + valS + "'"); + } + else + { + Assert.assertEquals(bsa.getBoolean(a), valB, + "Boolean/Unary value of BootstrapArg " + a.argString() + + "' is not the expected '" + valB + "'"); + } + } + + boolean isHeadless = bsa.isHeadless(); + Assert.assertEquals(isHeadless, headlessValue, + "Assumed headless setting '" + isHeadless + "' is wrong."); + } + + @DataProvider(name = "bootstrapArgsData") + public Object[][] bootstrapArgsData() + { + return new Object[][] { + /* + * cmdline args + * Arg (null if only testing headless) + * String value if there is one (null otherwise) + * boolean value if String value is null + * expected value of isHeadless() + */ + /* + */ + { "--open thisway.fa --output thatway.fa --jabaws https://forwardsandbackwards.com/", + Arg.JABAWS, "https://forwardsandbackwards.com/", false, true }, + { "--help-all --open thisway.fa --output thatway.fa --jabaws https://forwardsandbackwards.com/", + Arg.HELP, null, true, true }, + { "--help-all --nonews --open thisway.fa --output thatway.fa --jabaws https://forwardsandbackwards.com/", + Arg.NEWS, null, false, true }, + { "--help --nonews --open thisway.fa --output thatway.fa --jabaws https://forwardsandbackwards.com/", + Arg.NEWS, null, false, true }, + { "--help-opening --nonews --open thisway.fa --output thatway.fa --jabaws https://forwardsandbackwards.com/", + Arg.NEWS, null, false, true }, + { "--nonews --open thisway.fa --output thatway.fa --jabaws https://forwardsandbackwards.com/", + Arg.NEWS, null, false, true }, + { "--open thisway.fa --image thatway.png", null, null, false, + true }, + { "--open thisway.fa --output thatway.png", null, null, false, + true }, + { "--open thisway.fa --image thatway.png --noheadless", null, null, + false, false }, + { "--open thisway.fa --output thatway.png --noheadless", null, null, + false, false }, + { "--open thisway.fa --image thatway.png --gui", null, null, false, + false }, + { "--open thisway.fa --output thatway.png --gui", null, null, false, + false }, + // --gui takes precedence + { "--open thisway.fa --image thatway.png --gui --headless", null, + null, false, false }, + { "--open thisway.fa --output thatway.png --gui --headless", null, + null, false, false }, // }; } -} + +} \ No newline at end of file