Skip to content

Commit

Permalink
add ifconfig test case for NIC flags re. to #2037
Browse files Browse the repository at this point in the history
  • Loading branch information
giampaolo committed Sep 6, 2022
1 parent 70eecaf commit 5cf1807
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ print-wheels: ## Print downloaded wheels
# ===================================================================

git-tag-release: ## Git-tag a new release.
git tag -a release-`python -c "import setup; print(setup.get_version())"` -m `git rev-list HEAD --count`:`git rev-parse --short HEAD`
git tag -a release-`python3 -c "import setup; print(setup.get_version())"` -m `git rev-list HEAD --count`:`git rev-parse --short HEAD`
git push --follow-tags

sdist: ## Create tar.gz source distribution.
Expand Down
21 changes: 21 additions & 0 deletions psutil/tests/test_linux.py
Original file line number Diff line number Diff line change
Expand Up @@ -993,6 +993,27 @@ def test_mtu(self):
with open("/sys/class/net/%s/mtu" % name, "rt") as f:
self.assertEqual(stats.mtu, int(f.read().strip()))

@unittest.skipIf(not which("ifconfig"), "ifconfig utility not available")
def test_flags(self):
# first line looks like this:
# "eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500"
matches_found = 0
for name, stats in psutil.net_if_stats().items():
try:
out = sh("ifconfig %s" % name)
except RuntimeError:
pass
else:
match = re.search(r"flags=(\d+)?<(.*?)>", out)
if match and len(match.groups()) >= 2:
matches_found += 1
ifconfig_flags = set(match.group(2).lower().split(","))
psutil_flags = set(stats.flags.split(","))
self.assertEqual(ifconfig_flags, psutil_flags)

if not matches_found:
raise self.fail("no matches were found")


@unittest.skipIf(not LINUX, "LINUX only")
class TestSystemNetIOCounters(PsutilTestCase):
Expand Down

0 comments on commit 5cf1807

Please sign in to comment.