proper unit tests
This commit is contained in:
parent
16d67c49f4
commit
7986ab6bab
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
multiple-choice-quiz-csv-to-marp-markdown-slides-converter
|
multiple-choice-quiz-csv-to-marp-markdown-slides-converter
|
||||||
|
|
||||||
|
this tool can convert a csv file into a [Marp](https://marpit.marp.app/) markdown slides, which can subsequently be converted into a pdf file.
|
||||||
|
|
||||||
csv needs to have the following format
|
csv needs to have the following format
|
||||||
````
|
````
|
||||||
@ -10,7 +11,6 @@ Kategorie 1: Zitate ( Wer hat's gesagt?),,,,
|
|||||||
````
|
````
|
||||||
Strings surrounded with quotation marks
|
Strings surrounded with quotation marks
|
||||||
|
|
||||||
|
|
||||||
docker run --rm --init -v $PWD:/home/marp/app/ -e LANG=$LANG marpteam/marp-cli slide-deck.md --pdf
|
docker run --rm --init -v $PWD:/home/marp/app/ -e LANG=$LANG marpteam/marp-cli slide-deck.md --pdf
|
||||||
powerpoint export is also possible with --pptx
|
powerpoint export is also possible with --pptx
|
||||||
|
|
||||||
|
16
converter.py
16
converter.py
@ -1,14 +1,13 @@
|
|||||||
import calendar
|
|
||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
|
|
||||||
|
|
||||||
# def file_exists(filename):
|
# def file_exists(filename):
|
||||||
# if os.path.exists(filename):
|
# if os.path.exists(filename):
|
||||||
# print('Note: Diary \'' + filename + '\' already exists. Will not be modified.')
|
# print('Note: Diary \'' + filename + '\' already exists. Will not be modified.')
|
||||||
# return True
|
# return True
|
||||||
# return False
|
# return False
|
||||||
NUMBER_OF_ANSWERS = 5
|
NUMBER_OF_ANSWERS = 5
|
||||||
|
BASE_FODLER = "test_data"
|
||||||
|
|
||||||
|
|
||||||
class QuestionAndAnswers:
|
class QuestionAndAnswers:
|
||||||
@ -29,13 +28,16 @@ def convert(csv_path, output_pdf=False):
|
|||||||
|
|
||||||
def write_markdown_file(csv_path):
|
def write_markdown_file(csv_path):
|
||||||
# csv_path = "quiz-example.csv"
|
# csv_path = "quiz-example.csv"
|
||||||
markdown_path = "slide-deck.md"
|
OUTPUT_FODLER = "output"
|
||||||
|
markdown_filename = "slide-deck.md"
|
||||||
|
markdown_path = os.path.join(OUTPUT_FODLER, markdown_filename)
|
||||||
|
|
||||||
# read CSV
|
# read CSV
|
||||||
list_of_q_and_as = []
|
list_of_q_and_as = []
|
||||||
|
|
||||||
with open(csv_path, 'r', encoding='UTF-8') as csv_file:
|
with open(csv_path, 'r', encoding='UTF-8') as csv_file:
|
||||||
data = csv_file.readlines()
|
data = csv_file.readlines()
|
||||||
current_category = "bla"
|
current_category = ""
|
||||||
for line in data:
|
for line in data:
|
||||||
if line.startswith("Kategorie"):
|
if line.startswith("Kategorie"):
|
||||||
name_of_category = line.split(",")[0]
|
name_of_category = line.split(",")[0]
|
||||||
@ -108,8 +110,12 @@ def to_pdf(filename):
|
|||||||
client = docker.from_env()
|
client = docker.from_env()
|
||||||
current_dir = os.getcwd()
|
current_dir = os.getcwd()
|
||||||
print(current_dir)
|
print(current_dir)
|
||||||
|
|
||||||
|
OUTPUT_FODLER = "output"
|
||||||
|
output_folder_path = os.path.join(current_dir, OUTPUT_FODLER)
|
||||||
|
|
||||||
# https://docker-py.readthedocs.io/en/stable/containers.html
|
# https://docker-py.readthedocs.io/en/stable/containers.html
|
||||||
client.containers.run('marpteam/marp-cli', '{} --pdf'.format(filename), volumes=[current_dir + ':/home/marp/app/'],
|
client.containers.run('marpteam/marp-cli', '{} --pdf'.format(filename), volumes=[output_folder_path + ':/home/marp/app/'],
|
||||||
name="marp", detach=True, remove=True, init=True)
|
name="marp", detach=True, remove=True, init=True)
|
||||||
|
|
||||||
container = client.containers.get('marp')
|
container = client.containers.get('marp')
|
||||||
|
@ -2,13 +2,13 @@ Kategorie 1: Zitate ( Wer hat's gesagt?),,,,
|
|||||||
(1) Probleme sind nur Dorninge Chancen,Jan Böhmermann,Christian Lindner,Elon Musk,Pable Escobar
|
(1) Probleme sind nur Dorninge Chancen,Jan Böhmermann,Christian Lindner,Elon Musk,Pable Escobar
|
||||||
(2) Niemand hat die Absicht eine Mauer zu errichten,Erich Honecker,Lothar de Maizière,Walter Ulbricht,Donald Trump
|
(2) Niemand hat die Absicht eine Mauer zu errichten,Erich Honecker,Lothar de Maizière,Walter Ulbricht,Donald Trump
|
||||||
(3) Auf den Alkohol – den Ursprung und die Lösung sämtlicher Lebensprobleme,Boris Jelzin,Homer Simpson,Prinz Harry,Charlie Sheen
|
(3) Auf den Alkohol – den Ursprung und die Lösung sämtlicher Lebensprobleme,Boris Jelzin,Homer Simpson,Prinz Harry,Charlie Sheen
|
||||||
(4) Ich so zu mein homie: ich komme später, ich steck noch im Verkehr Er: mit dem Auto? Ich: nein in 1 bitch. Geschlechtsverkehr!",Moneyboy,Oliver Pocher,Manny Marc,Dieter Bohlen
|
(4) Ich so zu mein homie: ich komme später, ich steck noch im Verkehr Er: mit dem Auto? Ich: nein in 1 bitch. Geschlechtsverkehr!,Moneyboy,Oliver Pocher,Manny Marc,Dieter Bohlen
|
||||||
(5) Aus großer Macht folgt große Verantwortung.,Neil Armstrong,Jesus Christus,Chuck Norris,Ben Parker aus Spiderman
|
(5) Aus großer Macht folgt große Verantwortung.,Neil Armstrong,Jesus Christus,Chuck Norris,Ben Parker aus Spiderman
|
||||||
(6) Wenn ich über steuer- und erbrechtliche Anerkennung von homosexuellen Paaren diskutiere, dann kann ich gleich über Teufelsanbetung diskutieren.",Rainer Maria Woelki,Papst Benedikt XVI,Friedrich Merz,Edmund Stoiber
|
(6) Wenn ich über steuer- und erbrechtliche Anerkennung von homosexuellen Paaren diskutiere, dann kann ich gleich über Teufelsanbetung diskutieren.,Rainer Maria Woelki,Papst Benedikt XVI,Friedrich Merz,Edmund Stoiber
|
||||||
(7) Mir hat auch niemand gesagt, wie man Kapitalist wird.",Dagobert Duck,Christian Lindner,Jeff Bezos,Queen Elisabeth II.
|
(7) Mir hat auch niemand gesagt, wie man Kapitalist wird.,Dagobert Duck,Christian Lindner,Jeff Bezos,Queen Elisabeth II.
|
||||||
(8) Geh dein Weg, leb dein Leben, sei du selbst, Fick deine Mutter",Money Boy,Farid Bang,KIZ (wer von denen?),Immanuel Kant
|
(8) Geh dein Weg, leb dein Leben, sei du selbst, Fick deine Mutter,Money Boy,Farid Bang,KIZ (wer von denen?),Immanuel Kant
|
||||||
(9) Man muss Gesetze kompliziert machen. Dann fällt es nicht so auf.,Horst Seehofer,Wladimir Putin,Erich Honecker,Boris Johnson
|
(9) Man muss Gesetze kompliziert machen. Dann fällt es nicht so auf.,Horst Seehofer,Wladimir Putin,Erich Honecker,Boris Johnson
|
||||||
(10) Chef sein ist wie ein Wecker. Keiner will ihn, jeder hasst ihn, aber wenn er nicht da ist, dann machen alle Schnarch.",Paul Ditter,Bernd Stromberg,Markus Stockschläder,Jürgen Klopp
|
(10) Chef sein ist wie ein Wecker. Keiner will ihn, jeder hasst ihn, aber wenn er nicht da ist, dann machen alle Schnarch.,Paul Ditter,Bernd Stromberg,Markus Stockschläder,Jürgen Klopp
|
||||||
,,,,
|
,,,,
|
||||||
Kategorie 2: Unnützes Wissen,,,,
|
Kategorie 2: Unnützes Wissen,,,,
|
||||||
(1) Was wird als Ursache für die beschleunigte Expansion des Universums vermutet?,Antimaterie,Dunkle Materie,Dunkle Energie,Schwarze Magie
|
(1) Was wird als Ursache für die beschleunigte Expansion des Universums vermutet?,Antimaterie,Dunkle Materie,Dunkle Energie,Schwarze Magie
|
Can't render this file because it contains an unexpected character in line 5 and column 131.
|
58
tests.py
58
tests.py
@ -1,7 +1,7 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
import os
|
import os
|
||||||
import unittest
|
import unittest
|
||||||
import shutil
|
from time import sleep
|
||||||
|
|
||||||
import converter
|
import converter
|
||||||
|
|
||||||
@ -10,49 +10,55 @@ class TestDiary(unittest.TestCase):
|
|||||||
|
|
||||||
# BASE_FODLER = "test_data"
|
# BASE_FODLER = "test_data"
|
||||||
|
|
||||||
# def test_basic_csv_input(self):
|
def test_basic_csv_input(self):
|
||||||
# # python command_line 2021-01
|
# python command_line 2021-01
|
||||||
# BASE_FODLER = "test_data"
|
BASE_FODLER = "test_data"
|
||||||
# converter.write_markdown_file('quiz-example.csv')
|
OUTPUT_FODLER = "output"
|
||||||
# # assert file was created
|
|
||||||
# assert(os.path.exists(os.path.join(BASE_FODLER, "slide-deck.md")))
|
file_path = os.path.join(BASE_FODLER, "quiz-example.csv")
|
||||||
|
converter.write_markdown_file(file_path)
|
||||||
|
# assert file was created
|
||||||
|
assert (os.path.exists(os.path.join(OUTPUT_FODLER, "slide-deck.md")))
|
||||||
|
|
||||||
def test_csv_input_with_categories(self):
|
def test_csv_input_with_categories(self):
|
||||||
# python command_line 2021-01
|
# python command_line 2021-01
|
||||||
BASE_FODLER = "test_data"
|
BASE_FODLER = "test_data"
|
||||||
converter.write_markdown_file('quiz-example-with-category.csv')
|
OUTPUT_FODLER = "output"
|
||||||
|
|
||||||
|
file_path = os.path.join(BASE_FODLER, "quiz-example-with-category.csv")
|
||||||
|
# converter.write_markdown_file('test_data/quiz-example-with-category.csv')
|
||||||
|
converter.write_markdown_file(file_path)
|
||||||
# assert file was created
|
# assert file was created
|
||||||
assert(os.path.exists(os.path.join(BASE_FODLER, "slide-deck.md")))
|
assert (os.path.exists(os.path.join(OUTPUT_FODLER, "slide-deck.md")))
|
||||||
|
|
||||||
def test_csv_input_with_categories_and_empty_rows(self):
|
def test_csv_input_with_categories_and_empty_rows(self):
|
||||||
# python command_line 2021-01
|
# python command_line 2021-01
|
||||||
BASE_FODLER = "test_data"
|
BASE_FODLER = "test_data"
|
||||||
converter.write_markdown_file('quiz-example-with-category-and-empty-rows.csv')
|
OUTPUT_FODLER = "output"
|
||||||
|
|
||||||
|
file_path = os.path.join(BASE_FODLER, "quiz-example-with-category-and-empty-rows.csv")
|
||||||
|
converter.write_markdown_file(file_path)
|
||||||
# assert file was created
|
# assert file was created
|
||||||
assert(os.path.exists(os.path.join(BASE_FODLER, "slide-deck.md")))
|
assert (os.path.exists(os.path.join(OUTPUT_FODLER, "slide-deck.md")))
|
||||||
|
|
||||||
def test_to_pdf(self):
|
def test_to_pdf(self):
|
||||||
# python command_line 2021-01
|
# python command_line 2021-01
|
||||||
BASE_FODLER = "test_data"
|
OUTPUT_FODLER = "output"
|
||||||
converter.to_pdf("slide-deck.md")
|
converter.to_pdf("slide-deck.md")
|
||||||
|
sleep(5) # wait for docker container to finish conversion
|
||||||
|
|
||||||
# assert file was created
|
# assert file was created
|
||||||
assert(os.path.exists(os.path.join(BASE_FODLER, "slide-deck.md")))
|
assert (os.path.exists(os.path.join(OUTPUT_FODLER, "slide-deck.pdf")))
|
||||||
|
|
||||||
# def test_create_month_file_january(self):
|
def setUp(self):
|
||||||
# # python command_line 2021-01
|
print("test started...")
|
||||||
# BASE_FODLER = "test_data"
|
BASE_FODLER = "test_data"
|
||||||
# diary.parse_input('2021-01', BASE_FODLER)
|
OUTPUT_FODLER = "output"
|
||||||
# # assert file was created
|
|
||||||
# assert(os.path.exists(os.path.join(BASE_FODLER, "01_2021.md")))
|
|
||||||
|
|
||||||
|
if not os.path.exists(BASE_FODLER):
|
||||||
# def setUp(self):
|
os.makedirs(BASE_FODLER)
|
||||||
# print("test started...")
|
if not os.path.exists(OUTPUT_FODLER):
|
||||||
# BASE_FODLER = "test_data"
|
os.makedirs(OUTPUT_FODLER)
|
||||||
# # bla = os.path.join(BASE_FODLER, "12_2020.md")
|
|
||||||
# if not os.path.exists(BASE_FODLER):
|
|
||||||
# os.makedirs(BASE_FODLER)
|
|
||||||
|
|
||||||
# def tearDown(self):
|
# def tearDown(self):
|
||||||
# # pass
|
# # pass
|
||||||
|
Loading…
x
Reference in New Issue
Block a user