<commit_before>/*
  Copyright (C) 2003 EBI, GRL
 
  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation; either
  version 2.1 of the License, or (at your option) any later version.
 
  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  Lesser General Public License for more details.
 
  You should have received a copy of the GNU Lesser General Public
  License along with this library; if not, write to the Free Software
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

package org.ensembl.healthcheck.testcase;

import java.io.*;
import java.util.*;
import java.sql.*;
import java.util.logging.*;

import org.ensembl.healthcheck.*;

import org.ensembl.healthcheck.util.*;

/**
 * <p>The EnsTestCase class is the base class for all test cases in the EnsEMBL Healthcheck system.
 * <em>It is not intended to be instantiated directly</em>; subclasses should implement the <code>run()</code>
 * method and use that to provide test-case specific behaviour.</p>
 *
 *<p>EnsTestCase provides a number of methods which are intended to make writing test cases simple; in many cases
 * an extension test case will involve little more than calling one of the methods in this class and
 * setting some return value based on the result.</p>
 *
 * <p>For example, the following test case gets a {@link org.ensembl.healthcheck.util.DatabaseConnectionIterator DatabaseConnectionIterator}, then uses it to loop over each
 * affected database and call the <code>countOrphans()</code> method in EnsTestCase. In this particular situation,
 * if there are any orphans in any of the databases, the test fails.</p>
 * <pre>
 * public class OrphanTestCase extends EnsTestCase {
 *
 *   public OrphanTestCase() {
 *     databaseRegexp = "^homo_sapiens_core_\\d.*";
 *     addToGroup("group2");
 *   }
 *
 *  TestResult run() {
 *
 *     boolean result = true;
 *
 *     DatabaseConnectionIterator it = getDatabaseConnectionIterator();
 *
 *     while (it.hasNext()) {
 *
 *       Connection con = (Connection)it.next();
 *       int orphans = super.countOrphans(con, "gene", "gene_id", "gene_stable_id", "gene_id", false);
 *       result &= (orphans == 0);
 *
 *     }
 *
 *     return new TestResult(getShortTestName(), result, "");
 *
 *   }
 *
 * } // OrphanTestCase
 * </pre>
 *
 * <p>Most test cases you write will take this form:</p>
 * <ol>
 * <li>Set up the database regexp and any groups that this test case is a member of; Note that all tests by
 * default are members of a group called "all". There is no need to explicitly add your new test to this group.</li>
 * <li>Implement the run() method; normally this will involve getting a DatabaseConnectionIterator,
 * calling one or more superclass methods on each database connection.</li>
 * <li>Create and return a TestResult object according to the results of your tests.</li>
 * </ol>
 *
 *
 */

public abstract class EnsTestCase {
  
  /** Regexp that, when combined with a species name, will match core databases */
  protected static final String CORE_DB_REGEXP = "\\w+_\\w+_(core|est|estgene|vega)_\\d+_.*";
  protected static final String CORE_DB_REGEXP_POSTFIX = "_(core|est|estgene|vega)_\\d+_.*";
  /** The TestRunner associated with this EnsTestCase */
  protected TestRunner testRunner;
  /** The regular expression to match the names of the databases that the test case will apply to. */
  protected String databaseRegexp = CORE_DB_REGEXP;
  /** If set, this is applied to the database names before databaseRegexp. */
  protected String preFilterRegexp = "";
  /** A list of Strings representing the groups that this test is a member of.
   * All tests are members of the group "all", and also of a group with the same name as the test. */
  protected List groups;
  /** Each test has a set of conditions that it needs to be fulfilled in order for it to run */
  protected List conditions;
  
  /** Description field */
  protected String description;
  
  /** Logger object to use */
  protected static Logger logger = Logger.getLogger("HealthCheckLogger");
  
  /** Boolean variable that can be set if the test case is likely to take a long time to run */
  protected boolean hintLongRunning = false;
  
  // -------------------------------------------------------------------------
  /**
   * Creates a new instance of EnsTestCase
   */
  public EnsTestCase() {
    
    groups = new ArrayList();
    addToGroup("all");               // everything is in all, by default
    addToGroup(getShortTestName());  // each test is in a one-test group<commit_msg>changed default regexp so that it excludes homo_sapiens_est_expression_ style databases<commit_after>/*
  Copyright (C) 2003 EBI, GRL
 
  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation; either
  version 2.1 of the License, or (at your option) any later version.
 
  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  Lesser General Public License for more details.
 
  You should have received a copy of the GNU Lesser General Public
  License along with this library; if not, write to the Free Software
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

package org.ensembl.healthcheck.testcase;

import java.io.*;
import java.util.*;
import java.sql.*;
import java.util.logging.*;

import org.ensembl.healthcheck.*;

import org.ensembl.healthcheck.util.*;

/**
 * <p>The EnsTestCase class is the base class for all test cases in the EnsEMBL Healthcheck system.
 * <em>It is not intended to be instantiated directly</em>; subclasses should implement the <code>run()</code>
 * method and use that to provide test-case specific behaviour.</p>
 *
 *<p>EnsTestCase provides a number of methods which are intended to make writing test cases simple; in many cases
 * an extension test case will involve little more than calling one of the methods in this class and
 * setting some return value based on the result.</p>
 *
 * <p>For example, the following test case gets a {@link org.ensembl.healthcheck.util.DatabaseConnectionIterator DatabaseConnectionIterator}, then uses it to loop over each
 * affected database and call the <code>countOrphans()</code> method in EnsTestCase. In this particular situation,
 * if there are any orphans in any of the databases, the test fails.</p>
 * <pre>
 * public class OrphanTestCase extends EnsTestCase {
 *
 *   public OrphanTestCase() {
 *     databaseRegexp = "^homo_sapiens_core_\\d.*";
 *     addToGroup("group2");
 *   }
 *
 *  TestResult run() {
 *
 *     boolean result = true;
 *
 *     DatabaseConnectionIterator it = getDatabaseConnectionIterator();
 *
 *     while (it.hasNext()) {
 *
 *       Connection con = (Connection)it.next();
 *       int orphans = super.countOrphans(con, "gene", "gene_id", "gene_stable_id", "gene_id", false);
 *       result &= (orphans == 0);
 *
 *     }
 *
 *     return new TestResult(getShortTestName(), result, "");
 *
 *   }
 *
 * } // OrphanTestCase
 * </pre>
 *
 * <p>Most test cases you write will take this form:</p>
 * <ol>
 * <li>Set up the database regexp and any groups that this test case is a member of; Note that all tests by
 * default are members of a group called "all". There is no need to explicitly add your new test to this group.</li>
 * <li>Implement the run() method; normally this will involve getting a DatabaseConnectionIterator,
 * calling one or more superclass methods on each database connection.</li>
 * <li>Create and return a TestResult object according to the results of your tests.</li>
 * </ol>
 *
 *
 */

public abstract class EnsTestCase {
  
  /** Regexp that, when combined with a species name, will match core databases */
  protected static final String CORE_DB_REGEXP = "[A-Za-z]+_[A-Za-z]+_(core|est|estgene|vega)_\\d+_\\d+[A-Za-z]?.*";
  protected static final String CORE_DB_REGEXP_POSTFIX = "_(core|est|estgene|vega)_\\d+_\\d+[A-Za-z]?.*";
  /** The TestRunner associated with this EnsTestCase */
  protected TestRunner testRunner;
  /** The regular expression to match the names of the databases that the test case will apply to. */
  protected String databaseRegexp = CORE_DB_REGEXP;
  /** If set, this is applied to the database names before databaseRegexp. */
  protected String preFilterRegexp = "";
  /** A list of Strings representing the groups that this test is a member of.
   * All tests are members of the group "all", and also of a group with the same name as the test. */
  protected List groups;
  /** Each test has a set of conditions that it needs to be fulfilled in order for it to run */
  protected List conditions;
  
  /** Description field */
  protected String description;
  
  /** Logger object to use */
  protected static Logger logger = Logger.getLogger("HealthCheckLogger");
  
  /** Boolean variable that can be set if the test case is likely to take a long time to run */
  protected boolean hintLongRunning = false;
  
  // -------------------------------------------------------------------------
  /**
   * Creates a new instance of EnsTestCase
   */
  public EnsTestCase() {
    
    groups = new ArrayList();
    addToGroup("all");               // everything is in all, by default
    addToGroup(getShortTestName());  // each test is in a one-test group
{'fraction_non_alphanumeric': 0.1061383699445699, 'fraction_numerical': 0.0045165263806199955, 'mean_word_length': 3.3495535714285714, 'pattern_counts': {'":': 0, '<': 51, '<?xml version=': 0, '>': 51, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5391420', 'n_tokens_mistral': 2697, 'n_tokens_neox': 2609, 'n_words': 1176}