On Mon, Nov 17, 2014 at 11:29 AM, 'Aaron Karper' via ganeti-devel
<[email protected]> wrote:
> Many of the KVM related unittests are multiple tests in a single method
> and include non-trivial logic. This patch splits the tests in multiple
> methods, each of which has trivial logic.
>
> Signed-off-by: Aaron Karper <[email protected]>
> ---
>  test/py/ganeti.hypervisor.hv_kvm_unittest.py | 122 
> +++++++++++++++------------
>  1 file changed, 69 insertions(+), 53 deletions(-)
>
> diff --git a/test/py/ganeti.hypervisor.hv_kvm_unittest.py 
> b/test/py/ganeti.hypervisor.hv_kvm_unittest.py
> index a99157b..c831461 100755
> --- a/test/py/ganeti.hypervisor.hv_kvm_unittest.py
> +++ b/test/py/ganeti.hypervisor.hv_kvm_unittest.py
> @@ -319,73 +319,89 @@ class TestConsole(unittest.TestCase):
>
>
>  class TestVersionChecking(testutils.GanetiTestCase):
> -  def testParseVersion(self):
> -    parse = hv_kvm.KVMHypervisor._ParseKVMVersion
> -    help_112 = testutils.ReadTestData("kvm_1.1.2_help.txt")
> -    help_10 = testutils.ReadTestData("kvm_1.0_help.txt")
> -    help_01590 = testutils.ReadTestData("kvm_0.15.90_help.txt")
> -    help_0125 = testutils.ReadTestData("kvm_0.12.5_help.txt")
> -    help_091 = testutils.ReadTestData("kvm_0.9.1_help.txt")
> -    self.assertEqual(parse(help_112), ("1.1.2", 1, 1, 2))
> -    self.assertEqual(parse(help_10), ("1.0", 1, 0, 0))
> -    self.assertEqual(parse(help_01590), ("0.15.90", 0, 15, 90))
> -    self.assertEqual(parse(help_0125), ("0.12.5", 0, 12, 5))
> -    self.assertEqual(parse(help_091), ("0.9.1", 0, 9, 1))
> +  @staticmethod
> +  def ParseTestData(name):
> +    help = testutils.ReadTestData(name)
> +    return hv_kvm.KVMHypervisor._ParseKVMVersion(help)
>
> +  def testParseVersion112(self):
> +    self.assertEqual(
> +        self.ParseTestData("kvm_1.1.2_help.txt"), ("1.1.2", 1, 1, 2))
>
> -class TestSpiceParameterList(unittest.TestCase):
> -  def test(self):
> -    defaults = constants.HVC_DEFAULTS[constants.HT_KVM]
> +  def testParseVersion10(self):
> +    self.assertEqual(self.ParseTestData("kvm_1.0_help.txt"), ("1.0", 1, 0, 
> 0))
> +
> +  def testParseVersion01590(self):
> +    self.assertEqual(
> +        self.ParseTestData("kvm_0.15.90_help.txt"), ("0.15.90", 0, 15, 90))
> +
> +  def testParseVersion0125(self):
> +    self.assertEqual(
> +        self.ParseTestData("kvm_0.12.5_help.txt"), ("0.12.5", 0, 12, 5))
>
> -    params = \
> -      compat.UniqueFrozenset(getattr(constants, name)
> -                             for name in dir(constants)
> -                             if name.startswith("HV_KVM_SPICE_"))
> +  def testParseVersion091(self):
> +    self.assertEqual(
> +        self.ParseTestData("kvm_0.9.1_help.txt"), ("0.9.1", 0, 9, 1))
>
> -    # Parameters whose default value evaluates to True and don't need to be 
> set
> -    defaults_true = frozenset(filter(defaults.__getitem__, params))
>
> -    self.assertEqual(defaults_true, frozenset([
> -      constants.HV_KVM_SPICE_AUDIO_COMPR,
> -      constants.HV_KVM_SPICE_USE_VDAGENT,
> -      constants.HV_KVM_SPICE_TLS_CIPHERS,
> -      ]))
> +class TestSpiceParameterList(unittest.TestCase):
> +  def setUp(self):
> +    self.defaults = constants.HVC_DEFAULTS[constants.HT_KVM]
> +
> +  def testAudioCompressionDefaultOn(self):
> +    self.assertTrue(self.defaults[constants.HV_KVM_SPICE_AUDIO_COMPR])
>
> -    # HV_KVM_SPICE_BIND decides whether the other parameters must be set if
> -    # their default evaluates to False
> -    assert constants.HV_KVM_SPICE_BIND in params
> -    assert constants.HV_KVM_SPICE_BIND not in defaults_true
> +  def testVdAgentDefaultOn(self):
> +    self.assertTrue(self.defaults[constants.HV_KVM_SPICE_USE_VDAGENT])
>
> -    # Exclude some parameters
> -    params -= defaults_true | frozenset([
> -      constants.HV_KVM_SPICE_BIND,
> -      ])
> +  def testTlsCiphersDefaultOn(self):
> +    self.assertTrue(self.defaults[constants.HV_KVM_SPICE_TLS_CIPHERS])
>
> -    self.assertEqual(hv_kvm._SPICE_ADDITIONAL_PARAMS, params)
> +  def testBindDefaultOff(self):
> +    self.assertFalse(self.defaults[constants.HV_KVM_SPICE_BIND])
> +
> +  def testAdditionalParams(self):
> +    params = compat.UniqueFrozenset(
> +        getattr(constants, name)
> +        for name in dir(constants)
> +        if name.startswith("HV_KVM_SPICE_"))
> +    fixed = set([
> +        constants.HV_KVM_SPICE_BIND, constants.HV_KVM_SPICE_TLS_CIPHERS,
> +        constants.HV_KVM_SPICE_USE_VDAGENT, 
> constants.HV_KVM_SPICE_AUDIO_COMPR])
> +    self.assertEqual(hv_kvm._SPICE_ADDITIONAL_PARAMS, params - fixed)
>
>
>  class TestHelpRegexps(testutils.GanetiTestCase):
> -  def testBootRe(self):
> -    """Check _BOOT_RE
> +  """Check _BOOT_RE
>
> -    It has too match -drive.*boot=on|off except if there is another 
> dash-option
> -    at the beginning of the line.
> +  It has too match -drive.*boot=on|off except if there is another dash-option

s/too/to/

> +  at the beginning of the line.
>
> -    """
> +  """
> +
> +  @staticmethod
> +  def SearchTestData(name):
>      boot_re = hv_kvm.KVMHypervisor._BOOT_RE
> -    help_112 = testutils.ReadTestData("kvm_1.1.2_help.txt")
> -    help_10 = testutils.ReadTestData("kvm_1.0_help.txt")
> -    help_01590 = testutils.ReadTestData("kvm_0.15.90_help.txt")
> -    help_0125 = testutils.ReadTestData("kvm_0.12.5_help.txt")
> -    help_091 = testutils.ReadTestData("kvm_0.9.1_help.txt")
> -    help_091_fake = testutils.ReadTestData("kvm_0.9.1_help_boot_test.txt")
> -
> -    self.assertTrue(boot_re.search(help_091))
> -    self.assertTrue(boot_re.search(help_0125))
> -    self.assertFalse(boot_re.search(help_091_fake))
> -    self.assertFalse(boot_re.search(help_112))
> -    self.assertFalse(boot_re.search(help_10))
> -    self.assertFalse(boot_re.search(help_01590))
> +    help = testutils.ReadTestData(name)
> +    return boot_re.search(help)
> +
> +  def testBootRe112(self):
> +    self.assertFalse(self.SearchTestData("kvm_1.1.2_help.txt"))
> +
> +  def testBootRe10(self):
> +    self.assertFalse(self.SearchTestData("kvm_1.0_help.txt"))
> +
> +  def testBootRe01590(self):
> +    self.assertFalse(self.SearchTestData("kvm_0.15.90_help.txt"))
> +
> +  def testBootRe0125(self):
> +    self.assertTrue(self.SearchTestData("kvm_0.12.5_help.txt"))
> +
> +  def testBootRe091(self):
> +    self.assertTrue(self.SearchTestData("kvm_0.9.1_help.txt"))
> +
> +  def testBootRe091_fake(self):
> +    self.assertFalse(self.SearchTestData("kvm_0.9.1_help_boot_test.txt"))
>
>
>  class TestGetTunFeatures(unittest.TestCase):
> --
> 2.1.0.rc2.206.gedb03e5
>

Rest LGTM, no need to resend.

Thanks,
Michele

-- 
Google Germany GmbH
Dienerstr. 12
80331 München

Registergericht und -nummer: Hamburg, HRB 86891
Sitz der Gesellschaft: Hamburg
Geschäftsführer: Graham Law, Christine Elizabeth Flores

Reply via email to