From 196c6fe068cfc5aef6775c1ece2f9f110d864aa3 Mon Sep 17 00:00:00 2001 From: smerten Date: Sat, 10 Jul 2010 08:13:27 +0000 Subject: [PATCH] Standard transformations are done. Tests added. HTML output works. git-svn-id: https://docutils.svn.sourceforge.net/svnroot/docutils/trunk@6374 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- sandbox/rstdiff/global.log | 91 ++++++ sandbox/rstdiff/rstdiff.py | 26 +- sandbox/rstdiff/tag.log | 2 +- sandbox/rstdiff/tests/html/expected/contents.html | 327 +++++++++++++++++++++ sandbox/rstdiff/tests/html/expected/footnote.html | 319 ++++++++++++++++++++ sandbox/rstdiff/tests/html/expected/reference.html | 316 ++++++++++++++++++++ .../rstdiff/tests/html/expected/textDifferent.html | 313 ++++++++++++++++++++ sandbox/rstdiff/tests/html/filterunit.cfg | 10 + sandbox/rstdiff/tests/html/input/contents.new.rst | 9 + sandbox/rstdiff/tests/html/input/contents.old.rst | 9 + sandbox/rstdiff/tests/html/input/footnote.new.rst | 3 + sandbox/rstdiff/tests/html/input/footnote.old.rst | 3 + sandbox/rstdiff/tests/html/input/reference.new.rst | 4 + sandbox/rstdiff/tests/html/input/reference.old.rst | 4 + .../rstdiff/tests/html/input/textDifferent.new.rst | 1 + .../rstdiff/tests/html/input/textDifferent.old.rst | 1 + 16 files changed, 1425 insertions(+), 13 deletions(-) create mode 100644 sandbox/rstdiff/tests/html/expected/contents.html create mode 100644 sandbox/rstdiff/tests/html/expected/footnote.html create mode 100644 sandbox/rstdiff/tests/html/expected/reference.html create mode 100644 sandbox/rstdiff/tests/html/expected/textDifferent.html create mode 100644 sandbox/rstdiff/tests/html/filterunit.cfg create mode 100644 sandbox/rstdiff/tests/html/input/contents.new.rst create mode 100644 sandbox/rstdiff/tests/html/input/contents.old.rst create mode 100644 sandbox/rstdiff/tests/html/input/footnote.new.rst create mode 100644 sandbox/rstdiff/tests/html/input/footnote.old.rst create mode 100644 sandbox/rstdiff/tests/html/input/reference.new.rst create mode 100644 sandbox/rstdiff/tests/html/input/reference.old.rst create mode 100644 sandbox/rstdiff/tests/html/input/textDifferent.new.rst create mode 100644 sandbox/rstdiff/tests/html/input/textDifferent.old.rst diff --git a/sandbox/rstdiff/global.log b/sandbox/rstdiff/global.log index 18566024d..0bd1eb671 100644 --- a/sandbox/rstdiff/global.log +++ b/sandbox/rstdiff/global.log @@ -1,4 +1,95 @@ ************************************** +Date: Fri Jul 9 19:53:45 CEST 2010 +Author: stefan +Tag: rstdiff_1_55 + +-------------------------------------- +Update of /home/stefan/vault/sm/rstdiff/tests +In directory theowa:/home/stefan/free/rstdiff/tests + +Modified Files: + Makefile rules.gmk + +-------------------------------------- +Update of /home/stefan/vault/sm/rstdiff/tests/html +In directory theowa:/home/stefan/free/rstdiff/tests/html + +Modified Files: + filterunit.cfg + +-------------------------------------- +Log Message: +Errors fixed by using proper options. All tests run. +************************************** +Date: Fri Jul 9 19:45:11 CEST 2010 +Author: stefan +Tag: rstdiff_1_54 + +-------------------------------------- +Update of /home/stefan/vault/sm/rstdiff +In directory theowa:/home/stefan/free/rstdiff + +Modified Files: + rstdiff.py + +-------------------------------------- +Log Message: +Standard transformations are applied. Fixes footnote and contents +problem in HTML. +************************************** +Date: Fri Jul 9 19:16:34 CEST 2010 +Author: stefan +Tag: rstdiff_1_53 + +-------------------------------------- +Update of /home/stefan/vault/sm/rstdiff +In directory theowa:/home/stefan/free/rstdiff + +Modified Files: + rstdiff.py + +-------------------------------------- +Log Message: +Debugging. Classes attribute in is set correct. +************************************** +Date: Fri Jul 9 19:03:48 CEST 2010 +Author: stefan +Tag: rstdiff_1_52 + +-------------------------------------- +Update of /home/stefan/vault/sm/rstdiff/tests +In directory theowa:/home/stefan/free/rstdiff/tests + +Modified Files: + rules.gmk + +-------------------------------------- +Update of /home/stefan/vault/sm/rstdiff/tests/html +In directory theowa:/home/stefan/free/rstdiff/tests/html + +Added Files: + Makefile filterunit.cfg + +-------------------------------------- +Update of /home/stefan/vault/sm/rstdiff/tests/html/input +In directory theowa:/home/stefan/free/rstdiff/tests/html/input + +Added Files: + contents.new.rst contents.old.rst footnote.new.rst + footnote.old.rst reference.new.rst reference.old.rst + textDifferent.new.rst textDifferent.old.rst + +-------------------------------------- +Update of /home/stefan/vault/sm/rstdiff/tests/html/source +In directory theowa:/home/stefan/free/rstdiff/tests/html/source + +Added Files: + contents.rst footnote.rst reference.rst textDifferent.rst + +-------------------------------------- +Log Message: +Added tests for HTML writer decovering errors. All these tests fail. +************************************** Date: Sat Jul 3 18:42:26 CEST 2010 Author: stefan Tag: rstdiff_1_51 diff --git a/sandbox/rstdiff/rstdiff.py b/sandbox/rstdiff/rstdiff.py index 17e08039d..6866d332f 100755 --- a/sandbox/rstdiff/rstdiff.py +++ b/sandbox/rstdiff/rstdiff.py @@ -432,10 +432,7 @@ class DocutilsDispatcher(HashableNodeImpl): return self.dispatchClass('copyChild', node, newType) def copyChild_UNKNOWN(self, node, newType): - copy = node.deepcopy() - if newType: - copy['classes'].append(self.newType2Class(newType)) - return copy + return self.setNewType(node.deepcopy(), newType) def copyChildren(self, head, tail, root, newType): """Return a range of new nodes copied from [ `head` ] + `tail` under @@ -499,9 +496,11 @@ class DocutilsDispatcher(HashableNodeImpl): ########################################################################### # Helpers - def newType2Class(self, newType): - """Return a class name for `newType`.""" - return "change-%s" % ( newType, ) + def setNewType(self, node, newType): + """Set a class on `node` for `newType` if set. Returns `node`.""" + if newType: + node['classes'].append("change-%s" % ( newType, )) + return node ########################################################################### ########################################################################### @@ -547,7 +546,8 @@ class DocutilsDispatcher(HashableNodeImpl): childEq_White = rootEq_White def copyChildren_Text(self, head, tail, root, newType): - inline = nodes.inline(classes=self.newType2Class(newType)) + inline = nodes.inline() + self.setNewType(inline, newType) inline.extend([ head, ] + tail) return [ inline, ] @@ -582,6 +582,7 @@ def processCommandLine(): new_reporter('', pub.settings).severe("Internal error: Mismatch of pre-parsed (%r) and real (%r) writer" % ( preWriter, pub.settings.writer, )) + pub.set_destination() return pub def readTree(pub, sourceName): @@ -589,7 +590,10 @@ def readTree(pub, sourceName): # Reset reader - just in case it keeps state from a previous invocation pub.set_reader('standalone', None, 'restructuredtext') pub.set_source(None, sourceName) - return pub.reader.read(pub.source, pub.parser, pub.settings) + pub.document = None + pub.document = pub.reader.read(pub.source, pub.parser, pub.settings) + pub.apply_transforms() + return pub.document def doDiff(hashableNodeImpl, oldTree, newTree): """Create a difference from `oldTree` to `newTree` using @@ -697,13 +701,11 @@ if __name__ == '__main__': oldTree = readTree(pub, pub.settings._old_source) newTree = readTree(pub, pub.settings._new_source) - # TODO Standard transformations should be run probably - Text2Words(oldTree).apply() Text2Words(newTree).apply() diffDoc = createDiff(oldTree, newTree) Words2Text(diffDoc).apply() - pub.set_destination() pub.writer.write(diffDoc, pub.destination) + pub.writer.assemble_parts() diff --git a/sandbox/rstdiff/tag.log b/sandbox/rstdiff/tag.log index e3ad78805..0add360b9 100644 --- a/sandbox/rstdiff/tag.log +++ b/sandbox/rstdiff/tag.log @@ -1 +1 @@ -rstdiff_1_51 +rstdiff_1_55 diff --git a/sandbox/rstdiff/tests/html/expected/contents.html b/sandbox/rstdiff/tests/html/expected/contents.html new file mode 100644 index 000000000..fa9e52651 --- /dev/null +++ b/sandbox/rstdiff/tests/html/expected/contents.html @@ -0,0 +1,327 @@ + + + + + + + + + + + + + diff --git a/sandbox/rstdiff/tests/html/expected/footnote.html b/sandbox/rstdiff/tests/html/expected/footnote.html new file mode 100644 index 000000000..5c9e459b1 --- /dev/null +++ b/sandbox/rstdiff/tests/html/expected/footnote.html @@ -0,0 +1,319 @@ + + + + + + + + + + +
+ + +

A text [1].

+ + + + + +
[1]A footnote.
+
+ + diff --git a/sandbox/rstdiff/tests/html/expected/reference.html b/sandbox/rstdiff/tests/html/expected/reference.html new file mode 100644 index 000000000..ae3e6cd03 --- /dev/null +++ b/sandbox/rstdiff/tests/html/expected/reference.html @@ -0,0 +1,316 @@ + + + + + + + + + + +
+ + + +
+ + diff --git a/sandbox/rstdiff/tests/html/expected/textDifferent.html b/sandbox/rstdiff/tests/html/expected/textDifferent.html new file mode 100644 index 000000000..9980117b9 --- /dev/null +++ b/sandbox/rstdiff/tests/html/expected/textDifferent.html @@ -0,0 +1,313 @@ + + + + + + + + + + +
+ + +

SomeA changed line.

+
+ + diff --git a/sandbox/rstdiff/tests/html/filterunit.cfg b/sandbox/rstdiff/tests/html/filterunit.cfg new file mode 100644 index 000000000..430139648 --- /dev/null +++ b/sandbox/rstdiff/tests/html/filterunit.cfg @@ -0,0 +1,10 @@ +# Tests with the HTML writer + +command = ../../rstdiff.py + +inputExtension = .old.rst +inputExtension = .new.rst +inputCount = 2 +expectedExtension = .html + +options = --writer=html --no-doc-title $1< $2< diff --git a/sandbox/rstdiff/tests/html/input/contents.new.rst b/sandbox/rstdiff/tests/html/input/contents.new.rst new file mode 100644 index 000000000..afecbe5ea --- /dev/null +++ b/sandbox/rstdiff/tests/html/input/contents.new.rst @@ -0,0 +1,9 @@ +.. sectnum:: + +.. contents:: + +Header +====== + +Another header +-------------- diff --git a/sandbox/rstdiff/tests/html/input/contents.old.rst b/sandbox/rstdiff/tests/html/input/contents.old.rst new file mode 100644 index 000000000..afecbe5ea --- /dev/null +++ b/sandbox/rstdiff/tests/html/input/contents.old.rst @@ -0,0 +1,9 @@ +.. sectnum:: + +.. contents:: + +Header +====== + +Another header +-------------- diff --git a/sandbox/rstdiff/tests/html/input/footnote.new.rst b/sandbox/rstdiff/tests/html/input/footnote.new.rst new file mode 100644 index 000000000..c044acff3 --- /dev/null +++ b/sandbox/rstdiff/tests/html/input/footnote.new.rst @@ -0,0 +1,3 @@ +A text [#]_. + +.. [#] A footnote. diff --git a/sandbox/rstdiff/tests/html/input/footnote.old.rst b/sandbox/rstdiff/tests/html/input/footnote.old.rst new file mode 100644 index 000000000..c044acff3 --- /dev/null +++ b/sandbox/rstdiff/tests/html/input/footnote.old.rst @@ -0,0 +1,3 @@ +A text [#]_. + +.. [#] A footnote. diff --git a/sandbox/rstdiff/tests/html/input/reference.new.rst b/sandbox/rstdiff/tests/html/input/reference.new.rst new file mode 100644 index 000000000..fc904509f --- /dev/null +++ b/sandbox/rstdiff/tests/html/input/reference.new.rst @@ -0,0 +1,4 @@ +Header +====== + +Reference to header_. diff --git a/sandbox/rstdiff/tests/html/input/reference.old.rst b/sandbox/rstdiff/tests/html/input/reference.old.rst new file mode 100644 index 000000000..fc904509f --- /dev/null +++ b/sandbox/rstdiff/tests/html/input/reference.old.rst @@ -0,0 +1,4 @@ +Header +====== + +Reference to header_. diff --git a/sandbox/rstdiff/tests/html/input/textDifferent.new.rst b/sandbox/rstdiff/tests/html/input/textDifferent.new.rst new file mode 100644 index 000000000..4e3e1cc26 --- /dev/null +++ b/sandbox/rstdiff/tests/html/input/textDifferent.new.rst @@ -0,0 +1 @@ +A changed line. diff --git a/sandbox/rstdiff/tests/html/input/textDifferent.old.rst b/sandbox/rstdiff/tests/html/input/textDifferent.old.rst new file mode 100644 index 000000000..443e38aaf --- /dev/null +++ b/sandbox/rstdiff/tests/html/input/textDifferent.old.rst @@ -0,0 +1 @@ +Some line. -- 2.11.4.GIT