def test_from_file_invalid_file(self): src = """ --- title: A Dummy File --- Woops, did I accidentally put a newline in the header? """.strip() _, filename = tempfile.mkstemp() open(filename, 'w').write(src) assert os.path.exists(filename) with pytest.raises(ParseError): some_page = Page.from_file(filename) os.remove(filename) assert not exists(filename)
def test_from_file_valid(self): _, filename = tempfile.mkstemp() title = filename_to_title(filename) src = """ --- title: {} --- The body of some file """.format(title).strip() open(filename, 'w').write(src) assert os.path.exists(filename) some_page = Page.from_file(filename) assert some_page.config == {'title': title} assert some_page.content == 'The body of some file' os.remove(filename) assert not exists(filename)
def test_from_file_FileNotFound(self): with pytest.raises(FileNotFoundError): some_page = Page.from_file('non/existent/file.md')