-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:sibson/vncdotool
- Loading branch information
Showing
23 changed files
with
439 additions
and
1,650 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
jobs: | ||
build: | ||
executor: python/default | ||
steps: | ||
- checkout | ||
- python/load-cache | ||
- python/install-deps | ||
- run: | ||
command: | | ||
if << parameters.local >>; then | ||
pip install --user -r requirements-dev.txt | ||
else | ||
pip install -r requirements-dev.txt | ||
fi | ||
pip install nose | ||
name: Install Test Dependencies | ||
- python/save-cache | ||
- run: | ||
command: | | ||
nosetests --with-xunit --xunit-file="$CIRCLE_TEST_REPORTS/nosetests.xml" tests/unit | ||
orbs: | ||
python: circleci/python@0.1 | ||
|
||
version: 2.1 | ||
|
||
workflows: | ||
main: | ||
jobs: | ||
- build |
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,30 @@ | ||
name: VNCDo CI | ||
|
||
on: [push] | ||
|
||
jobs: | ||
build: | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v1 | ||
- name: Set up Python 3.7 | ||
uses: actions/setup-python@v1 | ||
with: | ||
python-version: 3.7 | ||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install -r requirements-dev.txt | ||
- name: Lint with flake8 | ||
run: | | ||
pip install flake8 | ||
# stop the build if there are Python syntax errors or undefined names | ||
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics | ||
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide | ||
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics | ||
- name: Test with nose | ||
run: | | ||
pip install nose | ||
nosetests tests/unit |
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 was deleted.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -7,3 +7,6 @@ py==1.4.31 | |
pytest==2.8.6 | ||
tox==2.3.1 | ||
virtualenv==14.0.1 | ||
mock | ||
pyvirtualdisplay | ||
attrs>=19.3.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
Pillow==3.4.1 | ||
Twisted==16.4.0 | ||
zope.interface==4.3.2 | ||
Pillow==6.2.0 | ||
Twisted==19.7.0 | ||
zope.interface==4.4.2 |
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,23 @@ | ||
from vncdotool import api | ||
|
||
from pyvirtualdisplay import Display | ||
import tempfile | ||
|
||
|
||
def test_color_xvnc(): | ||
with tempfile.NamedTemporaryFile(prefix="vnc_", suffix=".png") as png: | ||
|
||
with Display(backend="xvnc", rfbport=5900 + 9876): | ||
with api.connect("localhost:9876") as client: | ||
client.timeout = 1 | ||
client.captureScreen(png.name) | ||
|
||
with tempfile.NamedTemporaryFile(prefix="passwd_", delete=False) as passwd_file: | ||
password = "123456" | ||
vncpasswd_generated = b"\x49\x40\x15\xf9\xa3\x5e\x8b\x22" | ||
passwd_file.write(vncpasswd_generated) | ||
passwd_file.close() | ||
with Display(backend="xvnc", rfbport=5900 + 1234, rfbauth=passwd_file.name): | ||
with api.connect("localhost:1234", password=password) as client: | ||
client.timeout = 1 | ||
client.captureScreen(png.name) |
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,113 @@ | ||
import sys | ||
from unittest.mock import Mock, _importer | ||
from functools import wraps | ||
|
||
class _isolate(object): | ||
def __init__(self, target, excludes=None): | ||
self.target = target | ||
self.excludes = [] | ||
if excludes is not None: | ||
self.excludes = excludes | ||
self.names_under_test = set(self.get_names_under_test()) | ||
|
||
def get_names_under_test(self): | ||
module = sys.modules[self.target.__module__] | ||
for name, value in module.__dict__.items(): | ||
if value is self.target or name in self.excludes: | ||
yield name | ||
|
||
def __enter__(self): | ||
module_name = self.target.__module__ | ||
self.module = sys.modules[module_name] | ||
old_module_dict = self.module.__dict__.copy() | ||
module_keys = set(self.module.__dict__.keys()) | ||
|
||
dunders = set([k for k in module_keys | ||
if k.startswith('__') and k.endswith('__')]) | ||
replaced_keys = (module_keys - dunders - self.names_under_test) | ||
for key in replaced_keys: | ||
self.module.__dict__[key] = Mock() | ||
self.module.__dict__['__mock_isolated_dict__'] = old_module_dict | ||
|
||
def __exit__(self, *_): | ||
old_module_dict = self.module.__dict__['__mock_isolated_dict__'] | ||
self.module.__dict__.clear() | ||
self.module.__dict__.update(old_module_dict) | ||
|
||
def __call__(self, thing, *args, **kwargs): | ||
if isinstance(thing, type): | ||
return self.decorate_class(thing) | ||
else: | ||
return self.decorate_callable(thing) | ||
|
||
def decorate_callable(self, func): | ||
@wraps(func) | ||
def patched(*args, **keywargs): | ||
# don't use a with here (backwards compatability with 2.5) | ||
self.__enter__() | ||
try: | ||
return func(*args, **keywargs) | ||
finally: | ||
self.__exit__() | ||
|
||
if hasattr(func, 'func_code'): | ||
# not in Python 3 | ||
patched.compat_co_firstlineno = getattr(func, "compat_co_firstlineno", | ||
func.func_code.co_firstlineno) | ||
return patched | ||
|
||
def decorate_class(self, klass, *args): | ||
# wrapping setUp allows further shared customization of mocks | ||
setup = getattr(klass, 'setUp', None) | ||
teardown = getattr(klass, 'tearDown', None) | ||
if not setup: | ||
setattr(klass, 'setUp', self.start) | ||
else: | ||
def wrap_setup(*args): | ||
self.start() | ||
setup(*args) | ||
setattr(klass, setup.__name__, wrap_setup) | ||
|
||
if not teardown: | ||
setattr(klass, 'tearDown', self.stop) | ||
else: | ||
def wrap_teardown(*args): | ||
self.stop() | ||
teardown(*args) | ||
setattr(klass, teardown.__name__, wrap_teardown) | ||
|
||
return klass | ||
|
||
start = __enter__ | ||
stop = __exit__ | ||
|
||
|
||
def isolate(target, excludes=None): | ||
""" | ||
``isolate`` acts as a function decorator, class decorator or | ||
context manager. Within the function, TestCase methods or context all | ||
objects within the targets module will be patched with a new ``Mock`` | ||
object. On exiting the function or context the patch is undone. For a | ||
``TestCase`` setUp and tearDown are wrapped. | ||
``isolate`` is useful to quickly mock out everything in a module except | ||
the ``target``. | ||
``excludes`` is either a string of form `'package.module.objectname'` or | ||
a list of such strings. The named objects will not be patched. | ||
If applied to a TestCase ``isolate`` will wrap the setUp and tearDown | ||
methods. This allows configuration of the mocked module attributes | ||
during setUp. | ||
``isolate`` borrows heavily from DingusTestCase. | ||
""" | ||
target = _importer(target) | ||
return _isolate(target, excludes) | ||
|
||
|
||
def _isolate_object(*args, **kwargs): | ||
return _isolate(*args, **kwargs) | ||
|
||
|
||
isolate.object = _isolate_object |
Oops, something went wrong.