From 0c97b70b61d6d02ce932d04a1621d2961db77c16 Mon Sep 17 00:00:00 2001 From: Ben Soares Date: Thu, 30 Mar 2023 16:25:58 +0100 Subject: [PATCH] JAL-629 More extensive tests with real files being opened --- src/jalview/util/ArrayUtils.java | 25 ++ test/jalview/bin/CommandsTest.java | 83 +++-- .../bin/argparser/testfiles/argfile.autocounter | 8 +- test/jalview/bin/argparser/testfiles/argfile0.txt | 4 +- test/jalview/bin/argparser/testfiles/argfile1.txt | 8 +- test/jalview/bin/argparser/testfiles/argfile2.txt | 2 +- test/jalview/bin/argparser/testfiles/test3.fa | 2 +- test/jalview/bin/test_uniref50_out.html | 384 ++++++++++++++++++++ 8 files changed, 479 insertions(+), 37 deletions(-) create mode 100644 test/jalview/bin/test_uniref50_out.html diff --git a/src/jalview/util/ArrayUtils.java b/src/jalview/util/ArrayUtils.java index c05dac5..8142f8a 100644 --- a/src/jalview/util/ArrayUtils.java +++ b/src/jalview/util/ArrayUtils.java @@ -20,6 +20,8 @@ */ package jalview.util; +import java.util.Arrays; + public class ArrayUtils { /** @@ -44,4 +46,27 @@ public class ArrayUtils } } } + + public static T[] concatArrays(T[]... arrays) + { + if (arrays == null) + return null; + if (arrays.length == 1) + return arrays[0]; + + T[] result = arrays[0]; + for (int i = 1; i < arrays.length; i++) + { + result = concatTwoArrays(result, arrays[i]); + } + return result; + } + + private static T[] concatTwoArrays(T[] array1, T[] array2) + { + T[] result = Arrays.copyOf(array1, array1.length + array2.length); + System.arraycopy(array2, 0, result, array1.length, array2.length); + return result; + } + } diff --git a/test/jalview/bin/CommandsTest.java b/test/jalview/bin/CommandsTest.java index 204714f..b37c6e3 100644 --- a/test/jalview/bin/CommandsTest.java +++ b/test/jalview/bin/CommandsTest.java @@ -1,6 +1,8 @@ package jalview.bin; import java.util.Date; +import java.util.HashSet; +import java.util.Set; import org.testng.Assert; import org.testng.annotations.AfterClass; @@ -12,6 +14,7 @@ import org.testng.annotations.Test; import jalview.gui.AlignFrame; import jalview.gui.Desktop; import jalview.gui.JvOptionPane; +import jalview.util.ArrayUtils; @Test(singleThreaded = true) public class CommandsTest @@ -46,24 +49,71 @@ public class CommandsTest } @Test(groups = "Functional", dataProvider = "cmdLines") - public void commandsOpenTest(String cmdLine, String sequence) + public void commandsOpenTest(String cmdLine, boolean cmdArgs, + int numFrames, String[] sequences) { String[] args = cmdLine.split("\\s+"); Jalview.main(args); Commands cmds = Jalview.getInstance().getCommands(); Assert.assertNotNull(cmds); - Assert.assertTrue(cmds.commandArgsProvided(), + Assert.assertEquals(cmds.commandArgsProvided(), cmdArgs, "Commands were not provided in the args"); - Assert.assertTrue(cmds.argsWereParsed(), + Assert.assertEquals(cmds.argsWereParsed(), cmdArgs, "Overall command parse and operation is false"); - if (sequence != null) + Assert.assertEquals(Desktop.getAlignFrames().length, numFrames); + + if (sequences != null) { - Assert.assertTrue(lookForSequenceName(sequence), - "Sequence '" + sequence - + "' was not found in opened alignment files: " - + cmdLine); + Set openedSequenceNames = new HashSet<>(); + AlignFrame[] afs = Desktop.getAlignFrames(); + for (AlignFrame af : afs) + { + openedSequenceNames + .addAll(af.getViewport().getAlignment().getSequenceNames()); + } + for (String sequence : sequences) + { + Assert.assertTrue(openedSequenceNames.contains(sequence), + "Sequence '" + sequence + + "' was not found in opened alignment files: " + + cmdLine + ".\nOpened sequence names are:\n" + + String.join("\n", openedSequenceNames)); + } } + + Assert.assertFalse( + lookForSequenceName("THIS_SEQUENCE_ID_DOESN'T_EXIST")); + } + + @DataProvider(name = "cmdLines") + public Object[][] cmdLines() + { + String[] someUniref50Seqs = new String[] { "FER_CAPAA", "FER_CAPAN", + "FER1_MAIZE", "FER1_SPIOL", "O80429_MAIZE" }; + String[] t1 = new String[] { "TEST1" }; + String[] t2 = new String[] { "TEST2" }; + String[] t3 = new String[] { "TEST3" }; + return new Object[][] { + { "--open=examples/uniref50.fa", true, 1, someUniref50Seqs }, + { "--open examples/uniref50.fa", true, 1, someUniref50Seqs }, + { "--open=examples/uniref50*.fa", true, 1, someUniref50Seqs }, + // NOTE we cannot use shell expansion in tests, so list all files! + { "--open examples/uniref50.fa examples/uniref50_mz.fa", true, 1, + someUniref50Seqs }, + { "--open=[new]examples/uniref50*.fa", true, 2, someUniref50Seqs }, + { "--opennew=examples/uniref50*.fa", true, 2, someUniref50Seqs }, + { "examples/uniref50.fa", true, 1, someUniref50Seqs }, + { "examples/uniref50.fa test/jalview/bin/argparser/testfiles/test1.fa", + true, 2, ArrayUtils.concatArrays(someUniref50Seqs, t1) }, + { "examples/uniref50.fa test/jalview/bin/argparser/testfiles/test1.fa", + true, 2, t1 }, + { "--argfile=test/jalview/bin/argparser/testfiles/argfile0.txt", + true, 1, ArrayUtils.concatArrays(t1, t3) }, + { "--argfile=test/jalview/bin/argparser/testfiles/argfile*.txt", + true, 4, ArrayUtils.concatArrays(t1, t2, t3) }, + { "--argfile=test/jalview/bin/argparser/testfiles/argfile.autocounter", + true, 3, ArrayUtils.concatArrays(t1, t2) } }; } public static boolean lookForSequenceName(String sequenceName) @@ -82,21 +132,4 @@ public class CommandsTest return false; } - @DataProvider(name = "cmdLines") - public Object[][] cmdLines() - { - 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/testfiles/argfile.autocounter b/test/jalview/bin/argparser/testfiles/argfile.autocounter index bbf3776..7eaf95e 100644 --- a/test/jalview/bin/argparser/testfiles/argfile.autocounter +++ b/test/jalview/bin/argparser/testfiles/argfile.autocounter @@ -1,7 +1,7 @@ ---open[{++n}]=test/jalview/bin/argparser/test1.fa +--open[{++n}]=test/jalview/bin/argparser/testfiles/test1.fa --colour[{n}]=gecos:flower ---open[{++n}]=test/jalview/bin/argparser/test2.fa +--open[{++n}]=test/jalview/bin/argparser/testfiles/test2.fa --colour[{n}]=zappo ---open[{++n}]=test/jalview/bin/argparser/test1.fa ---open[{n}]=test/jalview/bin/argparser/test2.fa +--open[{++n}]=test/jalview/bin/argparser/testfiles/test1.fa +--open[{n}]=test/jalview/bin/argparser/testfiles/test2.fa --colour[{n}]=taylor diff --git a/test/jalview/bin/argparser/testfiles/argfile0.txt b/test/jalview/bin/argparser/testfiles/argfile0.txt index b27ceab..6e5185e 100644 --- a/test/jalview/bin/argparser/testfiles/argfile0.txt +++ b/test/jalview/bin/argparser/testfiles/argfile0.txt @@ -1,2 +1,2 @@ ---open=test/jalview/bin/argparser/test1.fa ---open=test/jalview/bin/argparser/test3.fa +--open=test/jalview/bin/argparser/testfiles/test1.fa +--open=test/jalview/bin/argparser/testfiles/test3.fa diff --git a/test/jalview/bin/argparser/testfiles/argfile1.txt b/test/jalview/bin/argparser/testfiles/argfile1.txt index 4164fb5..bb33f21 100644 --- a/test/jalview/bin/argparser/testfiles/argfile1.txt +++ b/test/jalview/bin/argparser/testfiles/argfile1.txt @@ -1,4 +1,4 @@ ---open[all]=test/jalview/bin/argparser/test1.fa ---open[all]=test/jalview/bin/argparser/test2.fa ---open[1]=test/jalview/bin/argparser/test1.fa ---open[2]=test/jalview/bin/argparser/test2.fa +--open[all]=test/jalview/bin/argparser/testfiles/test1.fa +--open[all]=test/jalview/bin/argparser/testfiles/test2.fa +--open[1]=test/jalview/bin/argparser/testfiles/test1.fa +--open[2]=test/jalview/bin/argparser/testfiles/test2.fa diff --git a/test/jalview/bin/argparser/testfiles/argfile2.txt b/test/jalview/bin/argparser/testfiles/argfile2.txt index e08a1dc..85ce3c2 100644 --- a/test/jalview/bin/argparser/testfiles/argfile2.txt +++ b/test/jalview/bin/argparser/testfiles/argfile2.txt @@ -1 +1 @@ ---open=test/jalview/bin/argparser/test2.fa +--open=test/jalview/bin/argparser/testfiles/test2.fa diff --git a/test/jalview/bin/argparser/testfiles/test3.fa b/test/jalview/bin/argparser/testfiles/test3.fa index ea05599..f9503d4 100644 --- a/test/jalview/bin/argparser/testfiles/test3.fa +++ b/test/jalview/bin/argparser/testfiles/test3.fa @@ -1,2 +1,2 @@ ->TEST2 +>TEST3 AAARG diff --git a/test/jalview/bin/test_uniref50_out.html b/test/jalview/bin/test_uniref50_out.html new file mode 100644 index 0000000..03b47e5 --- /dev/null +++ b/test/jalview/bin/test_uniref50_out.html @@ -0,0 +1,384 @@ + +  
  +
+
+ + + + +FER_CAPAA/1-97FER_CAPAN/1-144FER1_SOLLC/1-144Q93XJ9_SOLTU/1-144FER1_PEA/1-149Q7XA98_TRIPR/1-152FER1_MESCR/1-148FER1_SPIOL/1-147FER3_RAPSA/1-96FER2_ARATH/1-148FER_BRANA/1-96FER1_ARATH/1-148Q93Z60_ARATH/1-118FER1_MAIZE/1-150O80429_MAIZE/1-140ConservationQualityConsensus +
+ + + +
+ + + +102030405060708090100110120130140150-----------------------------------------------------------ASYKVKLITPDGPIEFDCPDDVYILDQAEEAGHDLPYSCRAGSCSSCAGKIAGGAVDQTDGNFLDDDQLEEGWVLTCVAYPQSDVTIETHKEAELVG-MA------SVSATMISTSFMPRKPAVTSL-KPIPNVGE--ALFGLKS-A--NGGKVTCMASYKVKLITPDGPIEFDCPDNVYILDQAEEAGHDLPYSCRAGSCSSCAGKIAGGAVDQTDGNFLDDDQLEEGWVLTCVAYPQSDVTIETHKEAELVG-MA------SISGTMISTSFLPRKPAVTSL-KAISNVGE--ALFGLKS-G--RNGRITCMASYKVKLITPEGPIEFECPDDVYILDQAEEEGHDLPYSCRAGSCSSCAGKVTAGSVDQSDGNFLDEDQEAAGFVLTCVAYPKGDVTIETHKEEELTA-MA------SISGTMISTSFLPRKPVVTSL-KAISNVGE--ALFGLKS-G--RNGRITCMASYKVKLITPDGPIEFECPDDVYILDQAEEEGHDLPYSCRAGSCSSCAGKVTAGTVDQSDGKFLDDDQEAAGFVLTCVAYPKCDVTIETHKEEELTA-MATT---PALYGTAVSTSFLRTQPMPMSV-TTTKAFSN--GFLGLKT-SLKRGDLAVAMASYKVKLVTPDGTQEFECPSDVYILDHAEEVGIDLPYSCRAGSCSSCAGKVVGGEVDQSDGSFLDDEQIEAGFVLTCVAYPTSDVVIETHKEEDLTA-MATT---PALYGTAVSTSFMRRQPVPMSV-ATTTTTKAFPSGFGLKSVSTKRGDLAVAMATYKVKLITPEGPQEFDCPDDVYILDHAEEVGIELPYSCRAGSCSSCAGKVVNGNVNQEDGSFLDDEQIEGGWVLTCVAFPTSDVTIETHKEEELTA-MAAT--TAALSGATMSTAFAPK--TPPMTAALPTNVGR--ALFGLKS-SASR-GRVTAMAAYKVTLVTPEGKQELECPDDVYILDAAEEAGIDLPYSCRAGSCSSCAGKVTSGSVNQDDGSFLDDDQIKEGWVLTCVAYPTGDVTIETHKEEELTA-MAAT--TTTMMG--MATTFVPKPQAPPMMAALPSNTGR--SLFGLKT-GSR--GGRMTMAAYKVTLVTPTGNVEFQCPDDVYILDAAEEEGIDLPYSCRAGSCSSCAGKLKTGSLNQDDQSFLDDDQIDEGWVLTCAAYPVSDVTIETHKEEELTA------------------------------------------------------------ATYKVKFITPEGEQEVECDDDVYVLDAAEEAGIDLPYSCRAGSCSSCAGKVVSGSVDQSDQSFLDDDQIAEGFVLTCAAYPTSDVTIETHREEDMV--MAST----ALSSAIVGTSFIRRSPAPISLRSLPSANTQ--SLFGLKS-GTARGGRVTAMATYKVKFITPEGELEVECDDDVYVLDAAEEAGIDLPYSCRAGSCSSCAGKVVSGSVDQSDQSFLDDEQIGEGFVLTCAAYPTSDVTIETHKEEDIV-------------------------------------------------------------ATYKVKFITPEGEQEVECDDDVYVLDAAEEAGIDLPYSCRAGSCSSCAGKVVSGFVDQSDESFLDDDQIAEGFVLTCAAYPTSDVTIETHKEEELV--MAST----ALSSAIVSTSFLRRQQTPISLRSLPFANTQ--SLFGLKS-STARGGRVTAMATYKVKFITPEGEQEVECEEDVYVLDAAEEAGLDLPYSCRAGSCSSCAGKVVSGSIDQSDQSFLDDEQMSEGYVLTCVAYPTSDVVIETHKEEAIM--MAST----ALSSAIVSTSFLRRQQTPISLRSLPFANTQ--SLFGLKS-STARGGRVTAMATYKVKFITPEGEQEVECEEDVYVLDAAEEAGLDLPYSCRAGSCSSCAGKVVSGSIDQSDQSFLDD--------------------------------MATVLGSPRAPAFFFSSSSLRAAPAPTAV--ALPAAKV--GIMGRSA-SSRR--RLRAQATYNVKLITPEGEVELQVPDDVYILDQAEEDGIDLPYSCRAGSCSSCAGKVVSGSVDQSDQSYLDDGQIADGWVLTCHAYPTSDVVIETHKEEELTGAMAAT---------ALSMSILR---APPPCFSSPLRLRV--AVAKPLA-APMRRQLLRAQATYNVKLITPEGEVELQVPDDVYILDFAEEEGIDLPFSCRAGSCSSCAGKVVSGSVDQSDQSFLNDNQVADGWVLTCAAYPTSDVVIETHKEDDLL--13------------1201010---11001--0000000--2111001-2-----00020*7*6*789**6*36*779568**9**3***3*59**9*************947*398*5*459*89010003232321322014322335330011-- MA+TLGTPALSGT+VSTSFLRRQPAPTSLRSLPS+VG+FP+LFGLKSVSTARGGRVTAMATYKVKLITPEGEQEFECPDDVYILDAAEEAGIDLPYSCRAGSCSSCAGKVVSGSVDQSD+SFLDDDQIAEGWVLTCVAYPTSDVTIETHKEEELTAA +
+ + + + \ No newline at end of file -- 1.7.10.2