From e5ac0132164af21bbcba44dec64d5970daf24f28 Mon Sep 17 00:00:00 2001 From: c-okelly Date: Tue, 23 Oct 2018 22:11:27 +0100 Subject: [PATCH] Udpate travis and setup.py to support python version 3.3and up. Update tests and parsers so that multi question are handled correctly --- .travis.yml | 1 - exampleOrgFiles/flatTopics.org | 15 +++++++++++ .../ankiConnectWrapper/AnkiConnector.py | 7 ++++- org_to_anki/org_parser/DeckBuilder.py | 1 + org_to_anki/org_parser/ParserUtils.py | 1 + setup.py | 2 +- tests/testAnkiConnector.py | 26 +++++++++++++++++++ tests/testData/longBasic.org | 2 -- 8 files changed, 50 insertions(+), 5 deletions(-) create mode 100644 exampleOrgFiles/flatTopics.org diff --git a/.travis.yml b/.travis.yml index 39743e6..a176e1a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,5 @@ language: python python: - - "3.3" - "3.4" - "3.5" - "3.6" diff --git a/exampleOrgFiles/flatTopics.org b/exampleOrgFiles/flatTopics.org new file mode 100644 index 0000000..cbb77c7 --- /dev/null +++ b/exampleOrgFiles/flatTopics.org @@ -0,0 +1,15 @@ +# This will result in only a single deck being produced +# The topics (e.g => Capital cities) is added to the top of each question in the finished card +#fileType = flatTopics + +* Capital cites +** What is the capital of Ireland +*** Dublin +* Languages of countries +** What are the main languages in Ireland +*** English +*** Irish +* Definitions of words +#type=Basic (and reversed card) +** Definition of a box +*** A container with a flat base and sides, typically square or rectangular and having a lid. \ No newline at end of file diff --git a/org_to_anki/ankiConnectWrapper/AnkiConnector.py b/org_to_anki/ankiConnectWrapper/AnkiConnector.py index b33316e..853439d 100644 --- a/org_to_anki/ankiConnectWrapper/AnkiConnector.py +++ b/org_to_anki/ankiConnectWrapper/AnkiConnector.py @@ -87,6 +87,7 @@ def _buildNote(self, ankiQuestion: AnkiQuestion): else: deckName = self._getFullDeckPath(ankiQuestion.deckName) + # TODO: Verify model name correctly and use parameters if ankiQuestion.getParameter("type") is not None: modelName = ankiQuestion.getParameter("type") else: @@ -104,12 +105,16 @@ def _buildNote(self, ankiQuestion: AnkiQuestion): return note def _createQuestionString(self, questions:[str]): + if len(questions) == 1: - return questions[0] + question = questions[0].replace("\n", "
") + return question else: questionString = "" for q in questions: + q = q.strip().replace("\n", "
") questionString += q + "
" + return questionString def _createAnswerString(self, answers: [str], bulletPoints: bool=True): diff --git a/org_to_anki/org_parser/DeckBuilder.py b/org_to_anki/org_parser/DeckBuilder.py index 58ee45f..6fb3a02 100644 --- a/org_to_anki/org_parser/DeckBuilder.py +++ b/org_to_anki/org_parser/DeckBuilder.py @@ -18,6 +18,7 @@ def buildDeck(self, questions: [str], deckName: str, filePath: str, fileType: st deck = self._buildNewDeck(questions, deckName, filePath) elif fileType == 'topics': deck = self._buildTopics(questions, deckName, filePath) + # TODO: Remove lower elif fileType.lower() == 'flattopics': deck = self._buildFlatTopics(questions, deckName, filePath) else: diff --git a/org_to_anki/org_parser/ParserUtils.py b/org_to_anki/org_parser/ParserUtils.py index 165436a..ee8b3ce 100644 --- a/org_to_anki/org_parser/ParserUtils.py +++ b/org_to_anki/org_parser/ParserUtils.py @@ -17,6 +17,7 @@ def convertLineToParamters(line: str): if "=" in item: item = item.strip() parts = item.split("=") + # TODO: Make lowercase parameters parameters[parts[0].strip()] = parts[1].strip() return parameters diff --git a/setup.py b/setup.py index 17cfc0b..3917905 100644 --- a/setup.py +++ b/setup.py @@ -6,7 +6,7 @@ author='Conor OKelly', author_email='okellyconor@gmail.com', url='https://github.com/c-okelly/org_to_anki', - python_requires='>3.3', + python_requires='>3.4', install_requires=['requests'], tests_require=['responses', 'nose', 'coverage'], test_suite="nose.collector", diff --git a/tests/testAnkiConnector.py b/tests/testAnkiConnector.py index 923880c..a235a23 100644 --- a/tests/testAnkiConnector.py +++ b/tests/testAnkiConnector.py @@ -50,3 +50,29 @@ def testBuildNoteForSublists(): expectedString = "" assert(answerString == expectedString) + +### Next two tests ensure that questions that have an internal multiline string are correctly html formatted ### +def testMultiLineQuestionLine(): + + q = AnkiQuestion("Capital Cities\nCapital of dublin") + q.addAnswer("Dublin") + deck = AnkiDeck("Capitals") + deck.addQuestion(q) + + a = AnkiConnector() + noteData = a._buildNote(deck.getQuestions()[0]) + + assert(noteData["fields"]["Front"] == "Capital Cities
Capital of dublin") + +def testManyMultiLineQuestionLines(): + + q = AnkiQuestion("Capital Cities\nCapital of dublin") + q.addQuestion("Second line") + q.addAnswer("Dublin") + deck = AnkiDeck("Capitals") + deck.addQuestion(q) + + a = AnkiConnector() + noteData = a._buildNote(deck.getQuestions()[0]) + + assert(noteData["fields"]["Front"] == "Capital Cities
Capital of dublin
Second line
") \ No newline at end of file diff --git a/tests/testData/longBasic.org b/tests/testData/longBasic.org index 8980f35..8170907 100644 --- a/tests/testData/longBasic.org +++ b/tests/testData/longBasic.org @@ -279,8 +279,6 @@ ** union file system * Create volume from dockerFile ** VOLUME -* How to use -v flag for mount directory from host -** -v /home/cokelly/path:/file/from/volume * How to share data between docker images ** Use flag => --volumes-from vol-name * Create docker containers for data storage? Best practices?