[PATCH 3/3] Add the s390 plugin test file.

Vratislav Podzimek vpodzime at redhat.com
Tue May 19 11:42:37 UTC 2015


On Mon, 2015-05-18 at 15:10 -0400, Samantha N. Bueno wrote:
> Testing is limited since tests have to run on arches other than s390x.
> So, right now the primary sort of testing we can safely do is input
> sanitizing.
> ---
>  tests/s390_test.py | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 74 insertions(+)
>  create mode 100644 tests/s390_test.py
> 
> diff --git a/tests/s390_test.py b/tests/s390_test.py
> new file mode 100644
> index 0000000..6759a78
> --- /dev/null
> +++ b/tests/s390_test.py
> @@ -0,0 +1,74 @@
> +import unittest
> +import os
> +import overrides_hack
> +
> +from utils import fake_path
> +from gi.repository import BlockDev, GLib
> +if not BlockDev.is_initialized():
> +    BlockDev.init(None, None)
> +
> +class S390TestCase(unittest.TestCase):
> +    def test_device_input(self):
> +        """Verify that s390_sanitize_dev_input works as expected"""
> +        dev = "1234"
> +        self.assertEqual(BlockDev.s390.sanitize_dev_input(dev), '0.0.' + dev)
> +
> +        # the device number is padded on the left with 0s up to 4 digits
> +        dev = "123.abc"
> +        self.assertEqual(BlockDev.s390.sanitize_dev_input(dev), "0.0.0abc")
> +        dev = "abc"
> +        self.assertEqual(BlockDev.s390.sanitize_dev_input(dev), "0.0.0abc")
> +        dev = ".abc"
> +        self.assertEqual(BlockDev.s390.sanitize_dev_input(dev), "0.0.0abc")
> +
> +        # a complete number is unchanged
> +        dev = "0.0.abcd"
> +        self.assertEqual(BlockDev.s390.sanitize_dev_input(dev), dev)
> +
> +    def test_wwpn_input(self):
> +        """Verify that s390_zfcp_sanitize_wwpn_input works as expected"""
> +        # missing "0x" from beginning of wwpn; this should be added by fx
> +        wwpn = "01234567abcdefab"
> +        self.assertEqual(BlockDev.s390.zfcp_sanitize_wwpn_input(wwpn), "0x01234567abcdefab")
> +        # this should be fine as-is
> +        wwpn = "0x01234567abcdefab"
> +        self.assertEqual(BlockDev.s390.zfcp_sanitize_wwpn_input(wwpn), wwpn)
> +
> +    def test_lun_input(self):
> +        """Verify that s390_zfcp_sanitize_lun_input works as expected"""
> +        # user does not prepend lun with "0x"; this should get added
> +        lun = "01234567abcdefab"
> +        self.assertEqual(BlockDev.s390.zfcp_sanitize_lun_input(lun), "0x01234567abcdefab")
> +        # a user enters a lun that is between 0 and 16 chars long (non-inclusive); 0 padding should be added to expand to 16
> +        lun = "0x123"
> +        self.assertEqual(BlockDev.s390.zfcp_sanitize_lun_input(lun), "0x0123000000000000")
> +        lun = "0x12345"
> +        self.assertEqual(BlockDev.s390.zfcp_sanitize_lun_input(lun), "0x1234500000000000")
> +        lun = "0x123456"
> +        self.assertEqual(BlockDev.s390.zfcp_sanitize_lun_input(lun), "0x1234560000000000")
> +        # this should be fine as-is
> +        lun = "0x1234567800000000"
> +        self.assertEqual(BlockDev.s390.zfcp_sanitize_lun_input(lun), lun)
If these tests don't fail on non-s390 arches, then there's something
really weird or wrong because the plugin is not available there and so
aren't all the s390.* functions used above.

> +
> +class S390TestCheck(unittest.TestCase):
> +    def test_check_no_dasdfmt(self):
> +        """Verify that checking dasdfmt tool availability works as expected"""
> +
> +        # don't run this on non-s390(x)
> +        unittest.skipUnless(os.uname()[4].startswith('s390'), "s390x architecture required")
Please use unittest.skipUnless() as a decorator. That's what other tests
do.

Generally, I think we should make all the tests s390-specific (with
@unittest.skipUnless).

-- 
Vratislav Podzimek

Anaconda Rider | Red Hat, Inc. | Brno - Czech Republic



More information about the anaconda-patches mailing list