From: Ben Soares Date: Wed, 29 Mar 2023 23:01:12 +0000 (+0100) Subject: JAL-629 extensive tests for ArgParser features X-Git-Tag: Release_2_11_4_0~417 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=97a11ea5aad66b0ff248ca13dd6a7023c4e089d1;p=jalview.git JAL-629 extensive tests for ArgParser features --- diff --git a/test/jalview/bin/ArgParserTest.java b/test/jalview/bin/ArgParserTest.java deleted file mode 100644 index e93f36f..0000000 --- a/test/jalview/bin/ArgParserTest.java +++ /dev/null @@ -1,133 +0,0 @@ -package jalview.bin; - -import java.io.File; -import java.io.IOException; -import java.util.List; -import java.util.Properties; - -import org.testng.Assert; -import org.testng.annotations.AfterClass; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; - -import jalview.bin.argparser.Arg; -import jalview.bin.argparser.ArgParser; -import jalview.bin.argparser.BootstrapArgs; - -@Test(singleThreaded = true) -public class ArgParserTest -{ - @AfterClass(alwaysRun = true) - public static void resetProps() - { - Cache.loadProperties("test/jalview/testProps.jvprops"); - } - - @Test(groups = "Functional", dataProvider = "argLines") - public void parseArgsAndSubValsTest(String commandLineArgs, Arg a, - String other) - { - String[] args = commandLineArgs.split("\\s*"); - ArgParser argparser = new ArgParser(args); - } - - @Test(groups = "Functional", dataProvider = "argLines") - public void bootstrapArgsTest(String commandLineArgs, Arg a, String other) - { - String[] args = commandLineArgs.split("\\s+"); - BootstrapArgs b = BootstrapArgs.getBootstrapArgs(args); - - Assert.assertTrue(b.contains(a)); - if (a == Arg.PROPS) - { - Properties bP = Cache.bootstrapProperties(b.get(Arg.PROPS)); - 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); - boolean found = false; - for (String s : filenames) - { - File f = new File(s); - File fo = new File(other); - try - { - if (fo.getCanonicalPath().equals(f.getCanonicalPath())) - { - found = true; - break; - } - } catch (IOException e) - { - } - } - Assert.assertTrue(found, - "File '" + other + "' not found in shell expanded glob '" - + commandLineArgs + "'"); - } - - } - - @Test(groups = "Functional", dataProvider = "argFiles") - public void argFilesTest(String commandLineArgs, Arg a, String other) - { - String[] args = commandLineArgs.split("\\s+"); - BootstrapArgs b = BootstrapArgs.getBootstrapArgs(args); - - Assert.assertTrue(b.contains(a)); - Assert.assertFalse(b.contains(Arg.OPEN)); - if (a == Arg.PROPS) - { - Properties bP = Cache.bootstrapProperties(b.get(Arg.PROPS)); - Assert.assertTrue("true".equals(bP.get(Cache.BOOTSTRAP_TEST))); - } - } - - @DataProvider(name = "argLinesNotworking") - public Object[][] argLinesTest() - { - return new Object[][] { - // can't use this one yet as it doesn't get shell glob expanded by the - // test - { "--argfile test/jalview/bin/argparser/argfile*.txt", Arg.ARGFILE, - "test/jalview/bin/argparser/argfile0.txt" }, }; - } - - @DataProvider(name = "argLines") - public Object[][] argLines() - { - return new Object[][] { - { "--debug --open=test/jalview/bin/argparser/test1.fa", Arg.DEBUG, - null }, - { "--open=test/jalview/bin/argparser/test1.fa --headless", - Arg.HEADLESS, null }, - { "--open=test/jalview/bin/argparser/test1.fa --props=test/jalview/bin/argparser/testProps.jvprops", - Arg.PROPS, "true" }, - { "--argfile test/jalview/bin/argparser/argfile0.txt", Arg.ARGFILE, - "test/jalview/bin/argparser/argfile0.txt" }, - // these next three are what a shell glob expansion would look like - { "--argfile test/jalview/bin/argparser/argfile0.txt test/jalview/bin/argparser/argfile1.txt test/jalview/bin/argparser/argfile2.txt", - Arg.ARGFILE, "test/jalview/bin/argparser/argfile0.txt" }, - { "--argfile test/jalview/bin/argparser/argfile0.txt test/jalview/bin/argparser/argfile1.txt test/jalview/bin/argparser/argfile2.txt", - Arg.ARGFILE, "test/jalview/bin/argparser/argfile1.txt" }, - { "--argfile test/jalview/bin/argparser/argfile0.txt test/jalview/bin/argparser/argfile1.txt test/jalview/bin/argparser/argfile2.txt", - Arg.ARGFILE, "test/jalview/bin/argparser/argfile2.txt" }, - { "--argfile=test/jalview/bin/argparser/argfile*.txt", Arg.ARGFILE, - "test/jalview/bin/argparser/argfile0.txt" }, - { "--argfile=test/jalview/bin/argparser/argfile*.txt", Arg.ARGFILE, - "test/jalview/bin/argparser/argfile1.txt" }, - { "--argfile=test/jalview/bin/argparser/argfile*.txt", Arg.ARGFILE, - "test/jalview/bin/argparser/argfile2.txt" } }; - - } - - @DataProvider(name = "argFiles") - public Object[][] argFiles() - { - return new Object[][] { { - "--argfile=test/jalview/bin/argparser/argfile0.txt --open=shouldntbeabootstrap", - Arg.ARGFILE, "test/jalview/bin/argfiles/test1.fa" } }; - } -} diff --git a/test/jalview/bin/ArgsParserTest.java b/test/jalview/bin/ArgsParserTest.java index a163a49..f36b45a 100644 --- a/test/jalview/bin/ArgsParserTest.java +++ b/test/jalview/bin/ArgsParserTest.java @@ -18,7 +18,7 @@ * along with Jalview. If not, see . * The Jalview Authors are detailed in the 'AUTHORS' file. */ -package jalview.bin.argparser; +package jalview.bin; import static org.testng.AssertJUnit.assertEquals; import static org.testng.AssertJUnit.assertFalse; diff --git a/test/jalview/bin/CommandsTest.java b/test/jalview/bin/CommandsTest.java index 41588e6..204714f 100644 --- a/test/jalview/bin/CommandsTest.java +++ b/test/jalview/bin/CommandsTest.java @@ -85,8 +85,18 @@ public class CommandsTest @DataProvider(name = "cmdLines") public Object[][] cmdLines() { - return new Object[][] { { "--open=examples/uniref50.fa", "FER1_SPIOL" }, - { "--argfile=test/jalview/bin/argparser/argfile0.txt", null } }; + return new Object[][] { + { "--open=examples/uniref50.fa", "FER1_SPIOL" }, + { "--argfile=test/jalview/bin/argparser/testfiles/argfile0.txt", + null } }; + } + + @DataProvider(name = "openingAlignments") + public Object[][] openingAlignments() + { + return new Object[][] { + { "--open=examples/uniref50.fa", 1 }, + { "--argfile=test/jalview/bin/argparser/testfiles/argfile0.txt", } }; } } diff --git a/test/jalview/bin/argparser/ArgParserTest.java b/test/jalview/bin/argparser/ArgParserTest.java new file mode 100644 index 0000000..47d9e24 --- /dev/null +++ b/test/jalview/bin/argparser/ArgParserTest.java @@ -0,0 +1,229 @@ +package jalview.bin.argparser; + +import java.io.File; +import java.io.IOException; +import java.util.List; +import java.util.Properties; + +import org.testng.Assert; +import org.testng.annotations.AfterClass; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; + +import jalview.bin.Cache; + +@Test(singleThreaded = true) +public class ArgParserTest +{ + @AfterClass(alwaysRun = true) + public static void resetProps() + { + Cache.loadProperties("test/jalview/testProps.jvprops"); + } + + @Test(groups = "Functional", dataProvider = "argLines") + public void parseArgsTest(String commandLineArgs, Arg a, String other) + { + String[] args = commandLineArgs.split("\\s+"); + ArgParser argparser = new ArgParser(args); + } + + @Test(groups = "Functional", dataProvider = "argSubValsAndLinkedIds") + public void parseSubValsAndLinkedIdsTest(String commandLineArgs, + String linkedId, Arg a, String subvalKey, String value, + boolean trueOrFalse) + { + String[] args = commandLineArgs.split("\\s+"); + ArgParser argparser = new ArgParser(args); + ArgValuesMap avm = argparser.linkedArgs(linkedId); + ArgValue av = avm.getArgValue(a); + SubVals sv = av.getSubVals(); + String testString = null; + if (subvalKey.equals("GETINDEX")) + { + testString = String.valueOf(sv.getIndex()); + } + else + { + testString = sv.get(subvalKey); + } + if (trueOrFalse) + { + Assert.assertEquals(testString, value); + } + else + { + Assert.assertNotEquals(testString, value); + } + } + + @Test( + groups = "Functional", + dataProvider = "argAutoIndexAndSubstitutions") + public void parseAutoIndexAndSubstitutionsTest(String commandLineArgs, + String linkedId, Arg a, String filename) + { + // { "--open=filename0 --increment --open=filename1", "JALVIEW:1", Arg.OPEN, + // "filename1" }, + String[] args = commandLineArgs.split("\\s+"); + ArgParser argparser = new ArgParser(args); + ArgValuesMap avm = argparser.linkedArgs(linkedId); + ArgValue av = avm.getArgValue(a); + Assert.assertEquals(av.getValue(), filename); + } + + @Test(groups = "Functional", dataProvider = "argLines") + public void bootstrapArgsTest(String commandLineArgs, Arg a, String other) + { + String[] args = commandLineArgs.split("\\s+"); + BootstrapArgs b = BootstrapArgs.getBootstrapArgs(args); + + Assert.assertTrue(b.contains(a)); + if (a == Arg.PROPS) + { + Properties bP = Cache.bootstrapProperties(b.get(Arg.PROPS)); + 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); + boolean found = false; + for (String s : filenames) + { + File f = new File(s); + File fo = new File(other); + try + { + if (fo.getCanonicalPath().equals(f.getCanonicalPath())) + { + found = true; + break; + } + } catch (IOException e) + { + } + } + Assert.assertTrue(found, + "File '" + other + "' not found in shell expanded glob '" + + commandLineArgs + "'"); + } + } + + @Test(groups = "Functional", dataProvider = "argFiles") + public void argFilesTest(String commandLineArgs, Arg a, String other) + { + String[] args = commandLineArgs.split("\\s+"); + BootstrapArgs b = BootstrapArgs.getBootstrapArgs(args); + + Assert.assertTrue(b.contains(a)); + Assert.assertFalse(b.contains(Arg.OPEN)); + if (a == Arg.PROPS) + { + Properties bP = Cache.bootstrapProperties(b.get(Arg.PROPS)); + Assert.assertTrue("true".equals(bP.get(Cache.BOOTSTRAP_TEST))); + } + } + + @DataProvider(name = "argLinesNotworking") + public Object[][] argLinesTest() + { + return new Object[][] { + // can't use this one yet as it doesn't get shell glob expanded by the + // test + { "--argfile test/jalview/bin/argparser/testfiles/argfile*.txt", + Arg.ARGFILE, + "test/jalview/bin/argparser/testfiles/argfile0.txt" }, }; + } + + @DataProvider(name = "argLines") + public Object[][] argLines() + { + return new Object[][] { + { "--debug --open=test/jalview/bin/argparser/testfiles/test1.fa", + Arg.DEBUG, null }, + { "--open=test/jalview/bin/argparser/testfiles/test1.fa --headless", + Arg.HEADLESS, null }, + { "--open=test/jalview/bin/argparser/testfiles/test1.fa --props=test/jalview/bin/argparser/testfiles/testProps.jvprops", + Arg.PROPS, "true" }, + { "--argfile test/jalview/bin/argparser/testfiles/argfile0.txt", + Arg.ARGFILE, + "test/jalview/bin/argparser/testfiles/argfile0.txt" }, + // these next three are what a shell glob expansion would look like + { "--argfile test/jalview/bin/argparser/testfiles/argfile0.txt test/jalview/bin/argparser/testfiles/argfile1.txt test/jalview/bin/argparser/testfiles/argfile2.txt", + Arg.ARGFILE, + "test/jalview/bin/argparser/testfiles/argfile0.txt" }, + { "--argfile test/jalview/bin/argparser/testfiles/argfile0.txt test/jalview/bin/argparser/testfiles/argfile1.txt test/jalview/bin/argparser/testfiles/argfile2.txt", + Arg.ARGFILE, + "test/jalview/bin/argparser/testfiles/argfile1.txt" }, + { "--argfile test/jalview/bin/argparser/testfiles/argfile0.txt test/jalview/bin/argparser/testfiles/argfile1.txt test/jalview/bin/argparser/testfiles/argfile2.txt", + Arg.ARGFILE, + "test/jalview/bin/argparser/testfiles/argfile2.txt" }, + { "--argfile=test/jalview/bin/argparser/testfiles/argfile*.txt", + Arg.ARGFILE, + "test/jalview/bin/argparser/testfiles/argfile0.txt" }, + { "--argfile=test/jalview/bin/argparser/testfiles/argfile*.txt", + Arg.ARGFILE, + "test/jalview/bin/argparser/testfiles/argfile1.txt" }, + { "--argfile=test/jalview/bin/argparser/testfiles/argfile*.txt", + Arg.ARGFILE, + "test/jalview/bin/argparser/testfiles/argfile2.txt" } }; + } + + @DataProvider(name = "argSubValsAndLinkedIds") + public Object[][] argSubValsAndLinkedIds() + { + return new Object[][] { { + "--debug --open=[hi]test/jalview/bin/argparser/testfiles/test1.fa", + "JALVIEW:0", Arg.OPEN, "hi", "true", true }, + { "--open[linkedId1]=[new;hello=world;1]test/jalview/bin/argparser/testfiles/test1.fa --headless", + "linkedId1", Arg.OPEN, "new", "true", true }, + { "--open[linkedId2]=[new;hello=world;1]test/jalview/bin/argparser/testfiles/test1.fa --headless", + "linkedId2", Arg.OPEN, "hello", "world", true }, + { "--open[linkedId3]=[new;hello=world;1]test/jalview/bin/argparser/testfiles/test1.fa --headless", + "linkedId3", Arg.OPEN, "GETINDEX", "1", true }, + { "--open[linkedId4]=[new;hello=world;1]test/jalview/bin/argparser/testfiles/test1.fa --open[linkedId5]=[notnew;hello=world;1]test/jalview/bin/argparser/testfiles/test1.fa --headless", + "linkedId5", Arg.OPEN, "new", "true", false }, + { "--open[linkedId5]=[new;hello=worlddomination;1]test/jalview/bin/argparser/testfiles/test1.fa --open[linkedId2]=[new;hello=world;1]test/jalview/bin/argparser/testfiles/test1.fa --headless", + "linkedId5", Arg.OPEN, "hello", "world", false }, + { "--open[linkedId6]=[new;hello=world;0]test/jalview/bin/argparser/testfiles/test1.fa --open[linkedId7]=[new;hello=world;1]test/jalview/bin/argparser/testfiles/test1.fa --headless", + "linkedId7", Arg.OPEN, "GETINDEX", "0", false }, }; + } + + @DataProvider(name = "argAutoIndexAndSubstitutions") + public Object[][] argAutoIndexAndSubstitutions() + { + return new Object[][] { { "--open=filename0 --open=filename1", + "JALVIEW:0", Arg.OPEN, "filename0" }, + { "--open=filename0 --increment --open=filename1", "JALVIEW:1", + Arg.OPEN, "filename1" }, + { "--open=filename0 --increment --increment --open=filename2", + "JALVIEW:0", Arg.OPEN, "filename0" }, + { "--open=filename0 --increment --increment --open=filename2", + "JALVIEW:2", Arg.OPEN, "filename2" }, + { "--open[linkA-{n}]=filenameA0 --open[linkA-{++n}]=filenameA1", + "linkA-0", Arg.OPEN, "filenameA0" }, + { "--open[linkB-{n}]=filenameB0 --open[linkB-{++n}]=filenameB1", + "linkB-1", Arg.OPEN, "filenameB1" }, + { "--open[linkC-{n}]=filenameC0 --image[linkC-{n}]=outputC{n}.txt", + "linkC-0", Arg.IMAGE, "outputC{n}.txt" }, + { "--open[linkD-{n}]=filenameD0 --substitutions --image[linkD-{n}]=outputD{n}.txt", + "linkD-0", Arg.IMAGE, "outputD0.txt" }, + { "--open[linkE-{n}]=filenameE0 --substitutions --image[linkE-{n}]=output-E{n}.txt --nil[{++n}] --image[linkE-{n}]=outputE{n}.txt", + "linkE-0", Arg.IMAGE, "output-E0.txt" }, + { "--open[linkF-{n}]=filenameF0 --substitutions --image[linkF-{n}]=output-F{n}.txt --nil[{++n}] --image[linkF-{n}]=outputF{n}.txt", + "linkF-1", Arg.IMAGE, "outputF1.txt" }, + { "--open[linkG-{n}]=filenameG0 --substitutions --image[linkG-{n}]=output-G{n}.txt --nil[{++n}] --nosubstitutions --image[linkG-{n}]=outputG{n}.txt", + "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" }, }; + } + + @DataProvider(name = "argFiles") + public Object[][] argFiles() + { + return new Object[][] { { + "--argfile=test/jalview/bin/argparser/testfiles/argfile0.txt --open=shouldntbeabootstrap", + Arg.ARGFILE, "test/jalview/bin/argfiles/testfiles/test1.fa" } }; + } +} diff --git a/test/jalview/bin/argparser/argfile.autocounter b/test/jalview/bin/argparser/testfiles/argfile.autocounter similarity index 100% rename from test/jalview/bin/argparser/argfile.autocounter rename to test/jalview/bin/argparser/testfiles/argfile.autocounter diff --git a/test/jalview/bin/argparser/argfile0.txt b/test/jalview/bin/argparser/testfiles/argfile0.txt similarity index 100% rename from test/jalview/bin/argparser/argfile0.txt rename to test/jalview/bin/argparser/testfiles/argfile0.txt diff --git a/test/jalview/bin/argparser/argfile1.txt b/test/jalview/bin/argparser/testfiles/argfile1.txt similarity index 100% rename from test/jalview/bin/argparser/argfile1.txt rename to test/jalview/bin/argparser/testfiles/argfile1.txt diff --git a/test/jalview/bin/argparser/argfile2.txt b/test/jalview/bin/argparser/testfiles/argfile2.txt similarity index 100% rename from test/jalview/bin/argparser/argfile2.txt rename to test/jalview/bin/argparser/testfiles/argfile2.txt diff --git a/test/jalview/bin/argparser/test1.fa b/test/jalview/bin/argparser/testfiles/test1.fa similarity index 100% rename from test/jalview/bin/argparser/test1.fa rename to test/jalview/bin/argparser/testfiles/test1.fa diff --git a/test/jalview/bin/argparser/test2.fa b/test/jalview/bin/argparser/testfiles/test2.fa similarity index 100% rename from test/jalview/bin/argparser/test2.fa rename to test/jalview/bin/argparser/testfiles/test2.fa diff --git a/test/jalview/bin/argparser/test3.fa b/test/jalview/bin/argparser/testfiles/test3.fa similarity index 100% rename from test/jalview/bin/argparser/test3.fa rename to test/jalview/bin/argparser/testfiles/test3.fa diff --git a/test/jalview/bin/argparser/testProps.jvprops b/test/jalview/bin/argparser/testfiles/testProps.jvprops similarity index 100% rename from test/jalview/bin/argparser/testProps.jvprops rename to test/jalview/bin/argparser/testfiles/testProps.jvprops