-
Notifications
You must be signed in to change notification settings - Fork 45
Update Quamash to work with Python 3.4 asyncio #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c25477a
Add test for killing of subprocess
aknuds1 6997373
Build PySide through pip on Travis
aknuds1 35eee37
Merge branch 'master' into kill
aknuds1 f2049ea
Merge branch 'master' into kill
aknuds1 37fce3d
Remove space
aknuds1 072ef15
Merge branch 'master' into kill
aknuds1 5477ecf
Fix setup
aknuds1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,16 +1,18 @@ | ||
from distutils.core import setup | ||
import quamash | ||
import re | ||
author = re.match(r'(?P<name>[^<]* <(?P<email>.*)>', quamash.__author__) | ||
|
||
|
||
groups = re.findall(r'(.+?) <(.+?)>(?:,\s*)?', quamash.__author__) | ||
authors = [x[0].strip() for x in groups] | ||
emails = [x[1].strip() for x in groups] | ||
setup( | ||
name='Quamash', | ||
version=quamash.__version__, | ||
author=author.group('name'), | ||
author_email=author.group('email'), | ||
author=', '.join(authors), | ||
author_email=', '.join(emails), | ||
packages=['quamash', ], | ||
license=quamash.__license__, | ||
depends=['tulip', 'PyQt', ], | ||
description=quamash.__doc__, | ||
long_description=open('README').read(), | ||
) |
This file contains hidden or 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,83 +1,96 @@ | ||
import asyncio | ||
import os.path | ||
import logging | ||
import sys | ||
import locale | ||
try: | ||
from PyQt5.QtWidgets import QApplication | ||
except ImportError: | ||
from PySide.QtGui import QApplication | ||
import pytest | ||
|
||
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))) | ||
import quamash | ||
|
||
|
||
logging.basicConfig(level=logging.DEBUG, | ||
format='%(asctime)s - %(levelname)s - %(name)s - %(message)s') | ||
|
||
|
||
class _SubprocessProtocol(asyncio.SubprocessProtocol): | ||
def __init__(self, *args, **kwds): | ||
super(_SubprocessProtocol, self).__init__(*args, **kwds) | ||
self.received_stdout = None | ||
|
||
def pipe_data_received(self, fd, data): | ||
text = data.decode(locale.getpreferredencoding(False)) | ||
if fd == 1: | ||
self.received_stdout = text.strip() | ||
|
||
def process_exited(self): | ||
asyncio.get_event_loop().stop() | ||
|
||
|
||
|
||
@pytest.fixture(scope='session') | ||
def application(): | ||
app = QApplication([]) | ||
return app | ||
|
||
|
||
@pytest.fixture | ||
def loop(request, application): | ||
lp = quamash.QEventLoop(application) | ||
asyncio.set_event_loop(lp) | ||
|
||
def fin(): | ||
try: | ||
lp.close() | ||
finally: | ||
asyncio.set_event_loop(None) | ||
|
||
request.addfinalizer(fin) | ||
return lp | ||
|
||
|
||
class TestQEventLoop: | ||
def test_can_run_tasks_in_default_executor(self, loop): | ||
"""Verify that tasks can be run in default (threaded) executor.""" | ||
def blocking_func(): | ||
nonlocal was_invoked | ||
was_invoked = True | ||
|
||
@asyncio.coroutine | ||
def blocking_task(): | ||
yield from loop.run_in_executor(None, blocking_func) | ||
|
||
was_invoked = False | ||
loop.run_until_complete(blocking_task()) | ||
|
||
assert was_invoked | ||
|
||
def test_can_execute_subprocess(self, loop): | ||
transport, protocol = loop.run_until_complete(loop.subprocess_exec( | ||
_SubprocessProtocol, 'python', '-c', 'print(\'Hello async world!\')')) | ||
loop.run_forever() | ||
assert transport.get_returncode() == 0 | ||
assert protocol.received_stdout == 'Hello async world!' | ||
|
||
def test_can_function_as_context_manager(self, application): | ||
with quamash.QEventLoop(application) as loop: | ||
assert isinstance(loop, quamash.QEventLoop) | ||
loop.call_soon(loop.stop) | ||
loop.run_forever() | ||
import asyncio | ||
import os.path | ||
import logging | ||
import sys | ||
import locale | ||
try: | ||
from PyQt5.QtWidgets import QApplication | ||
except ImportError: | ||
from PySide.QtGui import QApplication | ||
import pytest | ||
|
||
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))) | ||
import quamash | ||
|
||
|
||
logging.basicConfig(level=logging.DEBUG, | ||
format='%(asctime)s - %(levelname)s - %(name)s - %(message)s') | ||
|
||
|
||
class _SubprocessProtocol(asyncio.SubprocessProtocol): | ||
def __init__(self, *args, **kwds): | ||
super(_SubprocessProtocol, self).__init__(*args, **kwds) | ||
self.received_stdout = None | ||
|
||
def pipe_data_received(self, fd, data): | ||
text = data.decode(locale.getpreferredencoding(False)) | ||
if fd == 1: | ||
self.received_stdout = text.strip() | ||
|
||
def process_exited(self): | ||
asyncio.get_event_loop().stop() | ||
|
||
|
||
@pytest.fixture(scope='session') | ||
def application(): | ||
app = QApplication([]) | ||
return app | ||
|
||
|
||
@pytest.fixture | ||
def loop(request, application): | ||
lp = quamash.QEventLoop(application) | ||
asyncio.set_event_loop(lp) | ||
|
||
def fin(): | ||
try: | ||
lp.close() | ||
finally: | ||
asyncio.set_event_loop(None) | ||
|
||
request.addfinalizer(fin) | ||
return lp | ||
|
||
|
||
class TestQEventLoop: | ||
def test_can_run_tasks_in_default_executor(self, loop): | ||
"""Verify that tasks can be run in default (threaded) executor.""" | ||
def blocking_func(): | ||
nonlocal was_invoked | ||
was_invoked = True | ||
|
||
@asyncio.coroutine | ||
def blocking_task(): | ||
yield from loop.run_in_executor(None, blocking_func) | ||
|
||
was_invoked = False | ||
loop.run_until_complete(blocking_task()) | ||
|
||
assert was_invoked | ||
|
||
def test_can_execute_subprocess(self, loop): | ||
"""Verify that a subprocess can be executed.""" | ||
transport, protocol = loop.run_until_complete(loop.subprocess_exec( | ||
_SubprocessProtocol, 'python', '-c', 'print(\'Hello async world!\')')) | ||
loop.run_forever() | ||
assert transport.get_returncode() == 0 | ||
assert protocol.received_stdout == 'Hello async world!' | ||
|
||
def test_can_terminate_subprocess(self, loop): | ||
"""Verify that a subprocess can be terminated.""" | ||
# Start a never-ending process | ||
transport = loop.run_until_complete(loop.subprocess_exec( | ||
_SubprocessProtocol, 'python', '-c', 'import time\nwhile True: time.sleep(1)'))[0] | ||
# Terminate! | ||
transport.kill() | ||
# Wait for process to die | ||
loop.run_forever() | ||
|
||
assert transport.get_returncode() != 0 | ||
|
||
def test_can_function_as_context_manager(self, application): | ||
"""Verify that a QEventLoop can function as its own context manager.""" | ||
with quamash.QEventLoop(application) as loop: | ||
assert isinstance(loop, quamash.QEventLoop) | ||
loop.call_soon(loop.stop) | ||
loop.run_forever() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
depends
is apparently not a supported option to setup. It's possible to instead use setuptools anddependency_links
.