Revision: 3f8f6d060ac2
Author:   Jussi Malinen
Date:     Wed Jul 13 04:23:55 2011
Log: Python side of splitting also suite setup/teardown to separate js files when splitting log.
http://code.google.com/p/robotframework/source/detail?r=3f8f6d060ac2

Modified:
 /src/robot/result/elementhandlers.py
 /src/robot/result/parsingcontext.py
 /utest/result/test_js_serializer.py
 /utest/result/test_parsingcontext.py
 /utest/result/test_reporting.py

=======================================
--- /src/robot/result/elementhandlers.py        Wed Jul 13 01:40:54 2011
+++ /src/robot/result/elementhandlers.py        Wed Jul 13 04:23:55 2011
@@ -155,7 +155,6 @@

     def __init__(self, context, attrs):
         _Handler.__init__(self, context)
-        self._context.start_keyword()
         self._type = attrs.get('type')
         if self._type == 'for': self._type = 'forloop'
         self._name = attrs.get('name')
@@ -163,6 +162,10 @@
         self._keywords = []
         self._messages = []
         self._current_children = None
+        self._start()
+
+    def _start(self):
+        self._context.start_keyword()

     def get_handler_for(self, name, attrs):
         if name == 'status':
@@ -179,18 +182,28 @@

     def end_element(self, text):
         result = self._get_ids([self._type, self._name, self._timeout]) + \
- self._data_from_children + [self._keywords] + [self._messages]
-        self._context.end_keyword()
+ self._data_from_children + [self._get_keywords()] + [self._messages]
         return result

+    def _get_keywords(self):
+        self._context.end_keyword()
+        return self._keywords
+

 class _SuiteSetupTeardownHandler(_KeywordHandler):

+    def _start(self):
+        self._context.start_suite_setup_or_teardown()
+
     def end_element(self, text):
         if self._type == 'teardown' and not self._last_child_passed():
             self._context.suite_teardown_failed()
         return _KeywordHandler.end_element(self, text)

+    def _get_keywords(self):
+        return self._context.end_suite_setup_or_teardown(self._keywords)
+
+

# TODO: StatisticsHandler and StatItemHandler should be separated somehow from suite handlers

=======================================
--- /src/robot/result/parsingcontext.py Tue Jul 12 09:19:32 2011
+++ /src/robot/result/parsingcontext.py Wed Jul 13 04:23:55 2011
@@ -22,7 +22,7 @@

 class Context(object):

-    def __init__(self, log_path='NONE', split_tests=False):
+    def __init__(self, log_path='NONE', split_log=False):
         self._main_text_cache = TextCache()
         self._current_texts = self._main_text_cache
         self._split_text_caches = []
@@ -30,7 +30,7 @@
         self._stats = Stats()
         self._location = Location()
         self._links = {}
-        self._split_tests = split_tests
+        self._split_log = split_log
         self.split_results = []
         self._log_path = log_path

@@ -78,27 +78,39 @@
         self._location.end_suite()

     def start_test(self, name):
-        if self._split_tests:
+        if self._split_log:
             self._split_text_caches.append(TextCache())
         self._location.start_test()

     def end_test(self, kw_data=None):
         self._location.end_test()
-        if self._split_tests:
+        if self._split_log:
self.split_results.append((kw_data, self._split_text_caches[-1].dump()))
             return len(self.split_results)
         return kw_data

     def start_keyword(self):
-        if self._split_tests and self._location.on_test_level:
+        if self._split_log:
             self._current_texts = self._split_text_caches[-1]
         self._location.start_keyword()

     def end_keyword(self):
         self._location.end_keyword()
-        if self._split_tests and self._location.on_test_level:
+        if self._split_log and self._location.on_split_end_level:
             self._current_texts = self._main_text_cache

+    def start_suite_setup_or_teardown(self):
+        if self._split_log:
+            self._split_text_caches.append(TextCache())
+        self._location.start_keyword()
+
+    def end_suite_setup_or_teardown(self, kw_data=None):
+        self._location.end_keyword()
+        if self._split_log:
+ self.split_results.append((kw_data, self._split_text_caches[-1].dump()))
+            return len(self.split_results)
+        return kw_data
+
     def create_link_to_current_location(self, key):
         self._links[tuple(key)] = self._location.current_id

@@ -205,9 +217,15 @@
             ind.pop()

     @property
-    def on_test_level(self):
+    def on_split_end_level(self):
+ return self._on_test_level() or self._on_suite_setup_or_teardown_level()
+
+    def _on_test_level(self):
         return self._ids[-1][0] == 't'

+    def _on_suite_setup_or_teardown_level(self):
+        return self._ids[-2][0] == 's'
+
     @property
     def current_id(self):
         return '-'.join(self._ids)
=======================================
--- /utest/result/test_js_serializer.py Tue Jul 12 09:19:32 2011
+++ /utest/result/test_js_serializer.py Wed Jul 13 04:23:55 2011
@@ -406,66 +406,119 @@

 class TestTestSplittingJsSerializer(_JsSerializerTestBase):

-    SUITE_XML = """
+    def setUp(self):
+        self._context = Context(split_log=True)
+        self._handler = _RobotOutputHandler(self._context)
+
+    def test_split_tests(self):
+        data_model = self._get_data_model("""
 <suite source="/tmp/supersimple.txt" name="Supersimple">
+  <doc>sdoc</doc>
   <test name="Test" timeout="">
     <doc>doc</doc>
     <kw type="kw" name="Keyword.Example" timeout="">
<status status="PASS" endtime="20110601 12:01:51.353" starttime="20110601 12:01:51.376"></status>
     </kw>
+    <kw type="kw" name="Second keyword" timeout="">
+ <status status="PASS" endtime="20110601 12:01:51.353" starttime="20110601 12:01:51.376"></status>
+    </kw>
<status status="PASS" endtime="20110601 12:01:51.354" critical="yes" starttime="20110601 12:01:51.353"></status>
   </test>
<status status="PASS" endtime="20110601 12:01:51.354" starttime="20110601 12:01:51.329"></status>
-</suite>"""
-
-    SUITE_XML_WITH_TWO_KEYWORDS = """
+</suite>""")
+        assert_model(data_model,
+                     plain_suite=
+ ['*Supersimple', '*/tmp/supersimple.txt', '*', '*sdoc',
+                      ['*P', -47, 25],
+                      [],
+                      [['*Test', '*', '*Y', '*doc', ['*P', -23, 1], 1]],
+                      [],
+                      [1, 1, 1, 1]])
+ expected_data = [['*kw', '*Keyword.Example', '*', ['*P', 0, -23], [], []], + ['*kw', '*Second keyword', '*', ['*P', 0, -23], [], []]]
+        keywords, strings = self._context.split_results[0]
+        _assert_plain_suite_item(expected_data, keywords, strings)
+
+    def test_split_tests_and_suite_keywords(self):
+        data_model = self._get_data_model("""
 <suite source="/tmp/supersimple.txt" name="Supersimple">
+  <doc>sdoc</doc>
+  <kw type="setup" name="Suite Setup" timeout="1 year">
+    <doc>setup doc</doc>
+    <kw type="kw" name="First keyword" timeout="">
+      <doc>1st doc</doc>
+      <msg timestamp="20110601 12:01:51.353" level="WARN">setup msg</msg>
+ <status status="PASS" endtime="20110601 12:01:51.353" starttime="20110601 12:01:51.353"></status>
+      <kw type="kw" name="Sub keyword" timeout="">
+        <doc>sub doc</doc>
+ <status status="PASS" endtime="20110601 12:01:51.353" starttime="20110601 12:01:51.353"></status>
+      </kw>
+    </kw>
+    <kw type="kw" name="Second keyword" timeout="">
+      <doc>2nd doc</doc>
+ <status status="PASS" endtime="20110601 12:01:51.353" starttime="20110601 12:01:51.353"></status>
+    </kw>
+ <status status="PASS" endtime="20110601 12:01:51.353" starttime="20110601 12:01:51.353"></status>
+  </kw>
   <test name="Test" timeout="">
     <doc>doc</doc>
     <kw type="kw" name="Keyword.Example" timeout="">
- <status status="PASS" endtime="20110601 12:01:51.353" starttime="20110601 12:01:51.376"></status>
+      <doc>kd</doc>
+ <status status="PASS" endtime="20110601 12:01:51.354" starttime="20110601 12:01:51.353"></status>
     </kw>
-    <kw type="kw" name="Second keyword" timeout="">
- <status status="PASS" endtime="20110601 12:01:51.353" starttime="20110601 12:01:51.376"></status>
+    <kw type="teardown" name="Pass" timeout="">
+      <doc>ted</doc>
+ <status status="PASS" endtime="20110601 12:01:51.354" starttime="20110601 12:01:51.354"></status>
     </kw>
<status status="PASS" endtime="20110601 12:01:51.354" critical="yes" starttime="20110601 12:01:51.353"></status>
   </test>
- <status status="PASS" endtime="20110601 12:01:51.354" starttime="20110601 12:01:51.329"></status>
-</suite>"""
-
-    def setUp(self):
-        self._context = Context(split_tests=True)
-        self._handler = _RobotOutputHandler(self._context)
-
-    def test_split_keyword(self):
-        data_model = self._get_data_model(self.SUITE_XML)
+  <kw type="teardown" name="Suite Teardown" timeout="">
+    <doc>td doc</doc>
+    <msg timestamp="20110601 12:01:51.354" level="WARN">td msg</msg>
+ <status status="FAIL" endtime="20110601 12:01:51.354" starttime="20110601 12:01:51.354"></status>
+  </kw>
+ <status status="FAIL" endtime="20110601 12:01:51.354" starttime="20110601 12:01:51.353"></status>
+</suite>""")
         assert_model(data_model,
                      plain_suite=
- [ '*Supersimple', '*/tmp/supersimple.txt', '*', ['*P', -47, 25],[],
-                         [['*Test', '*', '*Y', '*doc',['*P', -23, 1],
-                           1
-                         ]],
-                         [],[1, 1, 1, 1]])
- expected_data = [['*kw', '*Keyword.Example', '*', ['*P', 0, -23], [], []]]
-        keywords, strings = self._context.split_results[0]
-        _assert_plain_suite_item(expected_data, keywords, strings)
-
-    def test_split_several_keywords(self):
-        data_model = self._get_data_model(self.SUITE_XML_WITH_TWO_KEYWORDS)
-        assert_model(data_model,
-                     plain_suite=
- ['*Supersimple', '*/tmp/supersimple.txt', '*', ['*P', -47, 25],[],
-                         [['*Test', '*', '*Y', '*doc',['*P', -23, 1],
-                           1
-                         ]],
-                         [],[1, 1, 1, 1]])
- expected_data = [['*kw', '*Keyword.Example', '*', ['*P', 0, -23], [], []], ['*kw', '*Second keyword', '*', ['*P', 0, -23], [], []]]
-        keywords, strings = self._context.split_results[0]
-        _assert_plain_suite_item(expected_data, keywords, strings)
+ ['*Supersimple', '*/tmp/supersimple.txt', '*', '*sdoc',
+                      ['*F', 0, 1],
+                      [],
+                      [['*Test', '*', '*Y', '*doc', ['*P', 0, 1], 2]],
+                      [
+                       ['*setup', '*Suite Setup', '*1 year', '*setup doc',
+                        ['*P', 0, 0], 1, []],
+                       ['*teardown', '*Suite Teardown', '*', '*td doc',
+                        ['*F', 1, 0], 3, [[1, '*W', '*td msg']]],
+                      ],
+                      [1, 0, 1, 0]])
+ split_test = [['*kw', '*Keyword.Example', '*', '*kd', ['*P', 0, 1], [], []], + ['*teardown', '*Pass', '*', '*ted', ['*P', 1, 0], [], []]] + _assert_plain_suite_item(split_test, *self._context.split_results[1]) + split_setup = [['*kw', '*First keyword', '*', '*1st doc', ['*P', 0, 0], + [['*kw', '*Sub keyword', '*', '*sub doc', ['*P', 0, 0], [], []]],
+                        [[0, '*W', '*setup msg']]
+                       ],
+ ['*kw', '*Second keyword', '*', '*2nd doc', ['*P', 0, 0], [], []]] + _assert_plain_suite_item(split_setup, *self._context.split_results[0])
+        split_teardown = []
+ _assert_plain_suite_item(split_teardown, *self._context.split_results[2]) + assert_equals(self._context.link_to([0, 'W', 'setup msg']), "s1-k1-k1")
+        assert_equals(self._context.link_to([1, 'W', 'td msg']), "s1-k2")


 class TestRelativeSuiteSource(_JsSerializerTestBase):
-    SUITE_XML = TestTestSplittingJsSerializer.SUITE_XML
+    SUITE_XML = """
+<suite source="/tmp/supersimple.txt" name="Supersimple">
+  <test name="Test" timeout="">
+    <doc>doc</doc>
+    <kw type="kw" name="Keyword.Example" timeout="">
+ <status status="PASS" endtime="20110601 12:01:51.353" starttime="20110601 12:01:51.376"></status>
+    </kw>
+ <status status="PASS" endtime="20110601 12:01:51.354" critical="yes" starttime="20110601 12:01:51.353"></status>
+  </test>
+ <status status="PASS" endtime="20110601 12:01:51.354" starttime="20110601 12:01:51.329"></status>
+</suite>"""

     def setUp(self):
         self._original_exists = os.path.exists
=======================================
--- /utest/result/test_parsingcontext.py        Tue Jul 12 09:19:32 2011
+++ /utest/result/test_parsingcontext.py        Wed Jul 13 04:23:55 2011
@@ -80,7 +80,7 @@
 class TestSplittingContext(unittest.TestCase):

     def setUp(self):
-        self._context = jsparser.Context(split_tests=True)
+        self._context = jsparser.Context(split_log=True)
         self._context.start_suite('suite')

     def test_getting_split_results(self):
=======================================
--- /utest/result/test_reporting.py     Mon Jul  4 04:25:40 2011
+++ /utest/result/test_reporting.py     Wed Jul 13 04:23:55 2011
@@ -134,10 +134,8 @@
         self._settings['SplitLog'] = True
         self._settings['Log'] = '/tmp/foo/log.bar.html'
         self._reporter.write_robot_results(resources.GOLDEN_OUTPUT)
-        self._assert_expected_split_tests('/tmp/foo/log.bar-1.js',
-                                          '/tmp/foo/log.bar-2.js',
-                                          '/tmp/foo/log.bar-3.js',
-                                          '/tmp/foo/log.bar-4.js')
+        expected = ('/tmp/foo/log.bar-%d.js' % i for i in range(1, 9))
+        self._assert_expected_split_tests(*expected)

     def _assert_expected_log(self, expected_file_name):
self.assertEquals(self._log_results['log_path'], expected_file_name)

Reply via email to