aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatěj Cepl <mcepl@redhat.com>2013-10-05 21:48:38 +0200
committerMatěj Cepl <mcepl@redhat.com>2013-10-05 21:49:08 +0200
commit4897720c88dfc6d08184b194cff633ba8bb9f969 (patch)
tree0d2c8df2322f272f4c29d48602cdf7a6f1ee598c
parent03f62c392f3c140f4cefb5ccd129d32734b169c3 (diff)
downloadcucutags-4897720c88dfc6d08184b194cff633ba8bb9f969.tar.gz
Add testsuite.
Also fix some problems with get_step.
-rwxr-xr-xcucutags.py25
-rw-r--r--setup.py23
-rw-r--r--test/__init__.py0
m---------test/data/common_steps0
-rw-r--r--test/data/features/app-menu.feature24
-rw-r--r--test/data/features/basics.feature29
-rw-r--r--test/data/features/environment.py97
-rw-r--r--test/data/features/steps/__init__.py4
-rw-r--r--test/data/features/steps/empathy_steps.py8
-rw-r--r--test/test_cucutags.py42
10 files changed, 237 insertions, 15 deletions
diff --git a/cucutags.py b/cucutags.py
index 6d8f907..8a1c09e 100755
--- a/cucutags.py
+++ b/cucutags.py
@@ -21,6 +21,7 @@
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
import os
+import os.path
import io
import re
import sys
@@ -28,10 +29,9 @@ import logging
logging.basicConfig(format='%(levelname)s:%(funcName)s:%(message)s',
level=logging.INFO)
import parse
-import argparse
__docformat__ = 'reStructuredText'
-__version__ = "0.3.0"
+__version__ = "0.4.0"
__author__ = u"Matěj Cepl <mcepl_at_redhat_dot_com>"
@@ -118,6 +118,7 @@ class CodeFile(io.TextIOWrapper):
'targets': [],
'features': []
}
+ logging.debug("self.name = %s", self.name)
file_ext = os.path.splitext(self.name)[1]
if file_ext in PATTERNS.keys():
ftype = PATTERNS[file_ext]
@@ -145,6 +146,7 @@ class Session(object):
def __init__(self, startdir):
self.feature_list = []
self.target_list = []
+ assert(os.path.exists(startdir))
for root, dirs, files in os.walk(startdir):
for directory in dirs:
@@ -173,9 +175,11 @@ class Session(object):
return out
def get_step(self, feature):
- for feat in self.feature_list:
- trg = feat.match(self.target_list)
- if trg:
+ logging.debug("feature = %s", feature)
+ logging.debug("self.target_list = %s", self.target_list)
+ for trg in self.target_list:
+ logging.debug("trg = %s", trg)
+ if trg.ismatch(feature):
return trg.filename, trg.lineno
@@ -183,15 +187,8 @@ if __name__ == "__main__":
desc = """
Generate tags from Behave feature files and steps.
"""
- parser = argparse.ArgumentParser(description=desc)
- parser.add_argument("-o", "--output", metavar="OUTPUT",
- action="store", dest="output", default=None,
- help="Name of the output file")
- options = parser.parse_args()
-
- logging.debug("options.output = %s", options.output)
- if options.output:
- outf = io.open(options.output, "w")
+ if len(sys.argv) > 1:
+ outf = io.open(sys.argv[1], "w")
outdir = os.path.dirname(outf.name)
else:
outf = sys.stdout
diff --git a/setup.py b/setup.py
index b5888f2..0f64ee7 100644
--- a/setup.py
+++ b/setup.py
@@ -1,8 +1,28 @@
# coding: utf-8
from __future__ import absolute_import, print_function
-from distutils.core import setup
+from distutils.core import setup, Command
import os.path
import cucutags
+import unittest
+
+
+class RunTests(Command):
+ """New setup.py command to run all tests for the package.
+ """
+ description = "run all tests for the package"
+
+ user_options = []
+
+ def initialize_options(self):
+ pass
+
+ def finalize_options(self):
+ pass
+
+ def run(self):
+ tests = unittest.TestLoader().discover('.')
+ runner = unittest.TextTestRunner(verbosity=2)
+ runner.run(tests)
def read(fname):
@@ -18,6 +38,7 @@ setup(
author_email='mcepl@redhat.com',
url='https://gitorious.org/cucutags/cucutags/',
long_description=read("README.md"),
+ cmdclass={'test': RunTests},
keywords=['BDD', 'behave', 'ctags', 'tags'],
classifiers=[
"Programming Language :: Python",
diff --git a/test/__init__.py b/test/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/test/__init__.py
diff --git a/test/data/common_steps b/test/data/common_steps
new file mode 160000
+Subproject d56c6197dfe923afc39e8795bf8e1b1d5a98403
diff --git a/test/data/features/app-menu.feature b/test/data/features/app-menu.feature
new file mode 100644
index 0000000..d38e81e
--- /dev/null
+++ b/test/data/features/app-menu.feature
@@ -0,0 +1,24 @@
+Feature: Empathy App menu actions
+
+ Background: Empathy Setup
+ * Make sure that Empathy is running
+ * I open GApplication menu
+
+ @testcase_184264
+ Scenario: Contact list - help contents
+ * I click menu "Help" in GApplication menu
+ Then Yelp should start
+
+# 1. Choose 'application menu->Accounts'
+# 2. In the 'Messaging and VoIP Accounts' click + to add a new account
+# 3. Select 'Google Talk'
+# 4. Put 'desktopqe@gmail.com' as a Google ID
+# 5. Put 'redhatqe' as password
+# 6. Check 'Remember Password'
+# 7. Hit 'Apply'
+
+# @testcase_181366
+# Scenario: Add account - GTalk
+# * I click menu "Accounts" in GApplication menu
+# Then Account should successfully connect (be 'Available')
+#
diff --git a/test/data/features/basics.feature b/test/data/features/basics.feature
new file mode 100644
index 0000000..4203e79
--- /dev/null
+++ b/test/data/features/basics.feature
@@ -0,0 +1,29 @@
+@testplan_6306
+Feature: Empathy basics
+
+# Works probably only in the Gnome3 Classic mode
+#
+# @testcase_175167
+# Scenario: Close via application menu
+# * Make sure that Empathy is running
+# * Click to the Empathy on gnome-panel
+# * Click Quit
+# Then Empathy should quit correctly
+
+ @testcase_172128
+ Scenario: Exit using menu
+ * Make sure that Empathy is running
+ * I open GApplication menu
+ * I click menu "Quit" in GApplication menu
+ Then empathy shouldn't be running anymore
+
+ @testcase_172129
+ Scenario: Exit using shortcut
+ * Make sure that Empathy is running
+ * Press "<Control>Q"
+ Then Empathy shouldn't be running anymore
+
+ @testcase_172130
+ Scenario: Start using Activities
+ * Start Empathy via menu
+ Then Empathy should start
diff --git a/test/data/features/environment.py b/test/data/features/environment.py
new file mode 100644
index 0000000..dc09990
--- /dev/null
+++ b/test/data/features/environment.py
@@ -0,0 +1,97 @@
+# -*- coding: UTF-8 -*-
+
+import os
+from common_steps.helpers import dummy, App
+from gi.repository import Gio
+from dogtail.config import config
+import logging
+logging.basicConfig(format='%(levelname)s:%(funcName)s:%(message)s',
+ level=logging.INFO)
+from time import sleep
+
+
+def before_all(context):
+ """Setup empathy stuff
+ Being executed before all features
+ """
+
+ # Reset GSettings
+ schemas = [x for x
+ in Gio.Settings.list_schemas() if 'empathy' in x.lower()]
+ for schema in schemas:
+ os.system("gsettings reset-recursively %s" % schema)
+
+ # Skip warning dialog
+ #os.system("gsettings set org.gnome.empathy.shell skip-wrnng-dialog true")
+
+ # Wait for things to settle
+ sleep(0.5)
+
+ # Skip dogtail actions to print to stdout
+ config.logDebugToStdOut = False
+ config.typingDelay = 0.2
+
+ # Include assertion object
+ context.assertion = dummy()
+
+ context.app = App('empathy',
+ # Store evo output in the empathy.log
+ parameters='> empathy.log 2>&1',
+ clean_dirs=['~/.local/share/Empathy',
+ '~/.local/share/telepathy',
+ '~/.local/share/telepathy-logger',
+ '~/.cache/Empathy', '~/.cache/telepathy',
+ '~/.config/Empathy'])
+
+
+def before_tag(context, tag):
+ """Setup for scenarios marked with tag
+ If tag contains 'goa', then setup a goa account:
+ google_goa will setup Google account etc.
+ """
+ try:
+ if 'goa' in tag:
+ context.execute_steps(
+ u"* Add %s account via GOA" % tag.split('_')[1].capitalize())
+ except Exception as e:
+ print("error in before_tag(%s): %s" % (tag, e.message))
+ raise RuntimeError
+
+
+def after_step(context, step):
+ """Teardown after each step.
+ Here we make screenshot and embed it (if one of formatters supports it)
+ """
+ try:
+ # Make screnshot if step has failed
+ if hasattr(context, "embed"):
+ os.system("gnome-screenshot -f /tmp/screenshot.jpg")
+ context.embed('image/jpg', open("/tmp/screenshot.jpg", 'r').read())
+
+ if step.status == 'failed' and os.environ.get('DEBUG_ON_FAILURE'):
+ import ipdb
+ ipdb.set_trace()
+
+ except Exception:
+ #print("Error in after_step: %s" % e)
+ pass
+
+
+def after_scenario(context, scenario):
+ """Teardown for each scenario
+ Kill empathy (in order to make this reliable we send sigkill)
+ """
+ try:
+ # Stop empathy
+ os.system("pkill -f empathy &> /dev/null")
+
+ # Attach logs
+ if hasattr(context, "embed"):
+ context.embed('text/plain', open("empathy.log", 'r').read())
+ os.system("rm -rf empathy.log")
+
+ # Make some pause after scenario
+ sleep(10)
+ except Exception:
+ # Stupid behave simply crashes in case exception has occurred
+ pass
diff --git a/test/data/features/steps/__init__.py b/test/data/features/steps/__init__.py
new file mode 100644
index 0000000..9d8b553
--- /dev/null
+++ b/test/data/features/steps/__init__.py
@@ -0,0 +1,4 @@
+from common_steps.dialogs import *
+from common_steps.app import *
+from common_steps.gmenu import *
+from common_steps.helpers import *
diff --git a/test/data/features/steps/empathy_steps.py b/test/data/features/steps/empathy_steps.py
new file mode 100644
index 0000000..1eafd65
--- /dev/null
+++ b/test/data/features/steps/empathy_steps.py
@@ -0,0 +1,8 @@
+# -- FILE: features/steps/example_steps.py
+# import os
+# from gi.repository import GLib
+# from behave import then, step
+# from time import sleep
+# #from subprocess import Popen, PIPE
+# from dogtail.tree import root, SearchError
+# from dogtail.rawinput import keyCombo
diff --git a/test/test_cucutags.py b/test/test_cucutags.py
new file mode 100644
index 0000000..7ae82ec
--- /dev/null
+++ b/test/test_cucutags.py
@@ -0,0 +1,42 @@
+# -*- coding: utf-8 -*- IGNORE:C0111
+from __future__ import absolute_import, print_function, unicode_literals
+import os.path
+import cucutags
+import unittest
+import logging
+
+
+class TestCucutags(unittest.TestCase):
+ def setUp(self):
+ self.maxDiff = None
+ self.datadir = os.path.join(os.path.dirname(__file__), "data")
+ self.session = cucutags.Session(self.datadir)
+ logging.debug("session = %s", self.session)
+
+ def test_init_session(self):
+ """Just initialize Session from data in the data
+ subdirectory."""
+ self.assertIsInstance(self.session, cucutags.Session)
+
+ def test_generate_tags(self):
+ """Generate tags and compare with expected result."""
+ tags = [tuple(x[1:]) for x in
+ self.session.generate_tags(self.datadir)]
+ expected = [(u'common_steps/app.py', 59),
+ (u'common_steps/gmenu.py', 12),
+ (u'common_steps/gmenu.py', 34),
+ (u'common_steps/app.py', 59),
+ (u'common_steps/app.py', 17),
+ (u'common_steps/app.py', 42),
+ (u'common_steps/app.py', 66),
+ (u'common_steps/app.py', 59),
+ (u'common_steps/gmenu.py', 12),
+ (u'common_steps/gmenu.py', 34),
+ (u'common_steps/app.py', 66)]
+ self.assertEqual(tags, expected)
+
+ def test_find_step(self):
+ step = self.session.get_step(u"Make sure that Empathy is running")
+ filename = os.path.relpath(step[0], os.path.dirname(__file__))
+ self.assertEqual([filename, step[1]],
+ ["data/common_steps/app.py", 59])