Exemple #1
0
 def testAllDirsExistsNoHang(self):
     flexmock(os.path)
     os.path.should_receive('exists').and_return(True)
     self.assertRaises(exceptions.TestSetupFail,
                       self.DummyTest,
                       "test",
                       test.TestName(1, "name"),
                       base_logdir=self.tmpdir)
Exemple #2
0
 def run(name, path_name):
     """ Initialize test and check the dirs were created """
     tst = self.DummyTest("test",
                          test.TestName(1, name),
                          base_logdir=self.tmpdir)
     self.assertEqual(os.path.basename(tst.logdir), path_name)
     self.assertTrue(os.path.exists(tst.logdir))
     self.assertEqual(os.path.dirname(os.path.dirname(tst.logdir)),
                      self.tmpdir)
Exemple #3
0
 def test_py_simple_test(self):
     avocado_simple_test = script.TemporaryScript(
         'simpletest.py', PY_SIMPLE_TEST, 'avocado_loader_unittest')
     avocado_simple_test.save()
     test_class, test_parameters = (self.loader.discover(
         avocado_simple_test.path, loader.ALL)[0])
     self.assertTrue(test_class == test.SimpleTest)
     test_parameters['name'] = test.TestName(0, test_parameters['name'])
     test_parameters['base_logdir'] = self.tmpdir
     tc = test_class(**test_parameters)
     tc.run_avocado()
     avocado_simple_test.remove()
Exemple #4
0
    def setUp(self):
        self.tmpdir = tempfile.mkdtemp(prefix='avocado_' + __name__)
        self.pass_script = script.TemporaryScript(
            'avocado_pass.sh', PASS_SCRIPT_CONTENTS,
            'avocado_simpletest_unittest')
        self.pass_script.save()

        self.fail_script = script.TemporaryScript(
            'avocado_fail.sh', FAIL_SCRIPT_CONTENTS,
            'avocado_simpletest_unittest')
        self.fail_script.save()

        self.tst_instance_pass = test.SimpleTest(name=test.TestName(
            1, self.pass_script.path),
                                                 base_logdir=self.tmpdir)
        self.tst_instance_pass.run_avocado()

        self.tst_instance_fail = test.SimpleTest(name=test.TestName(
            1, self.fail_script.path),
                                                 base_logdir=self.tmpdir)
        self.tst_instance_fail.run_avocado()
Exemple #5
0
 def test_load_simple_not_exec(self):
     simple_test = script.TemporaryScript('simpletest.sh', SIMPLE_TEST,
                                          'avocado_loader_unittest',
                                          mode=DEFAULT_NON_EXEC_MODE)
     simple_test.save()
     test_class, test_parameters = (
         self.loader.discover(simple_test.path, True)[0])
     self.assertTrue(test_class == test.NotATest, test_class)
     test_parameters['name'] = test.TestName(0, test_parameters['name'])
     tc = test_class(**test_parameters)
     self.assertRaises(exceptions.NotATestError, tc.test)
     simple_test.remove()
Exemple #6
0
 def test_load_not_a_test_exec(self):
     avocado_not_a_test = script.TemporaryScript('notatest.py', NOT_A_TEST,
                                                 'avocado_loader_unittest')
     avocado_not_a_test.save()
     test_class, test_parameters = (
         self.loader.discover(avocado_not_a_test.path, True)[0])
     self.assertTrue(test_class == test.SimpleTest, test_class)
     test_parameters['name'] = test.TestName(0, test_parameters['name'])
     tc = test_class(**test_parameters)
     # The test can't be executed (no shebang), raising an OSError
     # (OSError: [Errno 8] Exec format error)
     self.assertRaises(OSError, tc.test)
     avocado_not_a_test.remove()
Exemple #7
0
 def test_load_not_a_test(self):
     avocado_not_a_test = script.TemporaryScript('notatest.py',
                                                 NOT_A_TEST,
                                                 'avocado_loader_unittest',
                                                 mode=DEFAULT_NON_EXEC_MODE)
     avocado_not_a_test.save()
     test_class, test_parameters = (
         self.loader.discover(avocado_not_a_test.path, True)[0])
     self.assertTrue(test_class == test.NotATest, test_class)
     test_parameters['name'] = test.TestName(0, test_parameters['name'])
     tc = test_class(**test_parameters)
     self.assertRaises(exceptions.NotATestError, tc.test)
     avocado_not_a_test.remove()
Exemple #8
0
 def test_py_simple_test_notexec(self):
     avocado_simple_test = script.TemporaryScript('simpletest.py',
                                                  PY_SIMPLE_TEST,
                                                  'avocado_loader_unittest',
                                                  mode=DEFAULT_NON_EXEC_MODE)
     avocado_simple_test.save()
     test_class, test_parameters = (
         self.loader.discover(avocado_simple_test.path, loader.ALL)[0])
     self.assertTrue(test_class == test.NotATest)
     test_parameters['name'] = test.TestName(0, test_parameters['name'])
     test_parameters['base_logdir'] = self.tmpdir
     tc = test_class(**test_parameters)
     self.assertRaises(exceptions.NotATestError, tc.test)
     avocado_simple_test.remove()
Exemple #9
0
 def test_load_simple(self):
     simple_test = script.TemporaryScript('simpletest.sh', SIMPLE_TEST,
                                          'avocado_loader_unittest')
     simple_test.save()
     test_class, test_parameters = (self.loader.discover(
         simple_test.path, loader.ALL)[0])
     self.assertTrue(test_class == test.SimpleTest, test_class)
     test_parameters['name'] = test.TestName(0, test_parameters['name'])
     test_parameters['base_logdir'] = self.tmpdir
     tc = test_class(**test_parameters)
     tc.run_avocado()
     suite = self.loader.discover(simple_test.path, loader.ALL)
     self.assertEqual(len(suite), 1)
     self.assertEqual(suite[0][1]["name"], simple_test.path)
     simple_test.remove()
Exemple #10
0
 def test_load_simple(self):
     simple_test = script.TemporaryScript('simpletest.sh', SIMPLE_TEST,
                                          'avocado_loader_unittest')
     simple_test.save()
     test_class, test_parameters = (
         self.loader.discover(simple_test.path, True)[0])
     self.assertTrue(test_class == test.SimpleTest, test_class)
     test_parameters['name'] = test.TestName(0, test_parameters['name'])
     tc = test_class(**test_parameters)
     tc.test()
     # Load with params
     simple_with_params = simple_test.path + " 'foo bar' --baz"
     suite = self.loader.discover(simple_with_params, True)
     self.assertEqual(len(suite), 1)
     self.assertEqual(suite[0][1]["name"], simple_with_params)
     simple_test.remove()
Exemple #11
0
 def check(uid, name, variant, exp_logdir):
     tst = self.DummyTest("test",
                          test.TestName(uid, name, variant),
                          base_logdir=self.tmpdir)
     self.assertEqual(os.path.basename(tst.logdir), exp_logdir)
     return tst
Exemple #12
0
 def test_init(self):
     # No params
     self.tests.append(test.SkipTest())
     self.assertRaises(exceptions.TestSkipError, self.tests[-1].setUp)
     self.assertRaises(RuntimeError, self.tests[-1].test)
     # Positional
     self.tests.append(
         test.SkipTest("test", test.TestName(1, "my_name"), {}, None, "1",
                       None, None, "extra_param1", "extra_param2"))
     self.assertEqual(self.tests[-1].name, "1-my_name")
     # Kwargs
     self.tests.append(
         test.SkipTest(methodName="test",
                       name=test.TestName(1, "my_name2"),
                       params={},
                       base_logdir=None,
                       tag="a",
                       job=None,
                       runner_queue=None,
                       extra1="extra_param1",
                       extra2="extra_param2"))
     self.assertEqual(self.tests[-1].name, "1-my_name2")
     # both (theoretically impossible in python, but valid for nasty tests)
     # keyword args are used as they explicitly represent what they mean
     self.tests.append(
         test.SkipTest("not used",
                       "who cares", {},
                       None,
                       "0",
                       None,
                       None,
                       "extra_param1",
                       "extra_param2",
                       methodName="test",
                       name=test.TestName(1, "my_name3"),
                       params={},
                       base_logdir=None,
                       tag="3",
                       job=None,
                       runner_queue=None,
                       extra1="extra_param3",
                       extra2="extra_param4"))
     self.assertEqual(self.tests[-1].name, "1-my_name3")
     # combination
     self.tests.append(
         test.SkipTest("test",
                       test.TestName(1, "my_name4"),
                       tag="321",
                       other_param="Whatever"))
     self.assertEqual(self.tests[-1].name, "1-my_name4")
     # ugly combination (positional argument overrides kwargs, this only
     # happens when the substituted class reorders the positional arguments.
     # We try to first match keyword args and then fall-back to positional
     # ones.
     name = "positional_method_name_becomes_test_name"
     tag = "positional_base_logdir_becomes_tag"
     self.tests.append(
         test.SkipTest(test.TestName(1, name),
                       None,
                       None,
                       tag,
                       methodName="test",
                       other_param="Whatever"))
     self.assertEqual(self.tests[-1].name, "1-" + name)