-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
120 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
comtypes==1.1.2 | ||
enum==0.4.6 | ||
enum34==1.1.4 | ||
psutil==4.1.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
flake8==2.5.4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Tests | ||
|
||
## Run all tests | ||
|
||
Using Python unit testing framework: | ||
|
||
python -m unittest discover | ||
|
||
Using Tox: | ||
|
||
tox |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
""" | ||
Verifies examples run as expected. | ||
""" | ||
import sys | ||
import unittest | ||
from contextlib import contextmanager | ||
from pycaw.pycaw import AudioUtilities | ||
from examples import audio_endpoint_volume_example | ||
from examples import simple_audio_volume_example | ||
from examples import volume_by_process_example | ||
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 TestExamples(unittest.TestCase): | ||
|
||
def test_audio_endpoint_volume_example(self): | ||
with captured_output() as (out, err): | ||
audio_endpoint_volume_example.main() | ||
output = out.getvalue() | ||
lines = output.split("\n") | ||
self.assertEqual( | ||
lines[0], 'volume.GetMute(): 0') | ||
self.assertEqual( | ||
lines[1], 'volume.GetMasterVolumeLevel(): -20.0') | ||
self.assertEqual( | ||
lines[2], 'volume.GetVolumeRange(): (-95.25, 0.0, 0.75)') | ||
self.assertEqual( | ||
lines[3], 'volume.SetMasterVolumeLevel()') | ||
self.assertEqual( | ||
lines[4], 'volume.GetMasterVolumeLevel(): -20.0') | ||
|
||
def test_simple_audio_volume_example(self): | ||
with captured_output() as (out, err): | ||
simple_audio_volume_example.main() | ||
output = out.getvalue() | ||
lines = output.strip().split("\n") | ||
sessions = AudioUtilities.GetAllSessions() | ||
self.assertEqual(len(lines), len(sessions)) | ||
for line in lines: | ||
self.assertTrue( | ||
'volume.GetMute(): 0' in line or | ||
'volume.GetMute(): 1' in line) | ||
|
||
def test_volume_by_process_example(self): | ||
volume_by_process_example.main() | ||
sessions = AudioUtilities.GetAllSessions() | ||
for session in sessions: | ||
volume = session.SimpleAudioVolume | ||
if session.Process and session.Process.name() == "chrome.exe": | ||
self.assertEqual(volume.GetMute(), 0) | ||
else: | ||
self.assertEqual(volume.GetMute(), 1) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
[tox] | ||
envlist = pep8,py27,py35 | ||
|
||
[testenv] | ||
deps = -r{toxinidir}/requirements.txt | ||
-r{toxinidir}/test-requirements.txt | ||
commands = python -m unittest discover [] | ||
|
||
[testenv:pep8] | ||
commands = flake8 |