diff options
author | Don Garrett <dgarrett@google.com> | 2015-10-29 13:18:30 -0700 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2015-10-30 11:47:39 -0700 |
commit | 00c1338210ff72c4843e4d7e447c3b1a196d352e (patch) | |
tree | 0dd4340cff3389a9afaae386151664ce3eee301e | |
parent | 43668504679476b87b66a2588a7ffb7c05506c8a (diff) | |
download | chromite-00c1338210ff72c4843e4d7e447c3b1a196d352e.tar.gz |
Rename unittests without matching module.
We are considering adding a cros lint test to ensure that unittests
match a general library. This CL fixes all existing cases in chromite
where that isn't already true.
Note, in one case, the unittest was for logic in the __init__.py while,
which is now tested as 'init_unittest.py'. This may require specific
lint support, or further tweaking.
BUG=None
TEST=run_tests
Change-Id: If8cb3e9f4ab90f4b518c5f7ea7e66c47240de501
Reviewed-on: https://chromium-review.googlesource.com/309860
Commit-Ready: Don Garrett <dgarrett@chromium.org>
Tested-by: Don Garrett <dgarrett@chromium.org>
Reviewed-by: Mike Frysinger <vapier@chromium.org>
l--------- | cbuildbot/builders/init_unittest (renamed from cbuildbot/builders/builders_unittest) | 0 | ||||
-rw-r--r-- | cbuildbot/builders/init_unittest.py (renamed from cbuildbot/builders/builders_unittest.py) | 0 | ||||
l--------- | cbuildbot/results_lib_unittest (renamed from lib/cidb_setup_unittest) | 0 | ||||
-rw-r--r-- | cbuildbot/results_lib_unittest.py (renamed from cbuildbot/stages/stage_results_unittest.py) | 0 | ||||
l--------- | cbuildbot/stages/stage_results_unittest | 1 | ||||
-rw-r--r-- | lib/cidb_setup_unittest.py | 120 | ||||
-rw-r--r-- | lib/cidb_unittest.py | 110 |
7 files changed, 110 insertions, 121 deletions
diff --git a/cbuildbot/builders/builders_unittest b/cbuildbot/builders/init_unittest index ef3e37b67..ef3e37b67 120000 --- a/cbuildbot/builders/builders_unittest +++ b/cbuildbot/builders/init_unittest diff --git a/cbuildbot/builders/builders_unittest.py b/cbuildbot/builders/init_unittest.py index 084365137..084365137 100644 --- a/cbuildbot/builders/builders_unittest.py +++ b/cbuildbot/builders/init_unittest.py diff --git a/lib/cidb_setup_unittest b/cbuildbot/results_lib_unittest index 72196ceea..72196ceea 120000 --- a/lib/cidb_setup_unittest +++ b/cbuildbot/results_lib_unittest diff --git a/cbuildbot/stages/stage_results_unittest.py b/cbuildbot/results_lib_unittest.py index e971e4ff6..e971e4ff6 100644 --- a/cbuildbot/stages/stage_results_unittest.py +++ b/cbuildbot/results_lib_unittest.py diff --git a/cbuildbot/stages/stage_results_unittest b/cbuildbot/stages/stage_results_unittest deleted file mode 120000 index ef3e37b67..000000000 --- a/cbuildbot/stages/stage_results_unittest +++ /dev/null @@ -1 +0,0 @@ -../../scripts/wrapper.py
\ No newline at end of file diff --git a/lib/cidb_setup_unittest.py b/lib/cidb_setup_unittest.py deleted file mode 100644 index 680dfbd6f..000000000 --- a/lib/cidb_setup_unittest.py +++ /dev/null @@ -1,120 +0,0 @@ -# Copyright 2014 The Chromium OS Authors. All rights reserved. -# Use of this source code is governed by a BSD-style license that can be -# found in the LICENSE file. - -"""Unit tests for cidb.py Setup methods.""" - -from __future__ import print_function - -from chromite.cbuildbot import constants -from chromite.lib import cidb -from chromite.lib import cros_test_lib -from chromite.lib import factory - - -class CIDBConnectionFactoryTest(cros_test_lib.MockTestCase): - """Test that CIDBConnectionFactory behaves as expected.""" - - def setUp(self): - # Ensure that we do not create any live connections in this unit test. - self.connection_mock = self.PatchObject(cidb, 'CIDBConnection') - # pylint: disable=W0212 - cidb.CIDBConnectionFactory._ClearCIDBSetup() - - def tearDown(self): - # pylint: disable=protected-access - cidb.CIDBConnectionFactory._ClearCIDBSetup() - - def testGetConnectionBeforeSetup(self): - """Calling GetConnection before Setup should raise exception.""" - self.assertRaises(factory.ObjectFactoryIllegalOperation, - cidb.CIDBConnectionFactory.GetCIDBConnectionForBuilder) - - def testSetupProd(self): - """Test that SetupProd behaves as expected.""" - cidb.CIDBConnectionFactory.SetupProdCidb() - cidb.CIDBConnectionFactory.GetCIDBConnectionForBuilder() - - # Expected constructor call - self.connection_mock.assert_called_once_with(constants.CIDB_PROD_BOT_CREDS) - self.assertTrue(cidb.CIDBConnectionFactory.IsCIDBSetup()) - self.assertRaises(factory.ObjectFactoryIllegalOperation, - cidb.CIDBConnectionFactory.SetupProdCidb) - self.assertRaises(factory.ObjectFactoryIllegalOperation, - cidb.CIDBConnectionFactory.SetupDebugCidb) - self.assertRaises(factory.ObjectFactoryIllegalOperation, - cidb.CIDBConnectionFactory.SetupMockCidb) - self.assertRaises(factory.ObjectFactoryIllegalOperation, - cidb.CIDBConnectionFactory.SetupNoCidb) - - def testSetupDebug(self): - """Test that SetupDebug behaves as expected.""" - cidb.CIDBConnectionFactory.SetupDebugCidb() - cidb.CIDBConnectionFactory.GetCIDBConnectionForBuilder() - - # Expected constructor call - self.connection_mock.assert_called_once_with(constants.CIDB_DEBUG_BOT_CREDS) - self.assertTrue(cidb.CIDBConnectionFactory.IsCIDBSetup()) - self.assertRaises(factory.ObjectFactoryIllegalOperation, - cidb.CIDBConnectionFactory.SetupProdCidb) - self.assertRaises(factory.ObjectFactoryIllegalOperation, - cidb.CIDBConnectionFactory.SetupDebugCidb) - self.assertRaises(factory.ObjectFactoryIllegalOperation, - cidb.CIDBConnectionFactory.SetupMockCidb) - self.assertRaises(factory.ObjectFactoryIllegalOperation, - cidb.CIDBConnectionFactory.SetupNoCidb) - - def testInvalidateSetup(self): - """Test that cidb connection can be invalidated.""" - cidb.CIDBConnectionFactory.SetupProdCidb() - cidb.CIDBConnectionFactory.InvalidateCIDBSetup() - self.assertRaises(AssertionError, - cidb.CIDBConnectionFactory.GetCIDBConnectionForBuilder) - - def testSetupMock(self): - """Test that SetupMock behaves as expected.""" - # Set the CIDB to mock mode, but without supplying a mock - cidb.CIDBConnectionFactory.SetupMockCidb() - - # Calls to non-mock Setup methods should fail. - self.assertRaises(factory.ObjectFactoryIllegalOperation, - cidb.CIDBConnectionFactory.SetupProdCidb) - self.assertRaises(factory.ObjectFactoryIllegalOperation, - cidb.CIDBConnectionFactory.SetupDebugCidb) - - # Now supply a mock. - a = object() - cidb.CIDBConnectionFactory.SetupMockCidb(a) - self.assertTrue(cidb.CIDBConnectionFactory.IsCIDBSetup()) - self.assertEqual(cidb.CIDBConnectionFactory.GetCIDBConnectionForBuilder(), - a) - - # Mock object can be changed by future SetupMockCidb call. - b = object() - cidb.CIDBConnectionFactory.SetupMockCidb(b) - self.assertEqual(cidb.CIDBConnectionFactory.GetCIDBConnectionForBuilder(), - b) - - # Mock object can be cleared by future ClearMock call. - cidb.CIDBConnectionFactory.ClearMock() - - # Calls to non-mock Setup methods should still fail. - self.assertRaises(factory.ObjectFactoryIllegalOperation, - cidb.CIDBConnectionFactory.SetupProdCidb) - self.assertRaises(factory.ObjectFactoryIllegalOperation, - cidb.CIDBConnectionFactory.SetupDebugCidb) - - def testSetupNo(self): - """Test that SetupNoCidb behaves as expected.""" - cidb.CIDBConnectionFactory.SetupMockCidb() - cidb.CIDBConnectionFactory.SetupNoCidb() - cidb.CIDBConnectionFactory.SetupNoCidb() - self.assertTrue(cidb.CIDBConnectionFactory.IsCIDBSetup()) - self.assertEqual(cidb.CIDBConnectionFactory.GetCIDBConnectionForBuilder(), - None) - self.assertRaises(factory.ObjectFactoryIllegalOperation, - cidb.CIDBConnectionFactory.SetupProdCidb) - self.assertRaises(factory.ObjectFactoryIllegalOperation, - cidb.CIDBConnectionFactory.SetupDebugCidb) - self.assertRaises(factory.ObjectFactoryIllegalOperation, - cidb.CIDBConnectionFactory.SetupMockCidb) diff --git a/lib/cidb_unittest.py b/lib/cidb_unittest.py index 9ff8056bf..f94a634ea 100644 --- a/lib/cidb_unittest.py +++ b/lib/cidb_unittest.py @@ -9,8 +9,10 @@ from __future__ import print_function import exceptions import sqlalchemy +from chromite.cbuildbot import constants from chromite.lib import cidb from chromite.lib import cros_test_lib +from chromite.lib import factory class RetryableOperationalError(exceptions.EnvironmentError): @@ -50,3 +52,111 @@ class HelperFunctionsTest(cros_test_lib.TestCase): FatalOperationalError()))) self.assertFalse(cidb._IsRetryableException(self._WrapError( UnknownError()))) + + +class CIDBConnectionFactoryTest(cros_test_lib.MockTestCase): + """Test that CIDBConnectionFactory behaves as expected.""" + + def setUp(self): + # Ensure that we do not create any live connections in this unit test. + self.connection_mock = self.PatchObject(cidb, 'CIDBConnection') + # pylint: disable=W0212 + cidb.CIDBConnectionFactory._ClearCIDBSetup() + + def tearDown(self): + # pylint: disable=protected-access + cidb.CIDBConnectionFactory._ClearCIDBSetup() + + def testGetConnectionBeforeSetup(self): + """Calling GetConnection before Setup should raise exception.""" + self.assertRaises(factory.ObjectFactoryIllegalOperation, + cidb.CIDBConnectionFactory.GetCIDBConnectionForBuilder) + + def testSetupProd(self): + """Test that SetupProd behaves as expected.""" + cidb.CIDBConnectionFactory.SetupProdCidb() + cidb.CIDBConnectionFactory.GetCIDBConnectionForBuilder() + + # Expected constructor call + self.connection_mock.assert_called_once_with(constants.CIDB_PROD_BOT_CREDS) + self.assertTrue(cidb.CIDBConnectionFactory.IsCIDBSetup()) + self.assertRaises(factory.ObjectFactoryIllegalOperation, + cidb.CIDBConnectionFactory.SetupProdCidb) + self.assertRaises(factory.ObjectFactoryIllegalOperation, + cidb.CIDBConnectionFactory.SetupDebugCidb) + self.assertRaises(factory.ObjectFactoryIllegalOperation, + cidb.CIDBConnectionFactory.SetupMockCidb) + self.assertRaises(factory.ObjectFactoryIllegalOperation, + cidb.CIDBConnectionFactory.SetupNoCidb) + + def testSetupDebug(self): + """Test that SetupDebug behaves as expected.""" + cidb.CIDBConnectionFactory.SetupDebugCidb() + cidb.CIDBConnectionFactory.GetCIDBConnectionForBuilder() + + # Expected constructor call + self.connection_mock.assert_called_once_with(constants.CIDB_DEBUG_BOT_CREDS) + self.assertTrue(cidb.CIDBConnectionFactory.IsCIDBSetup()) + self.assertRaises(factory.ObjectFactoryIllegalOperation, + cidb.CIDBConnectionFactory.SetupProdCidb) + self.assertRaises(factory.ObjectFactoryIllegalOperation, + cidb.CIDBConnectionFactory.SetupDebugCidb) + self.assertRaises(factory.ObjectFactoryIllegalOperation, + cidb.CIDBConnectionFactory.SetupMockCidb) + self.assertRaises(factory.ObjectFactoryIllegalOperation, + cidb.CIDBConnectionFactory.SetupNoCidb) + + def testInvalidateSetup(self): + """Test that cidb connection can be invalidated.""" + cidb.CIDBConnectionFactory.SetupProdCidb() + cidb.CIDBConnectionFactory.InvalidateCIDBSetup() + self.assertRaises(AssertionError, + cidb.CIDBConnectionFactory.GetCIDBConnectionForBuilder) + + def testSetupMock(self): + """Test that SetupMock behaves as expected.""" + # Set the CIDB to mock mode, but without supplying a mock + cidb.CIDBConnectionFactory.SetupMockCidb() + + # Calls to non-mock Setup methods should fail. + self.assertRaises(factory.ObjectFactoryIllegalOperation, + cidb.CIDBConnectionFactory.SetupProdCidb) + self.assertRaises(factory.ObjectFactoryIllegalOperation, + cidb.CIDBConnectionFactory.SetupDebugCidb) + + # Now supply a mock. + a = object() + cidb.CIDBConnectionFactory.SetupMockCidb(a) + self.assertTrue(cidb.CIDBConnectionFactory.IsCIDBSetup()) + self.assertEqual(cidb.CIDBConnectionFactory.GetCIDBConnectionForBuilder(), + a) + + # Mock object can be changed by future SetupMockCidb call. + b = object() + cidb.CIDBConnectionFactory.SetupMockCidb(b) + self.assertEqual(cidb.CIDBConnectionFactory.GetCIDBConnectionForBuilder(), + b) + + # Mock object can be cleared by future ClearMock call. + cidb.CIDBConnectionFactory.ClearMock() + + # Calls to non-mock Setup methods should still fail. + self.assertRaises(factory.ObjectFactoryIllegalOperation, + cidb.CIDBConnectionFactory.SetupProdCidb) + self.assertRaises(factory.ObjectFactoryIllegalOperation, + cidb.CIDBConnectionFactory.SetupDebugCidb) + + def testSetupNo(self): + """Test that SetupNoCidb behaves as expected.""" + cidb.CIDBConnectionFactory.SetupMockCidb() + cidb.CIDBConnectionFactory.SetupNoCidb() + cidb.CIDBConnectionFactory.SetupNoCidb() + self.assertTrue(cidb.CIDBConnectionFactory.IsCIDBSetup()) + self.assertEqual(cidb.CIDBConnectionFactory.GetCIDBConnectionForBuilder(), + None) + self.assertRaises(factory.ObjectFactoryIllegalOperation, + cidb.CIDBConnectionFactory.SetupProdCidb) + self.assertRaises(factory.ObjectFactoryIllegalOperation, + cidb.CIDBConnectionFactory.SetupDebugCidb) + self.assertRaises(factory.ObjectFactoryIllegalOperation, + cidb.CIDBConnectionFactory.SetupMockCidb) |