def test_dir_with_file(self): """ Test a directory with a file. """ with tempfile.TemporaryDirectory() as tmp_dir: self.touch(os.path.join(tmp_dir, DEFAULT_PAGE + ".md")) self.assertListEqual(app.get_sub_pages(tmp_dir), [DEFAULT_PAGE])
def test_dir_with_sub_dir(self): """ Test a directory with a sub-directory. """ with tempfile.TemporaryDirectory() as tmp_dir: os.mkdir(os.path.join(tmp_dir, DEFAULT_PAGE)) self.assertListEqual(app.get_sub_pages(tmp_dir), [DEFAULT_PAGE])
def test_dir_non_md(self): """ Test a directory with an invalid file. """ with tempfile.TemporaryDirectory() as tmp_dir: self.touch(os.path.join(tmp_dir, "valid.txt")) self.assertListEqual(app.get_sub_pages(tmp_dir), [])
def test_dir_only_index(self): """ Test a directory with an index. """ with tempfile.TemporaryDirectory() as tmp_dir: self.touch(os.path.join(tmp_dir, "index.md")) self.assertListEqual(app.get_sub_pages(tmp_dir), [])
def test(self): """ Replicate the regression """ with tempfile.TemporaryDirectory() as tmp_dir: tmp_file = Path(os.path.join(tmp_dir, "namemd.md")) tmp_file.touch() self.assertListEqual(app.get_sub_pages(tmp_dir), ["namemd"])
def test_dir_with_dir_file_and_junk(self): """ Test a directory with a sub-directory, a file, an invalid file, and an index. """ with tempfile.TemporaryDirectory() as tmp_dir: os.mkdir(os.path.join(tmp_dir, "dir")) self.touch(os.path.join(tmp_dir, DEFAULT_PAGE + ".md")) self.touch(os.path.join(tmp_dir, "valid.txt")) self.touch(os.path.join(tmp_dir, "index.md")) self.assertListEqual(app.get_sub_pages(tmp_dir), ["dir", DEFAULT_PAGE])
def test_file(self): """ Test a directory with a file. """ with tempfile.NamedTemporaryFile(mode="x") as tmp_file: self.assertListEqual(app.get_sub_pages(tmp_file.name), [])
def test_empty_dir(self): """ Test an empty directory. """ with tempfile.TemporaryDirectory() as tmp_dir: self.assertListEqual(app.get_sub_pages(tmp_dir), [])