def test_check_links_fail(self): with cd(self.target_dir): os.unlink(os.path.join("output", "archive.html")) try: main.main(['check', '-l']) except SystemExit as e: self.assertNotEqual(e.code, 0)
def test_check_files_fail(self): with cd(self.target_dir): with codecs.open(os.path.join("output", "foobar"), "wb+", "utf8") as outf: outf.write("foo") try: main.main(['check', '-f']) except SystemExit as e: self.assertNotEqual(e.code, 0)
def test_future_post(self): """ Ensure that the future post is not present in the index and sitemap.""" index_path = os.path.join(self.target_dir, "output", "index.html") sitemap_path = os.path.join(self.target_dir, "output", "sitemap.xml") foo_path = os.path.join(self.target_dir, "output", "posts", "foo.html") bar_path = os.path.join(self.target_dir, "output", "posts", "bar.html") self.assertTrue(os.path.isfile(index_path)) self.assertTrue(os.path.isfile(foo_path)) self.assertTrue(os.path.isfile(bar_path)) index_data = codecs.open(index_path, "r", "utf8").read() sitemap_data = codecs.open(sitemap_path, "r", "utf8").read() self.assertTrue('foo.html' in index_data) self.assertFalse('bar.html' in index_data) self.assertTrue('foo.html' in sitemap_data) self.assertFalse('bar.html' in sitemap_data) # Run deploy command to see if future post is deleted with cd(self.target_dir): main.main(["deploy"]) self.assertTrue(os.path.isfile(index_path)) self.assertTrue(os.path.isfile(foo_path)) self.assertFalse(os.path.isfile(bar_path))
def build(self): """Build the site.""" with cd(self.target_dir): main.main(["build"])
def test_check_files(self): with cd(self.target_dir): try: main.main(['check', '-f']) except SystemExit as e: self.assertEqual(e.code, 0)
def test_subdir_run(self): """Check whether build works from posts/""" with cd(os.path.join(self.target_dir, 'posts')): result = main.main(['build']) self.assertEquals(result, 0)
def _run_command(self, args=[]): from nikola.main import main return main(args)