Revision: 4381ec97cc7f
Author: Pekka Klärck
Date: Thu Nov 10 06:42:09 2011
Log: split robot.result.model to executionresult, executionerrors,
testsuite, testcase, an keyword modules.
http://code.google.com/p/robotframework/source/detail?r=4381ec97cc7f
Added:
/src/robot/result/executionerrors.py
/src/robot/result/executionresult.py
/src/robot/result/keyword.py
/src/robot/result/testcase.py
/src/robot/result/testsuite.py
Deleted:
/src/robot/result/model.py
Modified:
/src/robot/result/__init__.py
/src/robot/result/builders.py
/src/robot/result/jsondatamodelhandlers.py
/utest/model/test_statistics.py
/utest/result/test_configurer.py
/utest/result/test_resultmodel.py
=======================================
--- /dev/null
+++ /src/robot/result/executionerrors.py Thu Nov 10 06:42:09 2011
@@ -0,0 +1,32 @@
+# Copyright 2008-2011 Nokia Siemens Networks Oyj
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+from robot.model.itemlist import ItemList
+from robot.model import Message
+
+
+class ExecutionErrors(object):
+
+ def __init__(self):
+ self.messages = ItemList(Message)
+
+ def add(self, other):
+ self.messages.extend(other.messages)
+
+ def visit(self, visitor):
+ # TODO: visiting logic should be moved into visitor
+ visitor.start_errors()
+ for message in self.messages:
+ message.visit(visitor)
+ visitor.end_errors()
=======================================
--- /dev/null
+++ /src/robot/result/executionresult.py Thu Nov 10 06:42:09 2011
@@ -0,0 +1,62 @@
+# Copyright 2008-2011 Nokia Siemens Networks Oyj
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+from robot.common.statistics import Statistics
+
+from configurer import SuiteConfigurer
+from testsuite import TestSuite
+from executionerrors import ExecutionErrors
+
+
+class ExecutionResult(object):
+
+ def __init__(self):
+ self.suite = TestSuite()
+ self.errors = ExecutionErrors()
+ self.generator = None
+ self.should_return_status_rc = True
+ self._stat_opts = ()
+
+ @property
+ def statistics(self):
+ return Statistics(self.suite, *self._stat_opts)
+
+ @property
+ def return_code(self):
+ if self.should_return_status_rc:
+ return min(self.suite.critical_stats.failed, 250)
+ return 0
+
+ def configure(self, status_rc=True, **suite_opts):
+ self.should_return_status_rc = status_rc
+ SuiteConfigurer(**suite_opts).configure(self.suite)
+
+ # TODO: 1) Use **kwargs. 2) Combine with configure?
+ def configure_statistics(self, *stat_opts):
+ self._stat_opts = stat_opts
+
+ def visit(self, visitor):
+ visitor.visit_result(self)
+
+
+class CombinedExecutionResult(ExecutionResult):
+
+ def __init__(self, *others):
+ ExecutionResult.__init__(self)
+ for other in others:
+ self.add_result(other)
+
+ def add_result(self, other):
+ self.suite.suites.append(other.suite)
+ self.errors.add(other.errors)
=======================================
--- /dev/null
+++ /src/robot/result/keyword.py Thu Nov 10 06:42:09 2011
@@ -0,0 +1,34 @@
+# Copyright 2008-2011 Nokia Siemens Networks Oyj
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+from robot import model, utils
+
+
+class Keyword(model.Keyword):
+ __slots__ = ['status', 'starttime', 'endtime']
+
+ def __init__(self, name='', doc='', args=None, type='kw', timeout='',
+ status='FAIL', starttime='N/A', endtime='N/A'):
+ model.Keyword.__init__(self, name, doc, args, type, timeout)
+ self.status = status
+ self.starttime = starttime
+ self.endtime = endtime
+
+ @property
+ def elapsedtime(self):
+ return utils.get_elapsed_time(self.starttime, self.endtime)
+
+ @property
+ def is_passed(self):
+ return self.status == 'PASS'
=======================================
--- /dev/null
+++ /src/robot/result/testcase.py Thu Nov 10 06:42:09 2011
@@ -0,0 +1,43 @@
+# Copyright 2008-2011 Nokia Siemens Networks Oyj
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+from robot import model, utils
+
+from keyword import Keyword
+
+
+class TestCase(model.TestCase):
+ __slots__ = ['status', 'message', 'starttime', 'endtime']
+ keyword_class = Keyword
+
+ def __init__(self, name='', doc='', tags=None, timeout='',
status='FAIL',
+ message='', starttime='N/A', endtime='N/A'):
+ model.TestCase.__init__(self, name, doc, tags, timeout)
+ self.status = status
+ self.message = message
+ self.starttime = starttime
+ self.endtime = endtime
+
+ @property
+ def elapsedtime(self):
+ return utils.get_elapsed_time(self.starttime, self.endtime)
+
+ # TODO: Rename to passed
+ @property
+ def is_passed(self):
+ return self.status == 'PASS'
+
+ # TODO: Remove, move to where statistics are created.
+ def is_included(self, includes, excludes):
+ return self.tags.match(includes) and not self.tags.match(excludes)
=======================================
--- /dev/null
+++ /src/robot/result/testsuite.py Thu Nov 10 06:42:09 2011
@@ -0,0 +1,81 @@
+# Copyright 2008-2011 Nokia Siemens Networks Oyj
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+from robot.common.statistics import CriticalStats, AllStats
+from robot import model, utils
+
+from messagefilter import MessageFilter
+from keywordremover import KeywordRemover
+from testcase import TestCase
+from keyword import Keyword
+
+
+class TestSuite(model.TestSuite):
+ __slots__ = ['message', 'starttime', 'endtime']
+ test_class = TestCase
+ keyword_class = Keyword
+
+ def __init__(self, source='', name='', doc='', metadata=None):
+ model.TestSuite.__init__(self, source, name, doc, metadata)
+ self.message = ''
+ self.starttime = 'N/A'
+ self.endtime = 'N/A'
+
+ @property
+ def status(self):
+ return 'PASS' if not self.critical_stats.failed else 'FAIL'
+
+ @property
+ def stat_message(self):
+ return self._stat_message()
+
+ @property
+ def full_message(self):
+ stat_msg = self._stat_message()
+ if not self.message:
+ return stat_msg
+ return '%s\n\n%s' % (self.message, stat_msg)
+
+ def _stat_message(self):
+ # TODO: Should create self.statistics and move this there.
+ ctotal, cend, cpass, cfail = self._get_counts(self.critical_stats)
+ atotal, aend, apass, afail = self._get_counts(self.all_stats)
+ return ('%d critical test%s, %d passed, %d failed\n'
+ '%d test%s total, %d passed, %d failed'
+ % (ctotal, cend, cpass, cfail, atotal, aend, apass, afail))
+
+ def _get_counts(self, stat):
+ ending = utils.plural_or_not(stat.total)
+ return stat.total, ending, stat.passed, stat.failed
+
+ @property
+ def critical_stats(self):
+ return CriticalStats(self)
+
+ @property
+ def all_stats(self):
+ return AllStats(self)
+
+ @property
+ def elapsedtime(self):
+ if self.starttime == 'N/A' or self.endtime == 'N/A':
+ children = list(self.suites) + list(self.tests) +
list(self.keywords)
+ return sum(item.elapsedtime for item in children)
+ return utils.get_elapsed_time(self.starttime, self.endtime)
+
+ def remove_keywords(self, how):
+ self.visit(KeywordRemover(how))
+
+ def filter_messages(self, log_level):
+ self.visit(MessageFilter(log_level))
=======================================
--- /src/robot/result/model.py Wed Nov 9 09:48:30 2011
+++ /dev/null
@@ -1,189 +0,0 @@
-# Copyright 2008-2011 Nokia Siemens Networks Oyj
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-from robot.common.statistics import CriticalStats, AllStats, Statistics
-from robot import model, utils
-
-from messagefilter import MessageFilter
-from configurer import SuiteConfigurer
-from keywordremover import KeywordRemover
-
-
-class ExecutionResult(object):
-
- def __init__(self):
- self.suite = TestSuite()
- self.errors = ExecutionErrors()
- self.generator = None
- self.should_return_status_rc = True
- self._stat_opts = ()
-
- @property
- def statistics(self):
- return Statistics(self.suite, *self._stat_opts)
-
- @property
- def return_code(self):
- if self.should_return_status_rc:
- return min(self.suite.critical_stats.failed, 250)
- return 0
-
- def configure(self, status_rc=True, **suite_opts):
- self.should_return_status_rc = status_rc
- SuiteConfigurer(**suite_opts).configure(self.suite)
-
- # TODO: 1) Use **kwargs. 2) Combine with configure?
- def configure_statistics(self, *stat_opts):
- self._stat_opts = stat_opts
-
- def visit(self, visitor):
- visitor.visit_result(self)
-
-
-class CombinedExecutionResult(ExecutionResult):
-
- def __init__(self, *others):
- ExecutionResult.__init__(self)
- for other in others:
- self.add_result(other)
-
- def add_result(self, other):
- self.suite.suites.append(other.suite)
- self.errors.add(other.errors)
-
-
-class ExecutionErrors(object):
-
- def __init__(self):
- # TODO: Handle somehow correctly. Probably Messages class is best
approach.
- from robot.model.itemlist import ItemList
- from robot.model import Message
- self.messages = ItemList(Message)
-
- def add(self, other):
- self.messages.extend(other.messages)
-
- def visit(self, visitor):
- visitor.start_errors()
- for message in self.messages:
- message.visit(visitor)
- visitor.end_errors()
-
-
-class TestSuite(model.TestSuite):
- __slots__ = ['message', 'starttime', 'endtime']
-
- def __init__(self, source='', name='', doc='', metadata=None):
- model.TestSuite.__init__(self, source, name, doc, metadata)
- self.message = ''
- self.starttime = 'N/A'
- self.endtime = 'N/A'
-
- @property
- def status(self):
- return 'PASS' if not self.critical_stats.failed else 'FAIL'
-
- @property
- def stat_message(self):
- return self._stat_message()
-
- @property
- def full_message(self):
- stat_msg = self._stat_message()
- if not self.message:
- return stat_msg
- return '%s\n\n%s' % (self.message, stat_msg)
-
- def _stat_message(self):
- # TODO: Should create self.statistics and move this there.
- ctotal, cend, cpass, cfail = self._get_counts(self.critical_stats)
- atotal, aend, apass, afail = self._get_counts(self.all_stats)
- return ('%d critical test%s, %d passed, %d failed\n'
- '%d test%s total, %d passed, %d failed'
- % (ctotal, cend, cpass, cfail, atotal, aend, apass, afail))
-
- def _get_counts(self, stat):
- ending = utils.plural_or_not(stat.total)
- return stat.total, ending, stat.passed, stat.failed
-
- @property
- def critical_stats(self):
- return CriticalStats(self)
-
- @property
- def all_stats(self):
- return AllStats(self)
-
- @property
- def elapsedtime(self):
- if self.starttime == 'N/A' or self.endtime == 'N/A':
- children = list(self.suites) + list(self.tests) +
list(self.keywords)
- return sum(item.elapsedtime for item in children)
- return utils.get_elapsed_time(self.starttime, self.endtime)
-
- def remove_keywords(self, how):
- self.visit(KeywordRemover(how))
-
- def filter_messages(self, log_level):
- self.visit(MessageFilter(log_level))
-
-
-class TestCase(model.TestCase):
- __slots__ = ['status', 'message', 'starttime', 'endtime']
-
- def __init__(self, name='', doc='', tags=None, timeout='',
status='FAIL',
- message='', starttime='N/A', endtime='N/A'):
- model.TestCase.__init__(self, name, doc, tags, timeout)
- self.status = status
- self.message = message
- self.starttime = starttime
- self.endtime = endtime
-
- @property
- def elapsedtime(self):
- return utils.get_elapsed_time(self.starttime, self.endtime)
-
- # TODO: Rename to passed
- @property
- def is_passed(self):
- return self.status == 'PASS'
-
- # TODO: Remove, move to where statistics are created.
- def is_included(self, includes, excludes):
- return self.tags.match(includes) and not self.tags.match(excludes)
-
-
-class Keyword(model.Keyword):
- __slots__ = ['status', 'starttime', 'endtime']
-
- def __init__(self, name='', doc='', args=None, type='kw', timeout='',
- status='FAIL', starttime='N/A', endtime='N/A'):
- model.Keyword.__init__(self, name, doc, args, type, timeout)
- self.status = status
- self.starttime = starttime
- self.endtime = endtime
-
- @property
- def elapsedtime(self):
- return utils.get_elapsed_time(self.starttime, self.endtime)
-
- @property
- def is_passed(self):
- return self.status == 'PASS'
-
-
-# TODO: Split this module so that classes can set attributes themselves
-TestSuite.keyword_class = Keyword
-TestSuite.test_class = TestCase
-TestCase.keyword_class = Keyword
=======================================
--- /src/robot/result/__init__.py Mon Oct 24 04:18:58 2011
+++ /src/robot/result/__init__.py Thu Nov 10 06:42:09 2011
@@ -11,3 +11,8 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
+
+from testsuite import TestSuite
+from testcase import TestCase
+from keyword import Keyword
+
=======================================
--- /src/robot/result/builders.py Tue Nov 8 04:38:12 2011
+++ /src/robot/result/builders.py Thu Nov 10 06:42:09 2011
@@ -18,7 +18,7 @@
from robot.utils.etreewrapper import ET
from robot import utils
-from model import ExecutionResult, CombinedExecutionResult
+from executionresult import ExecutionResult, CombinedExecutionResult
from suiteteardownfailed import SuiteTeardownFailureHandler
=======================================
--- /src/robot/result/jsondatamodelhandlers.py Wed Nov 9 04:20:44 2011
+++ /src/robot/result/jsondatamodelhandlers.py Thu Nov 10 06:42:09 2011
@@ -14,7 +14,7 @@
from robot import utils
from robot.output import LEVELS
-from robot.result.model import TestSuite, Keyword, TestCase
+from robot.result import TestSuite, Keyword, TestCase
class _Handler(object):
=======================================
--- /utest/model/test_statistics.py Wed Nov 9 05:50:28 2011
+++ /utest/model/test_statistics.py Thu Nov 10 06:42:09 2011
@@ -3,7 +3,7 @@
from robot.utils.asserts import *
from robot.model.statistics import *
-from robot.result.model import TestSuite, TestCase
+from robot.result import TestSuite, TestCase
def verify_stat(stat, name, passed, failed, critical=None, non_crit=None,
id=None):
=======================================
--- /utest/result/test_configurer.py Thu Nov 3 17:13:41 2011
+++ /utest/result/test_configurer.py Thu Nov 10 06:42:09 2011
@@ -3,7 +3,7 @@
from robot.utils.asserts import assert_equal, assert_raises_with_msg
from robot.errors import DataError
-from robot.result.model import TestSuite, TestCase
+from robot.result import TestSuite, TestCase
from robot.result.configurer import SuiteConfigurer
=======================================
--- /utest/result/test_resultmodel.py Wed Nov 9 08:52:02 2011
+++ /utest/result/test_resultmodel.py Thu Nov 10 06:42:09 2011
@@ -1,7 +1,7 @@
import unittest
-from robot.utils.asserts import assert_equal, assert_true, assert_raises
-
-from robot.result.model import *
+from robot.utils.asserts import assert_equal
+
+from robot.result import TestSuite, TestCase
class TestSuiteStats(unittest.TestCase):