From 53384afe24fbf70d37a7c6e8ae3f6521289dfbbe Mon Sep 17 00:00:00 2001 From: Lumir Balhar Date: Thu, 12 Apr 2018 13:44:51 +0200 Subject: [PATCH] Expect that tests may run without root privileges Partially fixes https://github.com/fedora-python/python-ethtool/issues/40 --- tests/test_ethtool.py | 8 +++++++- tests/test_scripts.py | 12 ++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/tests/test_ethtool.py b/tests/test_ethtool.py index ef2cb69..2d8bc0e 100755 --- a/tests/test_ethtool.py +++ b/tests/test_ethtool.py @@ -145,7 +145,13 @@ def _functions_accepting_devnames(self, devname): '[Errno 95] Operation not supported') self.assertIsInt(ethtool.get_sg(devname)) - self.assertIsInt(ethtool.get_ufo(devname)) + + try: + self.assertIsInt(ethtool.get_ufo(devname)) + except (OSError, IOError): + # This test may fail due to insufficient privileges + # That's IOError on 2.7, OSError (PermissionError) on 3 + pass self.assertIsInt(ethtool.get_tso(devname)) diff --git a/tests/test_scripts.py b/tests/test_scripts.py index 287c4da..6db3aac 100755 --- a/tests/test_scripts.py +++ b/tests/test_scripts.py @@ -72,13 +72,21 @@ def test_show_coalesce_lo(self): def test_show_offload_lo(self): self.assertIsNone(peth.show_offload(loopback)) + + # Check if we have rights to obtain ufo and set proper expected output + try: + ethtool.get_ufo(loopback) + expected_ufo = 'on' + except (OSError, IOError): + expected_ufo = 'not supported' + self.assertEqual(self._output(), '''scatter-gather: on tcp segmentation offload: on -udp fragmentation offload: on +udp fragmentation offload: {expected_ufo} generic segmentation offload: on generic receive offload: on -''' +'''.format(expected_ufo=expected_ufo) ) # Tests for another device