forked from AndreMiras/pycaw
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_core.py
More file actions
60 lines (52 loc) · 1.72 KB
/
test_core.py
File metadata and controls
60 lines (52 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
"""
Verifies core features run as expected.
"""
from __future__ import print_function
import sys
import unittest
from contextlib import contextmanager
from pycaw.pycaw import AudioUtilities
try:
from StringIO import StringIO
except ImportError:
from io import StringIO
@contextmanager
def captured_output():
new_out, new_err = StringIO(), StringIO()
old_out, old_err = sys.stdout, sys.stderr
try:
sys.stdout, sys.stderr = new_out, new_err
yield sys.stdout, sys.stderr
finally:
sys.stdout, sys.stderr = old_out, old_err
class TestCore(unittest.TestCase):
def test_session_unicode(self):
"""
Makes sure printing a session doesn't crash.
"""
with captured_output() as (out, err):
sessions = AudioUtilities.GetAllSessions()
print("sessions: %s" % sessions)
for session in sessions:
print("session: %s" % session)
print("session.Process: %s" % session.Process)
def test_device_unicode(self):
"""
Makes sure printing a device doesn't crash.
"""
with captured_output() as (out, err):
devices = AudioUtilities.GetAllDevices()
print("devices: %s" % devices)
for device in devices:
print("device: %s" % device)
def test_getallsessions_reliability(self):
"""
Verifies AudioUtilities.GetAllSessions() is reliable
even calling it multiple times, refs:
https://github.com/AndreMiras/pycaw/issues/1
"""
for _ in range(100):
sessions = AudioUtilities.GetAllSessions()
self.assertTrue(len(sessions) > 0)
if __name__ == '__main__':
unittest.main()