Skip to content

Commit

Permalink
Udpate travis and setup.py to support python version 3.3and up. Updat…
Browse files Browse the repository at this point in the history
…e tests and parsers so that multi question are handled correctly
  • Loading branch information
c-okelly committed Oct 23, 2018
1 parent 3e654ca commit e5ac013
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 5 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
language: python
python:
- "3.3"
- "3.4"
- "3.5"
- "3.6"
Expand Down
15 changes: 15 additions & 0 deletions exampleOrgFiles/flatTopics.org
Original file line number Diff line number Diff line change
@@ -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.
7 changes: 6 additions & 1 deletion org_to_anki/ankiConnectWrapper/AnkiConnector.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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", "<br>")
return question
else:
questionString = ""
for q in questions:
q = q.strip().replace("\n", "<br>")
questionString += q + " <br>"
return questionString


def _createAnswerString(self, answers: [str], bulletPoints: bool=True):
Expand Down
1 change: 1 addition & 0 deletions org_to_anki/org_parser/DeckBuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions org_to_anki/org_parser/ParserUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
26 changes: 26 additions & 0 deletions tests/testAnkiConnector.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,29 @@ def testBuildNoteForSublists():

expectedString = "<ul style='list-style-position: inside;'><li>first answer</li><ul style='list-style-position: inside;'><li>sublist 1</li><ul style='list-style-position: inside;'><li>sublist2</li></ul><li>back to sublist1</li></ul><li>second answer</li></ul>"
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<br>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<br>Capital of dublin <br>Second line <br>")
2 changes: 0 additions & 2 deletions tests/testData/longBasic.org
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down

0 comments on commit e5ac013

Please sign in to comment.