2 new revisions:

Revision: df0f84d68ae3
Branch:   default
Author:   Robot Framework Developers (robotframew...@gmail.com)
Date:     Mon Sep 30 10:32:19 2013 UTC
Log:      RestReader: Cleaner implementation to support includes....
http://code.google.com/p/robotframework/source/detail?r=df0f84d68ae3

Revision: dc71997438d0
Branch:   default
Author:   Robot Framework Developers (robotframew...@gmail.com)
Date:     Mon Sep 30 11:11:09 2013 UTC
Log:      RestReader: NamedTemporaryFile -> StringIO...
http://code.google.com/p/robotframework/source/detail?r=dc71997438d0

==============================================================================
Revision: df0f84d68ae3
Branch:   default
Author:   Robot Framework Developers (robotframew...@gmail.com)
Date:     Mon Sep 30 10:32:19 2013 UTC
Log:      RestReader: Cleaner implementation to support includes.

Also renamed document -> doctree and utf-8 -> UTF -> 8.

Update issue 1495
Use source_path argument instead of os.chdir. Also added includes with actual
test data to tests.
http://code.google.com/p/robotframework/source/detail?r=df0f84d68ae3

Added:
 /atest/testdata/parsing/data_formats/rest/include.rst
 /atest/testdata/parsing/data_formats/rest_directives/include.rst
Modified:
 /atest/testdata/parsing/data_formats/rest/sample.rst
 /atest/testdata/parsing/data_formats/rest_directives/sample.rst
 /src/robot/parsing/restreader.py

=======================================
--- /dev/null
+++ /atest/testdata/parsing/data_formats/rest/include.rst Mon Sep 30 10:32:19 2013 UTC
@@ -0,0 +1,9 @@
+Included file with some more test data.
+
+=============  =========  ==============  ===============
+  Metadata       Value         Value           Value
+=============  =========  ==============  ===============
+Default Tags   default1
+=============  =========  ==============  ===============
+
+The end.
=======================================
--- /dev/null
+++ /atest/testdata/parsing/data_formats/rest_directives/include.rst Mon Sep 30 10:32:19 2013 UTC
@@ -0,0 +1,9 @@
+Included file with some more test data.
+
+.. code:: robotframework
+
+   *** Setting ***
+   Default Tags    default1
+
+
+The end.
=======================================
--- /atest/testdata/parsing/data_formats/rest/sample.rst Fri Sep 27 13:02:37 2013 UTC +++ /atest/testdata/parsing/data_formats/rest/sample.rst Mon Sep 30 10:32:19 2013 UTC
@@ -1,4 +1,5 @@
 .. include:: empty.rest
+.. include:: include.rst

 ReST Test Data Example
 ======================
@@ -10,8 +11,8 @@
 =============  =========  ==============  ===============
   Metadata       Value         Value           Value
 =============  =========  ==============  ===============
-Document       A complex  testdata file   in rst format.
-Default Tags   default1   \               \
+Documentation  A complex  testdata file   in rst format.
+# Default      Tags       are in          include.rst
 Force Tags     force1     force2          \
 \              \          \               \
 Suite Setup    Log        Setup           \
=======================================
--- /atest/testdata/parsing/data_formats/rest_directives/sample.rst Fri Sep 27 13:02:37 2013 UTC +++ /atest/testdata/parsing/data_formats/rest_directives/sample.rst Mon Sep 30 10:32:19 2013 UTC
@@ -1,4 +1,5 @@
 .. include:: ../rest/empty.rest
+.. include:: include.rst

 ReST Test Data Example
 ======================
@@ -11,7 +12,7 @@
    *Setting*      *Value*

    Documentation  A complex testdata file   in rst format.
-   Default Tags   default1
+   # Default Tags are in include.rst
    Force Tags     force1   force2

    Suite Setup    Log   Setup
=======================================
--- /src/robot/parsing/restreader.py    Fri Sep 27 13:02:37 2013 UTC
+++ /src/robot/parsing/restreader.py    Mon Sep 30 10:32:19 2013 UTC
@@ -35,24 +35,17 @@
     class RestReader(object):

         def read(self, rstfile, rawdata):
- # TODO: Figure out a better way to handle relative paths in reST
-            # files than using os.chdir. Or at least clean up this code.
-            origdir = os.path.abspath('.')
-            os.chdir(os.path.dirname(rstfile.name))
-            try:
-                document = publish_doctree(
-                    rstfile.read(),
-                    settings_overrides={'input_encoding': 'utf-8'})
-            finally:
-                os.chdir(origdir)
-            store = RobotDataStorage(document)
+            doctree = publish_doctree(
+                rstfile.read(), source_path=rstfile.name,
+                settings_overrides={'input_encoding': 'UTF-8'})
+            store = RobotDataStorage(doctree)
             if store.has_data():
                 return self._read_text(store.get_data(), rawdata)
-            return self._read_html(document, rawdata)
+            return self._read_html(doctree, rawdata)

         def _read_text(self, data, rawdata):
             txtfile = tempfile.NamedTemporaryFile(suffix='.robot')
-            txtfile.write(data.encode('utf-8'))
+            txtfile.write(data.encode('UTF-8'))
             txtfile.seek(0)
             txtreader = TxtReader()
             try:
@@ -64,11 +57,11 @@
                 if os.path.isfile(txtfile.name):
                     os.remove(txtfile.name)

-        def _read_html(self, document, rawdata):
+        def _read_html(self, doctree, rawdata):
             htmlfile = tempfile.NamedTemporaryFile(suffix='.html')
             htmlfile.write(publish_from_doctree(
-                document, writer_name='html',
-                settings_overrides={'output_encoding': 'utf-8'}))
+                doctree, writer_name='html',
+                settings_overrides={'output_encoding': 'UTF-8'}))
             htmlfile.seek(0)
             htmlreader = HtmlReader()
             try:

==============================================================================
Revision: dc71997438d0
Branch:   default
Author:   Robot Framework Developers (robotframew...@gmail.com)
Date:     Mon Sep 30 11:11:09 2013 UTC
Log:      RestReader: NamedTemporaryFile -> StringIO

Update issue 1495
Realized we can simply use StringIO istead of temp files. That is a lot
simpler and ought to be also faster.
http://code.google.com/p/robotframework/source/detail?r=dc71997438d0

Modified:
 /src/robot/parsing/restreader.py

=======================================
--- /src/robot/parsing/restreader.py    Mon Sep 30 10:32:19 2013 UTC
+++ /src/robot/parsing/restreader.py    Mon Sep 30 11:11:09 2013 UTC
@@ -12,8 +12,7 @@
 #  See the License for the specific language governing permissions and
 #  limitations under the License.

-import os
-import tempfile
+from cStringIO import StringIO

 from robot.errors import DataError

@@ -44,34 +43,16 @@
             return self._read_html(doctree, rawdata)

         def _read_text(self, data, rawdata):
-            txtfile = tempfile.NamedTemporaryFile(suffix='.robot')
-            txtfile.write(data.encode('UTF-8'))
-            txtfile.seek(0)
-            txtreader = TxtReader()
-            try:
-                return txtreader.read(txtfile, rawdata)
-            finally:
-                # Ensure that the temp file gets closed and deleted:
-                if txtfile:
-                    txtfile.close()
-                if os.path.isfile(txtfile.name):
-                    os.remove(txtfile.name)
+            txtfile = StringIO(data.encode('UTF-8'))
+            return TxtReader().read(txtfile, rawdata)

         def _read_html(self, doctree, rawdata):
-            htmlfile = tempfile.NamedTemporaryFile(suffix='.html')
+            htmlfile = StringIO()
             htmlfile.write(publish_from_doctree(
                 doctree, writer_name='html',
                 settings_overrides={'output_encoding': 'UTF-8'}))
             htmlfile.seek(0)
-            htmlreader = HtmlReader()
-            try:
-                return htmlreader.read(htmlfile, rawdata)
-            finally:
-                # Ensure that the temp file gets closed and deleted:
-                if htmlfile:
-                    htmlfile.close()
-                if os.path.isfile(htmlfile.name):
-                    os.remove(htmlfile.name)
+            return HtmlReader().read(htmlfile, rawdata)

     return RestReader()

--

--- You received this message because you are subscribed to the Google Groups "robotframework-commit" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to robotframework-commit+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to