Skip to content

Commit

Permalink
Merge branch 'release/v20160508'
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreMiras committed May 8, 2016
2 parents beed698 + af4fe8c commit 83c039a
Show file tree
Hide file tree
Showing 11 changed files with 120 additions and 10 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Change Log

## [20160508]
- Fixed enum requirement
- Unit tested examples:
- audio_endpoint_volume_example
- simple_audio_volume_example
- volume_by_process_example
- Added Tox testing framework support
- Added pyflakes passive checker to tests
- Testing style convention using pep8
- Ported code to Python3

## [20160507]
- Implemented new interfaces:
- PROPVARIANT
Expand Down
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# pycaw
Python Core Audio Windows Library
Python Core Audio Windows Library, working for both Python2 and Python3.

## Install

Expand All @@ -12,6 +12,7 @@ Development branch:
pip install https://github.com/AndreMiras/pycaw/archive/develop.zip

## Usage

```Python
from ctypes import cast, POINTER
from comtypes import CLSCTX_ALL
Expand All @@ -27,3 +28,7 @@ volume.SetMasterVolumeLevel(-20.0, None)
```

See more in the [examples](examples/) directory.

## Tests

See in the [tests](tests/) directory.
11 changes: 6 additions & 5 deletions examples/audio_endpoint_volume_example.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Get and set access to master volume example.
"""
from __future__ import print_function
from ctypes import cast, POINTER
from comtypes import CLSCTX_ALL
from pycaw.pycaw import AudioUtilities, IAudioEndpointVolume
Expand All @@ -11,12 +12,12 @@ def main():
interface = devices.Activate(
IAudioEndpointVolume._iid_, CLSCTX_ALL, None)
volume = cast(interface, POINTER(IAudioEndpointVolume))
print "volume.GetMute():", volume.GetMute()
print "volume.GetMasterVolumeLevel():", volume.GetMasterVolumeLevel()
print "volume.GetVolumeRange():", volume.GetVolumeRange()
print "volume.SetMasterVolumeLevel()"
print("volume.GetMute(): %s" % volume.GetMute())
print("volume.GetMasterVolumeLevel(): %s" % volume.GetMasterVolumeLevel())
print("volume.GetVolumeRange(): (%s, %s, %s)" % volume.GetVolumeRange())
print("volume.SetMasterVolumeLevel()")
volume.SetMasterVolumeLevel(-20.0, None)
print "volume.GetMasterVolumeLevel():", volume.GetMasterVolumeLevel()
print("volume.GetMasterVolumeLevel(): %s" % volume.GetMasterVolumeLevel())


if __name__ == "__main__":
Expand Down
3 changes: 2 additions & 1 deletion examples/simple_audio_volume_example.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
"""
Per session GetMute() SetMute() using ISimpleAudioVolume.
"""
from __future__ import print_function
from pycaw.pycaw import AudioUtilities, ISimpleAudioVolume


def main():
sessions = AudioUtilities.GetAllSessions()
for session in sessions:
volume = session._ctl.QueryInterface(ISimpleAudioVolume)
print u"volume.GetMute():", volume.GetMute()
print("volume.GetMute(): %s" % volume.GetMute())
volume.SetMute(1, None)


Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
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
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
from distutils.core import setup

setup(name='pycaw',
version='20160507',
version='20160508',
description='Python Core Audio Windows Library',
author='Andre Miras',
url='https://github.com/AndreMiras/pycaw',
packages=['pycaw'],
install_requires=['comtypes', 'enum', 'psutil'])
install_requires=['comtypes', 'enum34', 'psutil'])
1 change: 1 addition & 0 deletions test-requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
flake8==2.5.4
11 changes: 11 additions & 0 deletions tests/README.md
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 added tests/__init__.py
Empty file.
70 changes: 70 additions & 0 deletions tests/test_examples.py
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()
10 changes: 10 additions & 0 deletions tox.ini
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

0 comments on commit 83c039a

Please sign in to comment.