summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2017-05-02 06:12:24 +0200
committerGiampaolo Rodola <g.rodola@gmail.com>2017-05-02 06:12:24 +0200
commitcc27d9f41264dc0baac39fba2d161dc668fd2c1d (patch)
tree766a49cdb28764749d8ea213030056f8490725b0
parenta8a535f7c5bd41f7513acfc4843b78c2b48be333 (diff)
parente16005089ce4af80b92d66ef017bcfdfba81fc4e (diff)
downloadpsutil-cc27d9f41264dc0baac39fba2d161dc668fd2c1d.tar.gz
Merge branch 'master' of github.com:giampaolo/psutil
-rwxr-xr-xpsutil/tests/test_connections.py3
-rwxr-xr-xpsutil/tests/test_windows.py40
-rwxr-xr-xscripts/internal/winmake.py19
3 files changed, 39 insertions, 23 deletions
diff --git a/psutil/tests/test_connections.py b/psutil/tests/test_connections.py
index c47160c7..d0c5445a 100755
--- a/psutil/tests/test_connections.py
+++ b/psutil/tests/test_connections.py
@@ -74,8 +74,9 @@ class Base(object):
# so there may be more connections.
return smap[sock.fileno()]
else:
- self.assertEqual(smap[sock.fileno()].fd, sock.fileno())
self.assertEqual(len(cons), 1)
+ if cons[0].fd != -1:
+ self.assertEqual(smap[sock.fileno()].fd, sock.fileno())
return cons[0]
def check_socket(self, sock, conn=None):
diff --git a/psutil/tests/test_windows.py b/psutil/tests/test_windows.py
index 77647652..2a883132 100755
--- a/psutil/tests/test_windows.py
+++ b/psutil/tests/test_windows.py
@@ -33,7 +33,6 @@ from psutil._compat import callable
from psutil.tests import APPVEYOR
from psutil.tests import get_test_subprocess
from psutil.tests import HAS_BATTERY
-from psutil.tests import HAS_SENSORS_BATTERY
from psutil.tests import mock
from psutil.tests import reap_children
from psutil.tests import retry_before_failing
@@ -190,33 +189,30 @@ class TestSystemAPIs(unittest.TestCase):
@unittest.skipIf(not WINDOWS, "WINDOWS only")
class TestSensorsBattery(unittest.TestCase):
- @unittest.skipIf(not HAS_SENSORS_BATTERY, "not supported")
+ def test_has_battery(self):
+ if win32api.GetPwrCapabilities()['SystemBatteriesPresent']:
+ self.assertIsNotNone(psutil.sensors_battery())
+ else:
+ self.assertIsNone(psutil.sensors_battery())
+
@unittest.skipIf(not HAS_BATTERY, "no battery")
def test_percent(self):
w = wmi.WMI()
+ battery_wmi = w.query('select * from Win32_Battery')[0]
battery_psutil = psutil.sensors_battery()
- if battery_psutil is None:
- with self.assertRaises(IndexError):
- w.query('select * from Win32_Battery')[0]
- else:
- battery_wmi = w.query('select * from Win32_Battery')[0]
- if battery_psutil is None:
- self.assertNot(battery_wmi.EstimatedChargeRemaining)
- return
-
- self.assertAlmostEqual(
- battery_psutil.percent, battery_wmi.EstimatedChargeRemaining,
- delta=1)
- self.assertEqual(
- battery_psutil.power_plugged, battery_wmi.BatteryStatus == 1)
+ self.assertAlmostEqual(
+ battery_psutil.percent, battery_wmi.EstimatedChargeRemaining,
+ delta=1)
- @unittest.skipIf(not HAS_SENSORS_BATTERY, "not supported")
@unittest.skipIf(not HAS_BATTERY, "no battery")
- def test_battery_present(self):
- if win32api.GetPwrCapabilities()['SystemBatteriesPresent']:
- self.assertIsNotNone(psutil.sensors_battery())
- else:
- self.assertIsNone(psutil.sensors_battery())
+ def test_power_plugged(self):
+ w = wmi.WMI()
+ battery_wmi = w.query('select * from Win32_Battery')[0]
+ battery_psutil = psutil.sensors_battery()
+ # Status codes:
+ # https://msdn.microsoft.com/en-us/library/aa394074(v=vs.85).aspx
+ self.assertEqual(battery_psutil.power_plugged,
+ battery_wmi.BatteryStatus == 2)
def test_emulate_no_battery(self):
with mock.patch("psutil._pswindows.cext.sensors_battery",
diff --git a/scripts/internal/winmake.py b/scripts/internal/winmake.py
index c9139977..82e99d96 100755
--- a/scripts/internal/winmake.py
+++ b/scripts/internal/winmake.py
@@ -354,6 +354,13 @@ def test_unicode():
@cmd
+def test_connections():
+ """Run connections tests"""
+ install()
+ sh("%s -m unittest -v psutil.tests.test_connections" % PYTHON)
+
+
+@cmd
def test_contracts():
"""Run contracts tests"""
install()
@@ -373,6 +380,18 @@ def test_by_name():
@cmd
+def test_script():
+ """Quick way to test a script"""
+ try:
+ print(sys.argv)
+ name = sys.argv[2]
+ except IndexError:
+ sys.exit('second arg missing')
+ install()
+ sh("%s %s" % (PYTHON, name))
+
+
+@cmd
def test_memleaks():
"""Run memory leaks tests"""
install()