Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions client/doc/tutorial_test_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
one test method.
"""

from __future__ import print_function, division, absolute_import, unicode_literals

from funq.testcase import FunqTestCase
import time

Expand Down
17 changes: 9 additions & 8 deletions client/doc/tutorial_test_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
interaction.
"""

from __future__ import print_function, division, absolute_import, unicode_literals

from funq.testcase import FunqTestCase
from funq.client import FunqError


class TestCase2(FunqTestCase):
Expand All @@ -22,7 +23,7 @@ def test_libelle_btn_test(self):
btn_test = self.funq.widget('btnTest')
properties = btn_test.properties()

self.assertEquals(properties['text'], 'Test')
self.assertEqual(properties['text'], 'Test')

def test_open_dialog(self):
"""
Expand All @@ -31,29 +32,29 @@ def test_open_dialog(self):
self.funq.widget('btnTest').click()
dlg_label = self.funq.widget('dialog1_label')

self.assertEquals(dlg_label.properties()['text'], "Button clicked")
self.assertEqual(dlg_label.properties()['text'], "Button clicked")

def test_tableview_content(self):
"""
Test the data in tableview.
"""
view = self.funq.widget('tableview')
items = list(view.model_items().iter())
self.assertEquals(len(items), 16)
self.assertEqual(len(items), 16)

for item in items:
text = "row {r}, column {c}".format(r=item.row,
c=item.column)
self.assertEquals(item.value, text)
self.assertEqual(item.value, text)

def test_some_treeview_content(self):
"""
test some data in the treeview
"""
model = self.funq.widget('treeview').model_items()

item = model.item_by_named_path([u"item 1", u"item 1-2"])
parent_item = model.item_by_named_path([u"item 1"])
item = model.item_by_named_path(["item 1", "item 1-2"])
parent_item = model.item_by_named_path(["item 1"])

self.assertEquals(item.value, u"item 1-2")
self.assertEqual(item.value, "item 1-2")
self.assertIn(item, parent_item.items)
4 changes: 3 additions & 1 deletion client/funq/aliases.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@
complete widget's paths.
"""

from ConfigParser import ConfigParser
from __future__ import print_function, division, absolute_import, unicode_literals

import collections
from six.moves.configparser import ConfigParser
from funq.errors import HooqAliasesInvalidLineError, HooqAliasesKeyError


Expand Down
21 changes: 8 additions & 13 deletions client/funq/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
:class:`FunqClient`.
"""

from __future__ import print_function, division, absolute_import, unicode_literals

import socket
import json
import errno
Expand All @@ -46,6 +48,7 @@
import base64
from collections import defaultdict
import logging
import six

from funq.aliases import HooqAliases
from funq.tools import wait_for
Expand All @@ -55,14 +58,6 @@
LOG = logging.getLogger('funq.client')


# python 3 compatibility
# https://stackoverflow.com/questions/11301138/how-to-check-if-variable-is-string-with-python-2-and-3-compatibility)
try:
basestring
except NameError:
basestring = str


class FunqClient(object):

"""
Expand All @@ -82,7 +77,7 @@ def __init__(self, host=None, port=None, aliases=None,

if aliases is None:
aliases = HooqAliases()
elif isinstance(aliases, basestring):
elif isinstance(aliases, six.string_types):
aliases = HooqAliases.from_file(aliases)
elif not isinstance(aliases, HooqAliases):
raise TypeError("aliases must be None or str or an"
Expand Down Expand Up @@ -156,8 +151,8 @@ def send_command(self, action, **kwargs):
header = f.readline()
if not header:
raise FunqError("NoResponseFromApplication",
u"Pas de réponse de l'application testée -"
u" probablement un crash.")
"Pas de réponse de l'application testée -"
" probablement un crash.")
to_read = int(header)
response = json.loads(f.read(to_read).decode('utf-8'))
if response.get('success') is False:
Expand Down Expand Up @@ -323,7 +318,7 @@ def dump_widgets_list(self, stream='widgets_list.json',
"""
Write in a file the result of :meth:`widgets_list`.
"""
if isinstance(stream, basestring):
if isinstance(stream, six.string_types):
stream = open(stream, 'w')
json.dump(self.widgets_list(with_properties=with_properties),
stream, sort_keys=True, indent=4, separators=(',', ': '))
Expand All @@ -333,7 +328,7 @@ def take_screenshot(self, stream='screenshot.png', format_='PNG'):
Take a screenshot of the active desktop.
"""
data = self.send_command('grab', format=format_)
if isinstance(stream, basestring):
if isinstance(stream, six.string_types):
stream = open(stream, 'wb')
raw = base64.standard_b64decode(data['data'])
stream.write(raw) # pylint: disable=E1103
Expand Down
4 changes: 3 additions & 1 deletion client/funq/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
Defines error classes used in funq.
"""

from __future__ import print_function, division, absolute_import, unicode_literals


class FunqError(Exception):

Expand All @@ -49,7 +51,7 @@ class FunqError(Exception):
def __init__(self, classname, desc):
self.classname = classname
self.desc = desc
Exception.__init__(self, u"{classname}: {desc}".format(
Exception.__init__(self, "{classname}: {desc}".format(
classname=classname,
desc=desc))

Expand Down
27 changes: 11 additions & 16 deletions client/funq/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,14 @@
"""
Definition of widgets and models useable in funq.
"""

from __future__ import print_function, division, absolute_import, unicode_literals

from funq.tools import wait_for
from funq.errors import FunqError
import json
import base64


# python 3 compatibility
# https://stackoverflow.com/questions/11301138/how-to-check-if-variable-is-string-with-python-2-and-3-compatibility)
try:
basestring
except NameError:
basestring = str
import six


class TreeItem(object): # pylint: disable=R0903
Expand All @@ -64,7 +60,7 @@ def create(cls, client, data):
"""
self = cls()
self.client = client
for k, v in data.iteritems():
for k, v in data.items():
if k != 'items':
setattr(self, k, v)
self.items = [cls.create(client, d) for d in data.get('items', [])]
Expand Down Expand Up @@ -128,6 +124,7 @@ def __new__(mcs, name, bases, attrs):
return cls


@six.add_metaclass(WidgetMetaClass)
class Object(object):

"""
Expand All @@ -141,8 +138,6 @@ class Object(object):
in inheritance order (ie 'QObject' is last)
[type : list(str)]
"""
__metaclass__ = WidgetMetaClass

oid = None
client = None
path = None
Expand All @@ -161,7 +156,7 @@ def create(cls, client, data):
break

self = cls()
for k, v in data.iteritems():
for k, v in data.items():
setattr(self, k, v)
setattr(self, 'client', client)
return self
Expand Down Expand Up @@ -209,7 +204,7 @@ def wait_for_properties(self, props, timeout=10.0, timeout_interval=0.1):
"""
def check_props():
properties = self.properties()
for k, v in props.iteritems():
for k, v in props.items():
if properties.get(k) != v:
return False
return True
Expand Down Expand Up @@ -787,7 +782,7 @@ def dump_gitems(self, stream='gitems.json'):
Write in a file the list of graphics items.
"""
data = self.client.send_command('graphicsitems', oid=self.oid)
if isinstance(stream, basestring):
if isinstance(stream, six.string_types):
stream = open(stream, 'w')
json.dump(data,
stream, sort_keys=True, indent=4, separators=(',', ': '))
Expand All @@ -802,7 +797,7 @@ def grab_scene(self, stream, format_="PNG"):
data = self.client.send_command('grab_graphics_view', format=format_,
oid=self.oid)
has_to_be_closed = False
if isinstance(stream, basestring):
if isinstance(stream, six.string_types):
stream = open(stream, 'wb')
has_to_be_closed = True
raw = base64.standard_b64decode(data['data'])
Expand Down Expand Up @@ -830,7 +825,7 @@ def set_current_text(self, text):
"""
Define the text of the combobox, ensuring that it is a possible value.
"""
if not isinstance(text, basestring):
if not isinstance(text, six.string_types):
raise TypeError('the text parameter must be a string'
' - got %s' % type(text))
column = self.properties()['modelColumn']
Expand Down
12 changes: 7 additions & 5 deletions client/funq/noseplugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,15 @@
Module that integrates funq with nosetests.
"""

from __future__ import print_function, division, absolute_import, unicode_literals

from funq.client import ApplicationRegistry
from funq.testcase import MultiFunqTestCase, FunqTestCase, \
register_funq_app_registry
from funq.screenshoter import ScreenShoter
from funq import tools
from nose.plugins import Plugin
from ConfigParser import ConfigParser
from six.moves.configparser import ConfigParser
import os
import codecs
import logging
Expand Down Expand Up @@ -149,7 +151,7 @@ def configure(self, options, cfg):
FunqPlugin._instance = self

def beforeTest(self, test):
message = u"Starting test `%s`" % test.id()
message = "Starting test `%s`" % test.id()
lines = message_with_sep(message)
for line in lines:
LOG.info(line)
Expand All @@ -160,7 +162,7 @@ def beforeTest(self, test):
f.write('\n')

def afterTest(self, test):
message = u"Ending test `%s`" % test.id()
message = "Ending test `%s`" % test.id()
lines = message_with_sep(message)
for line in lines:
LOG.info(line)
Expand All @@ -171,12 +173,12 @@ def afterTest(self, test):
f.write('\n')

def describeTest(self, test):
return u'%s' % test.id()
return '%s' % test.id()

def take_screenshot(self, test):
if isinstance(test, MultiFunqTestCase):
if test.__app_config__:
for k, v in test.__app_config__.iteritems():
for k, v in test.__app_config__.items():
if v.screenshot_on_error:
self.screenshoter.take_screenshot(
test.funq[k],
Expand Down
11 changes: 7 additions & 4 deletions client/funq/screenshoter.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,13 @@
automatically.
"""

from __future__ import print_function, division, absolute_import, unicode_literals

import os
import itertools
import logging
import codecs
import six

LOG = logging.getLogger('funq.screenshoter')

Expand All @@ -67,17 +70,17 @@ def take_screenshot(self, funqclient, longname):
if not os.path.isdir(self.working_folder):
os.makedirs(self.working_folder)

bname = '{0}.png'.format(self.counter.next())
bname = '{0}.png'.format(six.next(self.counter))
fname = os.path.join(self.working_folder, bname)

try:
funqclient.take_screenshot(fname, 'PNG')
except (SystemExit, KeyboardInterrupt):
raise
except Exception:
LOG.exception(u"impossible de prendre un screenshot pour"
u" %s", longname)
LOG.exception("impossible de prendre un screenshot pour"
" %s", longname)
return

with codecs.open(self.txt_file_path, "a", "utf-8") as f:
f.write(u"{0}: {1}\n".format(bname, longname))
f.write("{0}: {1}\n".format(bname, longname))
Loading