def test_draft(self): cmdline.main(["--draft", "My Draft", "--quiet"]) file_path = os.path.join(utils.TEST_ROOT, "drafts", "my_draft.rst") # assert draft was created self.assertTrue(os.path.exists(file_path))
def test_post_with_date(self): cmdline.main(["--post", "Dated Post", "--date", "2011/11/20"]) file_path = os.path.join(utils.TEST_ROOT, "2011/11/20", "dated_post.rst") # assert file exists self.assertTrue(os.path.exists(file_path))
def test_page_from_title(self): cmdline.main(["--page", "My Test Page", "--quiet"]) file_path = os.path.join(utils.TEST_ROOT, "pages", "my_test_page.rst") # assert file exsits self.assertTrue(os.path.exists(file_path))
def test_date_only_on_post(self): self.assertNotEqual( 0, cmdline.main(["--page", "Test Page", "--date", "2011/11/20"])) self.assertNotEqual( 0, cmdline.main(["--draft", "Test Draft", "--date", "2011/11/20"])) self.assertNotEqual(0, cmdline.main(["--build", "--date", "2011/11/20"]))
def test_date_only_on_post(self): self.assertNotEqual(0, cmdline.main(["--page", "Test Page", "--date", "2011/11/20"])) self.assertNotEqual(0, cmdline.main(["--draft", "Test Draft", "--date", "2011/11/20"])) self.assertNotEqual(0, cmdline.main(["--build", "--date", "2011/11/20"]))
def test_post_from_title(self): cmdline.main(["--post", "My Test Post", "--quiet"]) # this might fail at midnight :P year, month, day = tinkerer.utils.split_date() file_path = os.path.join(utils.TEST_ROOT, year, month, day, "my_test_post.rst") # assert file exists self.assertTrue(os.path.exists(file_path))
def test_setup(self): # blog is setup as part of test setup, tear it down and re-create it via # cmdline self.tearDown() cmdline.main(["--setup", "--quiet"]) self.assertEqual( set(os.listdir(utils.TEST_ROOT)), set(["_static", "_templates", "drafts", "conf.py", "index.html", tinkerer.master_doc + ".rst"]), )
def test_setup(self): # blog is setup as part of test setup, tear it down and re-create it via # cmdline self.tearDown() cmdline.main(["--setup", "--quiet"]) self.assertEqual( set(os.listdir(utils.TEST_ROOT)), set([ "_static", "_templates", "drafts", "conf.py", "index.html", tinkerer.master_doc + ".rst" ]))
def test_root_only(self): # remove "conf.py" created by test setup os.remove(os.path.join(paths.root, "conf.py")) self.assertNotEqual(0, cmdline.main(["--page", "Test Post", "--quiet"])) self.assertNotEqual(0, cmdline.main(["--post", "Test Page", "--quiet"])) self.assertNotEqual(0, cmdline.main(["--build", "--quiet"])) # setup should work fine from anywhere self.assertEqual(0, cmdline.main(["--setup", "--quiet"]))
def test_filename_only(self): # hook up test log handler test_stream = StringIO() # restore logging for this particular test logging.disable(logging.NOTSET) output.filename.addHandler(logging.StreamHandler(test_stream)) # setup new blog with --filename flag cmdline.main(["--setup", "--filename"]) # output should be `conf.py` self.assertEquals("conf.py", test_stream.getvalue().strip())
def test_post_from_existing_file(self): # create file draft_file = os.path.join(utils.TEST_ROOT, "drafts", "draft_page.rst") with open(draft_file, "w") as f: f.write("Content") cmdline.main(["--page", draft_file, "--quiet"]) file_path = os.path.join(utils.TEST_ROOT, "pages", "draft_page.rst") # assert file exists and check content self.assertTrue(os.path.exists(file_path)) with open(file_path, "r") as f: self.assertEquals("Content", f.read())
def test_post_from_path(self): # create file draft_file = os.path.join(utils.TEST_ROOT, "drafts", "draft_page.rst") with open(draft_file, "w") as f: f.write("Content") cmdline.main(["--page", draft_file, "--quiet"]) file_path = os.path.join(utils.TEST_ROOT, "pages", "draft_page.rst") # assert file exists and check content self.assertTrue(os.path.exists(file_path)) with open(file_path, "r") as f: self.assertEquals("Content", f.read())
def test_missing_template(self): # creating a post with a missing template file should fail self.assertNotEqual( 0, cmdline.main(["--post", "test", "--template", "missing", "--quiet"]) )
def test_setup(self): # blog is setup as part of test setup, tear it down and # re-create it via cmdline self.tearDown() cmdline.main(["--setup", "--quiet"]) self.assertEqual( set(os.listdir(utils.TEST_ROOT)), set([ "_static", "_templates", "drafts", "conf.py", "index.html", tinkerer.master_doc + ".rst" ])) # favicon should be copied to the blog _static folder self.assertTrue( os.path.exists( os.path.join(utils.TEST_ROOT, "_static", paths.favicon)))
def test_post_from_path(self): # create file draft_file = os.path.join(utils.TEST_ROOT, "drafts", "draft_post.rst") with open(draft_file, "w") as f: f.write("Content") cmdline.main(["--post", draft_file, "--quiet"]) # this might also fail at midnight :P year, month, day = tinkerer.utils.split_date() file_path = os.path.join(utils.TEST_ROOT, year, month, day, "draft_post.rst") # assert file exists and check content self.assertTrue(os.path.exists(file_path)) with open(file_path, "r") as f: self.assertEquals("Content", f.read())
def test_setup(self): # blog is setup as part of test setup, tear it down and # re-create it via cmdline self.tearDown() cmdline.main(["--setup", "--quiet"]) self.assertEqual( set(os.listdir(utils.TEST_ROOT)), set([ "_static", "_templates", "drafts", "conf.py", "index.html", tinkerer.master_doc + ".rst" ])) # favicon should be copied to the blog _static folder self.assertTrue(os.path.exists( os.path.join(utils.TEST_ROOT, "_static", paths.favicon) ))
def test_preview(self): # create a post new_post = post.create("A post", datetime.datetime(2010, 10, 1)) # post should be in master doc (precondition) lines = master.read_master() self.assertTrue(" %s\n" % new_post.docname in lines) # create a draft new_draft = draft.create("draft") self.assertTrue(os.path.exists(new_draft)) # preview it (build should succeed) self.assertEqual(0, cmdline.main(["--preview", new_draft, "-q"])) # draft should not be in TOC for line in master.read_master(): self.assertFalse("draft" in line)
def test_preview(self): # create a post new_post = post.create("A post", datetime.datetime(2010, 10, 1)) # post should be in master doc (precondition) lines = master.read_master() self.assertTrue(" %s\n" % new_post.docname in lines) # create a draft new_draft = draft.create("draft") self.assertTrue(os.path.exists(new_draft)) # preview it (build should succeed) self.assertEquals(0, cmdline.main(["--preview", new_draft, "-q"])) # draft should not be in TOC for line in master.read_master(): self.assertFalse("draft" in line)
from tinkerer import cmdline import sys cmdline.main(sys.argv[1:])