def test_cases_with_html(tmpdir, name): slider = Slider() pages = slider.parse(os.path.join('cases', '{}.md'.format(name))) with open(os.path.join('cases', 'dom', '{}.json'.format(name))) as fh: assert pages == json.load(fh) target_dir = str(tmpdir) print(target_dir) slider.generate_html_files(target_dir) compare_dirs(target_dir, os.path.join('cases', 'html', name), name)
def test_other_dir(tmpdir): root = str(tmpdir) cwd = os.getcwd() os.chdir(root) from slider import Slider, SliderError slider = Slider() target_dir = os.path.join(root, 'html') os.mkdir(target_dir) pages = slider.parse(os.path.join(cwd, 'cases', 'all.md')) slider.generate_html_files(target_dir) compare_dirs(target_dir, os.path.join(cwd, 'cases', 'html', 'all'), 'all') data = slider.process_yml(os.path.join(cwd, 'cases', 'multi.yml')) assert data == {} os.chdir(cwd)
def test_md_to_html_no_file_extension(tmpdir, name): slider = Slider() md_file = os.path.join('cases', 'input', '{}.md'.format(name)) pages = slider.parse(md_file) with open(os.path.join('cases', 'output', 'dom', '{}.json'.format(name))) as fh: assert pages == json.load(fh) target_dir = str(tmpdir) print(target_dir) html = OnePage( chapter=pages, includes=os.path.dirname(md_file), ) html.generate_html_files(target_dir) compare_dirs(target_dir, os.path.join('cases', 'output', 'plain_html', name), name)
def test_other_dir(tmpdir): root = str(tmpdir) original = os.getcwd() with cwd(root): slider = Slider() target_dir = os.path.join(root, 'html') os.mkdir(target_dir) md_file = os.path.join(original, 'cases', 'input', 'all.md') pages = slider.parse(md_file) with open(os.path.join(original, 'cases/output/dom/all.json')) as fh: expected = json.load(fh) assert expected == pages html = OnePage( chapter=pages, includes=os.path.dirname(md_file), ext='html', ) html.generate_html_files(target_dir) compare_dirs(target_dir, os.path.join(original, 'cases', 'output', 'html', 'all'), 'all')
def test_exceptions(tmpdir): slider = Slider() path = os.path.join('cases', 'no-chapter-title.md') with pytest.raises(Exception) as exinfo: slider.parse(path) assert exinfo.type == SliderError assert str(exinfo.value) == 'Chapter title is missing in {}'.format(path) path = os.path.join('cases', 'no-chapter-id.md') with pytest.raises(Exception) as exinfo: slider.parse(path) assert exinfo.type == SliderError assert str(exinfo.value) == 'Chapter id is missing in {}'.format(path) path = os.path.join('cases', 'chapters.md') with pytest.raises(Exception) as exinfo: slider.parse(path) assert exinfo.type == SliderError assert str(exinfo.value) == 'Second chapter found in the same file in {}'.format(path)
def test_cases(name): slider = Slider() pages = slider.parse(os.path.join('cases', '{}.md'.format(name))) with open(os.path.join('cases', 'dom', '{}.json'.format(name))) as fh: assert pages == json.load(fh)
def test_exceptions(): slider = Slider() path = os.path.join('cases', 'input', 'no-chapter-title.md') with pytest.raises(Exception) as exinfo: slider.parse(path) assert exinfo.type == SliderError assert str(exinfo.value) == 'Chapter title is missing in {}'.format(path) path = os.path.join('cases', 'input', 'no-chapter-id.md') with pytest.raises(Exception) as exinfo: slider.parse(path) assert exinfo.type == SliderError assert str(exinfo.value) == 'Chapter id is missing in {}'.format(path) path = os.path.join('cases', 'input', 'chapters.md') with pytest.raises(Exception) as exinfo: slider.parse(path) assert exinfo.type == SliderError assert str( exinfo.value ) == "Second chapter 'Chapters Title 1' found in the same file in '{}'".format( path) path = os.path.join('cases', 'input', 'duplicate_page_ids.md') with pytest.raises(Exception) as exinfo: slider.parse(path) assert exinfo.type == SliderError assert str( exinfo.value ) == 'The id page-1-url found twice in file {} in line 11'.format(path) path = os.path.join('cases', 'input', 'duplicate_ids.md') with pytest.raises(Exception) as exinfo: slider.parse(path) assert exinfo.type == SliderError assert str( exinfo.value ) == 'The id chapter-url found twice in file {} in line 8'.format(path) path = os.path.join('cases', 'input', 'missing_page_id.md') with pytest.raises(Exception) as exinfo: slider.parse(path) assert exinfo.type == SliderError assert str( exinfo.value) == 'Page id is missing in {} in line 11'.format(path) path = os.path.join('cases', 'input', 'missing_chapter_id.md') with pytest.raises(Exception) as exinfo: slider.parse(path) assert exinfo.type == SliderError assert str(exinfo.value) == 'Chapter id is missing in {}'.format(path) path = os.path.join('cases', 'input', 'second_page_id.md') with pytest.raises(Exception) as exinfo: slider.parse(path) assert exinfo.type == SliderError assert str( exinfo.value ) == "Second page id 'page-1-url' found in the same file in '{}' in line '9'".format( path) path = os.path.join('cases', 'input', 'second_chapter_id.md') with pytest.raises(Exception) as exinfo: slider.parse(path) assert exinfo.type == SliderError assert str( exinfo.value ) == 'Second chapter id found in the same file in {} in line 4'.format( path) path = os.path.join('cases', 'input', 'verbatim_outside.md') with pytest.raises(Exception) as exinfo: slider.parse(path) assert exinfo.type == SliderError assert str(exinfo.value) == '``` outside of page {} in line 4'.format(path) path = os.path.join('cases', 'input', 'incorrect-include.md') with pytest.raises(Exception) as exinfo: slider.parse(path) assert exinfo.type == SliderError assert str( exinfo.value ) == 'Included file "cases/input/some/not/existing/place" does not exist. In {} in line 9.'.format( path)