From 234273a46fa6514e1eb1ed39996cafdb25202551 Mon Sep 17 00:00:00 2001 From: Zeping Lee Date: Tue, 12 Mar 2024 16:31:41 +0800 Subject: [PATCH 1/2] Update machine formats --- .../machines/bugreports_SingleQuoteXml.json | 39 +++++++++++++++++++ .../fullstyles_ChicagoAuthorDateSimple.json | 2 +- .../machines/label_EditorTranslator1.json | 2 +- .../machines/label_MissingReturnsEmpty.json | 3 +- processor.py | 24 ++++++------ 5 files changed, 54 insertions(+), 16 deletions(-) create mode 100644 processor-tests/machines/bugreports_SingleQuoteXml.json diff --git a/processor-tests/machines/bugreports_SingleQuoteXml.json b/processor-tests/machines/bugreports_SingleQuoteXml.json new file mode 100644 index 0000000..344a29b --- /dev/null +++ b/processor-tests/machines/bugreports_SingleQuoteXml.json @@ -0,0 +1,39 @@ +{ + "abbreviations": false, + "bibentries": false, + "bibsection": false, + "citation_items": [ + [ + { + "id": "ITEM-1" + }, + { + "id": "ITEM-2" + } + ] + ], + "citations": false, + "csl": "\n", + "input": [ + { + "id": "ITEM-1", + "title": "Book Title", + "type": "book" + }, + { + "composer": [ + { + "family": "Smith", + "given": "Bob" + } + ], + "id": "ITEM-2", + "title": "Book-2 Title", + "type": "book" + } + ], + "mode": "citation", + "result": "[Cite with a composer ; O A. \"hello\" Book Title]", + "tags": false, + "version": "1.0" +} \ No newline at end of file diff --git a/processor-tests/machines/fullstyles_ChicagoAuthorDateSimple.json b/processor-tests/machines/fullstyles_ChicagoAuthorDateSimple.json index 9923536..0cb054b 100644 --- a/processor-tests/machines/fullstyles_ChicagoAuthorDateSimple.json +++ b/processor-tests/machines/fullstyles_ChicagoAuthorDateSimple.json @@ -4,7 +4,7 @@ "bibsection": false, "citation_items": false, "citations": false, - "csl": "\n", + "csl": "\n", "input": [ { "author": [ diff --git a/processor-tests/machines/label_EditorTranslator1.json b/processor-tests/machines/label_EditorTranslator1.json index d54f827..495d86c 100644 --- a/processor-tests/machines/label_EditorTranslator1.json +++ b/processor-tests/machines/label_EditorTranslator1.json @@ -58,7 +58,7 @@ } ], "mode": "bibliography", - "result": "
\n
1.\tИванов И.И. Пример оформления книги с редактором и переводчиком в одном лице : вид издания : in 5 vols. Vol. 2 / И.И. Иванов, П.П. Петров, С.С. Сидоров; ed & trans. Р.Р. Романов Дополнительно. – Тюмень: Дом, 2013. – 10. – 100 p.
\n
", + "result": "
\n
1.\tИванов И.И. Пример оформления книги с редактором и переводчиком в одном лице : вид издания : in 5 vols. Vol. 2 / И.И. Иванов, П.П. Петров, С.С. Сидоров; ed & trans. Р.Р. Романов Дополнительно. – Тюмень: Дом, 2013. – No. 10. – 100 p.
\n
", "tags": false, "version": "1.0" } \ No newline at end of file diff --git a/processor-tests/machines/label_MissingReturnsEmpty.json b/processor-tests/machines/label_MissingReturnsEmpty.json index beaab91..77eda6f 100644 --- a/processor-tests/machines/label_MissingReturnsEmpty.json +++ b/processor-tests/machines/label_MissingReturnsEmpty.json @@ -10,7 +10,7 @@ ] ], "citations": false, - "csl": "", + "csl": "", "input": [ { "author": [ @@ -19,7 +19,6 @@ "given": "Alan" } ], - "collection-number": 23, "id": "ITEM-1", "type": "book" } diff --git a/processor.py b/processor.py index ea31281..838a801 100755 --- a/processor.py +++ b/processor.py @@ -60,7 +60,7 @@ def fixEndings(s): class ApplyLicense: def __init__(self): - self.rex = "(?sm)^^(/\*.*?^\s*\*/\n*)(.*)" + self.rex = r"(?sm)^^(/\*.*?^\s*\*/\n*)(.*)" m = re.match(self.rex, fixEndings(open( os.path.join("src","load.js")).read()) ) if m: self.license = "%s\n" % m.group(1).strip() @@ -227,7 +227,7 @@ def __init__(self,opt,cp,hpath,testname,pos=0): self.CREATORS = ["author","editor","translator","recipient","interviewer"] self.CREATORS += ["composer","original-author","container-author","collection-editor"] self.RE_ELEMENT = '(?sm)^(.*>>=[^\n]*%s[^\n]+)(.*)(\n<<=.*%s.*)' - self.RE_FILENAME = '^[a-z]+_[a-zA-Z0-9]+\.txt$' + self.RE_FILENAME = r"^[a-z]+_[a-zA-Z0-9]+\.txt$" self.script = os.path.split(sys.argv[0])[1] self.pickle = ".".join((os.path.splitext( self.script )[0], "pkl")) self.data = {} @@ -330,7 +330,7 @@ def validate(self): tfd,tfilename = tempfile.mkstemp(dir=".") os.write(tfd,self.data["csl"].encode('utf8')) os.close(tfd) - + jfh = os.popen("%s %s -c %s %s" % (self.cp.get("jing", "command"), self.cp.get("jing", "path"),rnc_path,tfilename)) success = True plural = "" @@ -344,13 +344,13 @@ def validate(self): sys.exit() m = re.match(".*:([0-9]+):([0-9]+): *error:(.*)",line) if m: - if success: - print("\n##") - print("#### Error%s in CSL for test: %s" % (plural,self.hp)) - print("##\n") - success = False - print(" %s @ line %s" %(m.group(3).upper(),m.group(1))) - plural = "s" + if success: + print("\n##") + print("#### Error%s in CSL for test: %s" % (plural,self.hp)) + print("##\n") + success = False + print(" %s @ line %s" %(m.group(3).upper(),m.group(1))) + plural = "s" jfh.close() os.unlink(tfilename) if not success: @@ -370,8 +370,8 @@ def validate(self): pickler.dump( (opt, self.pos) ) sys.exit() - - + + if __name__ == "__main__": from optparse import OptionParser From cd1c065170a03b8b0d6aba66a086dc89873ccc30 Mon Sep 17 00:00:00 2001 From: Zeping Lee Date: Tue, 12 Mar 2024 16:13:48 +0800 Subject: [PATCH 2/2] Fixup two failing tests --- processor-tests/humans/label_EditorTranslator1.txt | 3 +-- processor-tests/humans/label_MissingReturnsEmpty.txt | 5 ++--- processor-tests/machines/label_EditorTranslator1.json | 2 +- processor-tests/machines/label_MissingReturnsEmpty.json | 4 ++-- 4 files changed, 6 insertions(+), 8 deletions(-) diff --git a/processor-tests/humans/label_EditorTranslator1.txt b/processor-tests/humans/label_EditorTranslator1.txt index 1a26bab..178627f 100644 --- a/processor-tests/humans/label_EditorTranslator1.txt +++ b/processor-tests/humans/label_EditorTranslator1.txt @@ -6,7 +6,7 @@ bibliography >>===== RESULT =====>>
-
1. Иванов И.И. Пример оформления книги с редактором и переводчиком в одном лице : вид издания : in 5 vols. Vol. 2 / И.И. Иванов, П.П. Петров, С.С. Сидоров; ed & trans. Р.Р. Романов Дополнительно. – Тюмень: Дом, 2013. – No. 10. – 100 p.
+
1. Иванов И.И. Пример оформления книги с редактором и переводчиком в одном лице : вид издания : in 5 vols. Vol. 2 / И.И. Иванов, П.П. Петров, С.С. Сидоров; ed & trans. Р.Р. Романов Дополнительно. – Тюмень: Дом, 2013. – No. 10. – 100 p.
<<===== RESULT =====<< @@ -610,4 +610,3 @@ _______________________________________________________________________________ >>===== VERSION =====>> 1.0 <<===== VERSION =====<< - diff --git a/processor-tests/humans/label_MissingReturnsEmpty.txt b/processor-tests/humans/label_MissingReturnsEmpty.txt index 41471d4..3e2aaa5 100644 --- a/processor-tests/humans/label_MissingReturnsEmpty.txt +++ b/processor-tests/humans/label_MissingReturnsEmpty.txt @@ -3,7 +3,7 @@ citation <<==== MODE ====<< >>==== RESULT ====>> -Aalto, 23 +Aalto <<==== RESULT ====<< >>==== CITATION-ITEMS ====>> @@ -17,7 +17,7 @@ Aalto, 23 <<==== CITATION-ITEMS ====<< >>==== CSL ====>> -", + "csl": "\n \n \n \n <updated>2009-08-10T04:49:00+09:00</updated>\n </info>\n <!-- locale>\n <term name=\"number\">nummie</term>\n </locale -->\n <macro name=\"author\">\n <names variable=\"author\">\n <name form=\"short\" />\n <label form=\"long\" prefix=\", \"/>\n </names>\n </macro>\n <citation>\n <layout delimiter=\"; \">\n <text macro=\"author\" />\n </layout>\n </citation>\n</style>", "input": [ { "author": [ @@ -24,7 +24,7 @@ } ], "mode": "citation", - "result": "Aalto, 23", + "result": "Aalto", "tags": false, "version": "1.0" } \ No newline at end of file