JAL-4290 not quite working tests
authorBen Soares <b.soares@dundee.ac.uk>
Mon, 18 Dec 2023 13:58:28 +0000 (13:58 +0000)
committerBen Soares <b.soares@dundee.ac.uk>
Mon, 18 Dec 2023 13:58:28 +0000 (13:58 +0000)
test/jalview/bin/CommandsTest.java

index e42cc54..e6d69cd 100644 (file)
  */
 package jalview.bin;
 
+import java.awt.image.BufferedImage;
 import java.io.File;
 import java.io.IOException;
-import java.lang.reflect.InvocationTargetException;
 import java.nio.file.Files;
 import java.util.Date;
 import java.util.HashSet;
 import java.util.Set;
 
+import javax.imageio.ImageIO;
 import javax.swing.SwingUtilities;
 
 import org.testng.Assert;
@@ -93,7 +94,12 @@ public class CommandsTest
 
   public static void callJalviewMain(String[] args)
   {
-    if (Jalview.getInstance() != null)
+    callJalviewMain(args, false);
+  }
+
+  public static void callJalviewMain(String[] args, boolean newJalview)
+  {
+    if (!newJalview || Jalview.getInstance() != null)
     {
       Jalview.getInstance().doMain(args);
     }
@@ -116,7 +122,11 @@ public class CommandsTest
   }
   */
 
-  @Test(groups = { "Functional", "testTask3" }, dataProvider = "cmdLines", singleThreaded = true)
+  @Test(
+    groups =
+    { "Functional", "testTask3" },
+    dataProvider = "cmdLines",
+    singleThreaded = true)
 
   public void commandsOpenTest(String cmdLine, boolean cmdArgs,
           int numFrames, String[] sequences)
@@ -169,7 +179,8 @@ public class CommandsTest
   @Test(
     groups =
     { "Functional", "testTask3" },
-    dataProvider = "structureImageOutputFiles",    singleThreaded = true)
+    dataProvider = "structureImageOutputFiles",
+    singleThreaded = true)
   public void structureImageOutputTest(String cmdLine, String[] filenames)
           throws IOException
   {
@@ -193,7 +204,8 @@ public class CommandsTest
   }
 
   /**
-   * given two command lines, compare the output files produced - they should exist and be equal in size
+   * given two command lines, compare the output files produced - they should
+   * exist and be equal in size
    */
   @Test(
     groups =
@@ -208,12 +220,13 @@ public class CommandsTest
     {
       for (String cmdLine : cmdLines)
       {
-        CommandLineOperations.Worker runner = CommandLineOperations.getJalviewDesktopRunner(false, cmdLine, 1000);
+        CommandLineOperations.Worker runner = CommandLineOperations
+                .getJalviewDesktopRunner(false, cmdLine, 1000);
         long timeOut = 10000;
-        while (runner.isAlive() && timeOut>0)
+        while (runner.isAlive() && timeOut > 0)
         {
           Thread.sleep(25);
-          timeOut-=25;
+          timeOut -= 25;
         }
       }
       verifyOrderedFileSet(cmdLines[0] + " vs " + cmdLines[1], filenames,
@@ -228,6 +241,7 @@ public class CommandsTest
       tearDown();
     }
   }
+
   @DataProvider(name = "compareHeadlessAndGUIOps")
   public Object[][] compareHeadlessAndGUIOps()
   {
@@ -237,7 +251,8 @@ public class CommandsTest
                 + "--structure [seqid=FER1_SPIOL,tempfac=plddt,showssannotations,structureviewer=jmol]"
                 + "examples/AlphaFold/AF-P00221-F1-model_v4.pdb "
                 + "--paematrix examples/AlphaFold/AF-P00221-F1-predicted_aligned_error_v4.json --image="
-                + testfiles + "test-al-pae-ss-gui.png --overwrite --gui --quit",
+                + testfiles
+                + "test-al-pae-ss-gui.png --overwrite --gui --quit",
             "--open examples/uniref50.fa "
                     + "--structure [seqid=FER1_SPIOL,tempfac=plddt,showssannotations,structureviewer=jmol]"
                     + "examples/AlphaFold/AF-P00221-F1-model_v4.pdb "
@@ -245,19 +260,18 @@ public class CommandsTest
                     + testfiles
                     + "test-al-pae-ss-nogui.png --overwrite --nogui"
 
-        }, new String[] {
-            testfiles + "test-al-pae-ss-gui.png",
-            testfiles
-            + "test-al-pae-ss-nogui.png",
-        } } };
+        }, new String[] { testfiles + "test-al-pae-ss-gui.png",
+            testfiles + "test-al-pae-ss-nogui.png", } } };
   }
-  
-  private static void verifyIncreasingSize(String cmdLine, String[] filenames) throws Exception
+
+  private static void verifyIncreasingSize(String cmdLine,
+          String[] filenames) throws Exception
   {
     verifyOrderedFileSet(cmdLine, filenames, true);
   }
-  
-  private static void verifyOrderedFileSet(String cmdLine, String[] filenames, boolean increasingSize) throws Exception
+
+  private static void verifyOrderedFileSet(String cmdLine,
+          String[] filenames, boolean increasingSize) throws Exception
   {
     File lastFile = null;
     for (String filename : filenames)
@@ -272,14 +286,22 @@ public class CommandsTest
       // make sure the successive output files get bigger!
       if (lastFile != null)
       {
-        waitForLastWrite(file,25);
-        
+        waitForLastWrite(file, 25);
+
         if (increasingSize)
-        { Assert.assertTrue(Files.size(file.toPath()) > Files
-                .size(lastFile.toPath()),"Expected " + file.toPath()+ " to be larger than "+lastFile.toPath());
-        } else {
-          Assert.assertEquals(Files.size(file.toPath()), Files
-                .size(lastFile.toPath()), "New file "+file.toPath()+" (actual size) not same as last file's size "+lastFile.toString());
+        {
+          Assert.assertTrue(
+                  Files.size(file.toPath()) > Files.size(lastFile.toPath()),
+                  "Expected " + file.toPath() + " to be larger than "
+                          + lastFile.toPath());
+        }
+        else
+        {
+          Assert.assertEquals(Files.size(file.toPath()),
+                  Files.size(lastFile.toPath()),
+                  "New file " + file.toPath()
+                          + " (actual size) not same as last file's size "
+                          + lastFile.toString());
         }
       }
       // remember it for next file
@@ -287,21 +309,29 @@ public class CommandsTest
     }
 
   }
+
   private static long waitForLastWrite(File file, int i) throws IOException
   {
-    long lastSize,stableSize =Files.size(file.toPath());
+    long lastSize, stableSize = Files.size(file.toPath());
     // wait around until we are sure the file has been completely written.
-    do {
+    do
+    {
       lastSize = stableSize;
-      try {
+      try
+      {
         Thread.sleep(i);
-      } catch (Exception x) {}
-      stableSize=Files.size(file.toPath());
-    } while (stableSize!=lastSize);
+      } catch (Exception x)
+      {
+      }
+      stableSize = Files.size(file.toPath());
+    } while (stableSize != lastSize);
     return stableSize;
   }
 
-  @Test(groups = "Functional", dataProvider = "argfileOutputFiles", singleThreaded = true)
+  @Test(
+    groups = "Functional",
+    dataProvider = "argfileOutputFiles",
+    singleThreaded = true)
 
   public void argFilesGlobAndSubstitutionsTest(String cmdLine,
           String[] filenames) throws IOException
@@ -324,10 +354,13 @@ public class CommandsTest
         Assert.assertTrue(Files.size(file.toPath()) > 0, "File '" + filename
                 + "' has no content from '" + cmdLine + "'");
         // make sure the successive output files get bigger!
-        if (lastFile != null) {
+        if (lastFile != null)
+        {
           Assert.assertTrue(Files.size(file.toPath()) > Files
                   .size(lastFile.toPath()));
-          System.out.println("this file: "+file+" +"+Files.size(file.toPath()) + " greater than " +Files.size(lastFile.toPath()));
+          System.out.println("this file: " + file + " +"
+                  + Files.size(file.toPath()) + " greater than "
+                  + Files.size(lastFile.toPath()));
         }
         // remember it for next file
         lastFile = file;
@@ -379,18 +412,25 @@ public class CommandsTest
             { testfiles + "/structureimage1.png",
                 testfiles + "/structureimage2.png",
                 testfiles + "/structureimage3.png" } },
-        { "--gui --nonews --nosplash --open examples/1gaq.txt --append ./examples/3W5V.pdb "+"--structure examples/1gaq.txt --seqid \"1GAQ|A\" "+"--structureimage "+testfiles+"/1gaq.png --structure examples/3W5V.pdb "+"--seqid \"3W5V|A\" --structureimage "+testfiles+"/3w5v.png --overwrite",
-                       
-                new String[] {
-                               testfiles+"/1gaq.png",testfiles+"/3w5v.png"
-                }
-        },
-        { "--headless --noquit --open ./examples/1gaq.txt --append ./examples/3W5V.pdb "+"--structure examples/1gaq.txt --seqid \"1GAQ|A\" "+"--structureimage "+testfiles+"/1gaq.png --structure examples/3W5V.pdb "+"--seqid \"3W5V|A\" --structureimage "+testfiles+"/3w5v.png --overwrite",
-               
-            new String[] {
-                       testfiles+"/1gaq.png",testfiles+"/3w5v.png"
-            }
-    }
+        { "--gui --nonews --nosplash --open examples/1gaq.txt --append ./examples/3W5V.pdb "
+                + "--structure examples/1gaq.txt --seqid \"1GAQ|A\" "
+                + "--structureimage " + testfiles
+                + "/1gaq.png --structure examples/3W5V.pdb "
+                + "--seqid \"3W5V|A\" --structureimage " + testfiles
+                + "/3w5v.png --overwrite",
+
+            new String[]
+            { testfiles + "/1gaq.png",
+                testfiles + "/3w5v.png" } },
+        { "--headless --noquit --open ./examples/1gaq.txt --append ./examples/3W5V.pdb "
+                + "--structure examples/1gaq.txt --seqid \"1GAQ|A\" "
+                + "--structureimage " + testfiles
+                + "/1gaq.png --structure examples/3W5V.pdb "
+                + "--seqid \"3W5V|A\" --structureimage " + testfiles
+                + "/3w5v.png --overwrite",
+
+            new String[]
+            { testfiles + "/1gaq.png", testfiles + "/3w5v.png" } }
 
         /*
                 */
@@ -747,4 +787,98 @@ public class CommandsTest
     };
   }
 
+  @Test(
+    groups =
+    { "Functional", "testTask3" },
+    dataProvider = "structureImageAnnotationsOutputFiles",
+    singleThreaded = true)
+  public void structureImageAnnotationsOutputTest(String cmdLine,
+          String filename, int height) throws IOException
+  {
+    cleanupFiles(new String[] { filename });
+    String[] args = (cmdLine).split("\\s+");
+    callJalviewMain(args, true); // Create new instance of Jalview each time for
+                                 // linkedIds
+
+    BufferedImage img = ImageIO.read(new File(filename));
+    Assert.assertEquals(height, img.getHeight(), "Output image '" + filename
+            + "' is not in the expected height range, possibly because of the wrong number of annotations");
+
+    cleanupFiles(new String[] { filename });
+    tearDown();
+  }
+
+  @DataProvider(name = "structureImageAnnotationsOutputFiles")
+  public Object[][] structureImageAnnotationsOutputFiles()
+  {
+    String filename = "test/jalview/bin/argparser/testfiles/test_annotations.png";
+    return new Object[][] {
+        //
+        { "--headless --nonews --nosplash --overwrite --open=./examples/uniref50.fa "
+                + "--structure=examples/AlphaFold/AF-P00221-F1-model_v4.pdb "
+                + "--seqid=FER1_SPIOL --structureviewer=jmol "
+                + "--paematrix examples/AlphaFold/AF-P00221-F1-predicted_aligned_error_v4.json "
+                + "--image=" + filename + " " + "--tempfac=plddt "
+                + "--noshowssannotations " + "--noshowannotations", //
+            filename, //
+            252 }, //
+        { "--headless --nonews --nosplash --overwrite --open=./examples/uniref50.fa "
+                + "--structure=examples/AlphaFold/AF-P00221-F1-model_v4.pdb "
+                + "--seqid=FER1_SPIOL --structureviewer=jmol "
+                + "--paematrix examples/AlphaFold/AF-P00221-F1-predicted_aligned_error_v4.json "
+                + "--image=" + filename + " " + "--tempfac=plddt "
+                + "--showssannotations " + "--noshowannotations", //
+            filename, //
+            368 }, //
+        { "--headless --nonews --nosplash --overwrite --open=./examples/uniref50.fa "
+                + "--structure=examples/AlphaFold/AF-P00221-F1-model_v4.pdb "
+                + "--seqid=FER1_SPIOL --structureviewer=jmol "
+                + "--paematrix examples/AlphaFold/AF-P00221-F1-predicted_aligned_error_v4.json "
+                + "--image=" + filename + " " + "--tempfac=plddt "
+                + "--noshowssannotations " + "--showannotations", //
+            filename, //
+            524 }, //
+        { "--headless --nonews --nosplash --overwrite --open=./examples/uniref50.fa "
+                + "--structure=examples/AlphaFold/AF-P00221-F1-model_v4.pdb "
+                + "--seqid=FER1_SPIOL --structureviewer=jmol "
+                + "--paematrix examples/AlphaFold/AF-P00221-F1-predicted_aligned_error_v4.json "
+                + "--image=" + filename + " " + "--tempfac=plddt "
+                + "--showssannotations " + "--showannotations", //
+            filename, //
+            660 }, //
+        { "--gui --nonews --nosplash --overwrite --open=./examples/uniref50.fa "
+                + "--structure=examples/AlphaFold/AF-P00221-F1-model_v4.pdb "
+                + "--seqid=FER1_SPIOL --structureviewer=jmol "
+                + "--paematrix examples/AlphaFold/AF-P00221-F1-predicted_aligned_error_v4.json "
+                + "--image=" + filename + " " + "--tempfac=plddt "
+                + "--noshowssannotations " + "--noshowannotations", //
+            filename, //
+            252 }, //
+        { "--gui --nonews --nosplash --overwrite --open=./examples/uniref50.fa "
+                + "--structure=examples/AlphaFold/AF-P00221-F1-model_v4.pdb "
+                + "--seqid=FER1_SPIOL --structureviewer=jmol "
+                + "--paematrix examples/AlphaFold/AF-P00221-F1-predicted_aligned_error_v4.json "
+                + "--image=" + filename + " " + "--tempfac=plddt "
+                + "--showssannotations " + "--noshowannotations", //
+            filename, //
+            368 }, //
+        { "--gui --nonews --nosplash --overwrite --open=./examples/uniref50.fa "
+                + "--structure=examples/AlphaFold/AF-P00221-F1-model_v4.pdb "
+                + "--seqid=FER1_SPIOL --structureviewer=jmol "
+                + "--paematrix examples/AlphaFold/AF-P00221-F1-predicted_aligned_error_v4.json "
+                + "--image=" + filename + " " + "--tempfac=plddt "
+                + "--noshowssannotations " + "--showannotations", //
+            filename, //
+            524 }, //
+        { "--gui --nonews --nosplash --overwrite --open=./examples/uniref50.fa "
+                + "--structure=examples/AlphaFold/AF-P00221-F1-model_v4.pdb "
+                + "--seqid=FER1_SPIOL --structureviewer=jmol "
+                + "--paematrix examples/AlphaFold/AF-P00221-F1-predicted_aligned_error_v4.json "
+                + "--image=" + filename + " " + "--tempfac=plddt "
+                + "--showssannotations " + "--showannotations", //
+            filename, //
+            660 }, //
+    };
+  }
+
 }