Exemplo n.º 1
0
  def generate_test_cases(self, context_factory, parameterizations=None):
    """Creates the set of test cases that this test represents.

    The parameterizations argument should contain a parameterizations registry
    (keyed by parameterization name) containing values that are instances of
    a checkers.Parameterization class.

    Args:
      context_factory: Callable to create a context instance given a TestCase.
      parameterizations: (Registry) Parameterizations used to create test cases.

    Returns:
      list(TestCase): List of test cases (aka test closures).
    """
    test_cases = registry.AutoKeyRegistry(lambda tc: tc.full_name)
    if not parameterizations:
      test_case = TestCase(self, context_factory,
                           description=self.description)
      test_cases.register(test_case)
      return test_cases
    # It is a parameterized test, so we need to generate multiple test cases;
    # one for each parameterization.
    for suffix, param in parameterizations.iteritems():
      name = '%s_%s' % (self.name, suffix)
      full_name = '%s_%s' % (self.full_name, suffix)
      test_case = TestCase(self, context_factory, name=name,
                           full_name=full_name, description=self.description)
      for key, value in param.variables.iteritems():
        test_case.context.variables.register(key, value)
      for suite_name in param.suites:
        test_case.test_suites.register(TestSuite(suite_name))
      test_cases.register(test_case)
    return test_cases
Exemplo n.º 2
0
 def testSuite(self):
     suite= TestSuite()
     suite.add(WasRun("testMethod"))
     suite.add(WasRun("testBrokenMethod"))
     suite.run(self.result)
     assert("2 run, 1 failed" == self.result.summary())
     print('testSuite done')
Exemplo n.º 3
0
def main():
    """
    """
    # data = credit.dataset_31_credit_g()
    data = wine.wine_quality_red_csv()
    print(data.shape)
    print(data.columns)

    target = "class"
    X, y = data[[col for col in data.columns if col != target]], data[target]
    X_train, X_test, y_train, y_test = split(X,
                                             y,
                                             test_size=0.2,
                                             random_state=0)

    # pipeline = CreditGPipeline()
    pipeline = WineQualityPipeline()
    classifier = RandomForest(size=40)
    model = pipeline.with_estimator(classifier).fit(X_train, y_train)

    prediction = model.predict(X_test)
    print(accuracy_score(y_test, prediction))

    suite = TestSuite()
    automated_suite = AutomatedTestSuite()
    data_profile = DataFrameProfiler().on(X_train)
    pipeline_profile = SklearnPipelineProfiler().on(model)

    suite.add(Test().is_complete(
        data_profile.for_column('volatile_acidity')).is_in_range(
            data_profile.for_column('alcohol')))

    warnings = suite.on(X_test)

    print("*** TEST_SUITE, X_TEST")
    if warnings and (len(warnings) != 0):
        print("======= WARNINGS =======")
        for warn in warnings:
            print(warn)

    error_generator = ExplicitMissingValues()
    corrupted_X_test = error_generator.run(X_test, ['volatile_acidity'])

    warnings = suite.on(corrupted_X_test)

    print("*** TEST_SUITE, CORRUPTED_X_TEST")
    if warnings and (len(warnings) != 0):
        print("======= WARNINGS =======")
        for warn in warnings:
            print(warn)

    tests, warnings = (automated_suite.with_profiles(
        data_profile, pipeline_profile).run(corrupted_X_test))

    print("*** AUTOMATED_TEST_SUITE, CORRUPTED_X_TEST")
    if warnings and (len(warnings) != 0):
        print("======= WARNINGS =======")
        for warn in warnings:
            print(warn)
Exemplo n.º 4
0
 def LoadTestsFromModule(self, module, suite_name=None):
     suite_name = suite_name if suite_name else ''  # module.__name__
     suite_description = module.__doc__
     test_suite = TestSuite(suite_name, suite_description)
     for attr_name in dir(module):
         attr = getattr(module, attr_name)
         if isinstance(attr, TestCase):
             test_suite.AddTestCase(attr)
     self.LoadTestSuite(test_suite)
Exemplo n.º 5
0
    def run(self):
        testsuites = self.tfs.get_testsuites()

        self.__create_tfs_features_path(self.features_path)

        with open(self.features_path + '/sequence.featureset', 'w') as f:
            for testsuite in testsuites:
                ts = TestSuite(self.tfs, testsuite)
                new_filename = ts.write_feature_file(self.features_path)
                f.write(new_filename + '\n')

        f.close()
Exemplo n.º 6
0
 def discover(self, path):
     test_suite = TestSuite()
     for api_file in self.collect(path):
         test_case = TestCase(api_file)
         test_suite.add_case(test_case)
     return test_suite
Exemplo n.º 7
0
 def testSuiteContainsFailingSetup(self):
     suite = TestSuite()
     suite.add(BrokenSetup("testMethod"))
     suite.run(self.result)
     assert ("1 run, 1 failed" == self.result.summary())
Exemplo n.º 8
0
        suite = TestSuite()
        suite.add(BrokenSetup("testMethod"))
        suite.run(self.result)
        assert ("1 run, 1 failed" == self.result.summary())

    def testSuite(self):
        suite = TestSuite()
        suite.add(WasRun("testMethod"))
        suite.add(WasRun("testBrokenMethod"))
        suite.run(self.result)
        assert ("2 run, 1 failed" == self.result.summary())

    def tearDownIfFailed(self):
        test = WasRun("testBrokenMethod")
        test.run(self.result)


suite = TestSuite()
suite.add(TestCaseTest("testTemplateMethod"))
suite.add(TestCaseTest("testResult"))
suite.add(TestCaseTest("testFailedResultFormatting"))
suite.add(TestCaseTest("testFailedResult"))
suite.add(TestCaseTest("testSuite"))
suite.add(TestCaseTest("setupFailed"))
suite.add(TestCaseTest("testSuiteContainsFailingSetup"))
suite.add(TestCaseTest("tearDownIfFailed"))

result = TestResult()
suite.run(result)
print(result.summary())
Exemplo n.º 9
0
from test_suite import TestSuite

ts = TestSuite()
#ts.set_test_params(0, 'prince', 0, 2009, 1, 5, 10, 0)
ts.set_test_params(1, 'prince', 0, 2009, 3, 10, 10, 2)

ts.battery()
#ts.battery(0, 'prince', 2009, 20, 20, 10, 0)
Exemplo n.º 10
0
    with open(os.path.join(dir_path, "PaySim.properties")) as file:
        content = file.readlines()

    properties = dict()
    for line in content[1:]:
        pair = line.split("=")
        properties[pair[0]] = pair[1]

    #os.system("java -jar {jar_path}  -file PaySim.properties 1 off".format(jar_path=file_path))

    simulation_name = os.listdir(os.path.join(dir_path, "outputs"))[-1]
    rawLog = pd.read_csv(
        os.path.join(dir_path, "outputs", simulation_name,
                     "{}_rawLog.csv".format(simulation_name)))

    test_suite = TestSuite(rawLog, properties)
    for test in test_suite.tests:
        console_string = test(test_suite)
        nice_printing(console_string)

    template_path = os.path.join(os.path.dirname(os.path.abspath(__file__)),
                                 "templates")
    css_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "css")
    env = Environment(loader=FileSystemLoader(template_path))
    template = env.get_template("report.html")

    template.stream(test_suite.template_vars).dump("output.html")
    html_output = template.render(test_suite.template_vars)

    weasyprint.HTML(string=html_output).write_pdf(
        "report.pdf", stylesheets=[os.path.join(css_path, "typography.css")])
Exemplo n.º 11
0
 def setUp(self):
     self.result = TestResult()
     self.test = WasRun("testMethod")
     self.suite = TestSuite()
Exemplo n.º 12
0
 def CreateTestSuite(self, suite_name=None, suite_description=''):
     suite_name = suite_name if suite_name else TestRun._DEFAULT_SUITE_NAME
     if suite_name not in self.suites:
         self.suites[suite_name] = TestSuite(suite_name, suite_description)
Exemplo n.º 13
0
def main():
    dir = os.getcwd() + "/App/"
    net_assigned = False
    try:
        # Read testing arguments
        target_classifier = sys.argv[1]
        network_attack = sys.argv[2]
        adversarial_attack = sys.argv[3]

        training_dir = dir + "nids_config/training_status.txt"

        # Configure and launch Mininet
        setLogLevel('info')
        net = launch_network()
        net_assigned = True

        #Launch NIDS
        try:
            with open(training_dir, 'w') as training_status:
                training_status.write("")
        except:
            logging.error('Unable to open training status directory')
        launch_nids(dir, target_classifier)

        print("\n")
        # Initialise test suite and execute attack
        ts = TestSuite(dir, network_attack, adversarial_attack, net)
        result = ts.run_test()

        time.sleep(5)
        results_dir = dir + "TestManager/test_results/results.txt"
        try:
            with open(results_dir, "a+") as results:
                # Write results based on what the test has returned
                output = result
                results.write(str(output))
                results.write("\n")
        except:
            logging.error('Unable to open and write to results file')

    except KeyboardInterrupt:
        print("Stopping Neptune..")
        os.system('sudo pkill -f Neptune/main.py')

        print("\nStopping network..\n")
        if net_assigned:
            net.stop()

        sys.exit(0)

    finally:
        print("Stopping Neptune..")
        os.system('sudo pkill -f Neptune/main.py')

        if net_assigned:
            print("\nStopping network..\n")
            net.stop()
        time.sleep(5)

        with open(training_dir, 'w') as training_status:
            training_status.write("")