Skip to content

Commit

Permalink
Merge branch 'master' of github.com:sibson/vncdotool
Browse files Browse the repository at this point in the history
  • Loading branch information
sibson committed Aug 25, 2021
2 parents 716caec + a92eafc commit ee3a4f0
Show file tree
Hide file tree
Showing 23 changed files with 439 additions and 1,650 deletions.
30 changes: 30 additions & 0 deletions .circleci/config.yml
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
30 changes: 30 additions & 0 deletions .github/workflows/pythonapp.yml
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
6 changes: 6 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ python:
- "2.7"
- "3.5"

addons:
apt:
packages:
- vnc4server
- xfonts-base

# command to install dependencies
install:
- if [[ "$TRAVIS_PYTHON_VERSION" == "2.6" ]]; then pip install -r requirements-2.6-dev.txt; else pip install -r requirements-dev.txt; fi
Expand Down
11 changes: 11 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
1.0.0 (2020-04-10)
----------------------
- add ZRLE encoding, thanks Adrian Weiler
- drop python2 support
- fix mouseDrag behaviour, thanks Samir Aguiar

0.13.0 (2019-11-21)
----------------------
- new flag --incremental-refreshes, increased compatibility of capture, thanks Amir Rossert
- exit non-zero and print to stderr for unknown commands, thanks Amir Rossert

0.12.1 (2018-12-06)
----------------------
- bugfix expectRegion to use cropped images for compare, thanks Michael Fürnschuß
Expand Down
3 changes: 1 addition & 2 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
.. image:: https://img.shields.io/pypi/v/vncdotool.svg :target: https://pypi.python.org/pypi/vncdotool
.. image:: https://img.shields.io/travis/sibson/vncdotool.svg :target: https://travis-ci.org/sibson/vncdotool
.. image:: https://img.shields.io/pypi/v/vncdotool :alt: PyPI

vncdotool
===========
Expand Down
6 changes: 0 additions & 6 deletions circle.yml

This file was deleted.

1 change: 1 addition & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#
# All configuration values have a default; values that are commented out
# serve to show the default.
# flake8: noqa

import sys, os

Expand Down
4 changes: 2 additions & 2 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ version:
version-%: OLDVERSION:=$(shell python setup.py --version)
version-%: NEWVERSION=$(subst -,.,$*)
version-%:
sed -i -e s/$(OLDVERSION)/$(NEWVERSION)/ $(VERSION_FILE)
git ci setup.py -m"bump version to $*"
sed -i '' -e s/$(OLDVERSION)/$(NEWVERSION)/ $(VERSION_FILE)
git ci $(VERSION_FILE) -m"bump version to $*"

release: release-test release-tag upload

Expand Down
6 changes: 0 additions & 6 deletions requirements-2.6-dev.txt

This file was deleted.

7 changes: 0 additions & 7 deletions requirements-2.6.txt

This file was deleted.

3 changes: 3 additions & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 3 additions & 3 deletions requirements.txt
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
23 changes: 23 additions & 0 deletions tests/functional/test_xvnc.py
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)
113 changes: 113 additions & 0 deletions tests/unit/helpers.py
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

0 comments on commit ee3a4f0

Please sign in to comment.