Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: tests/test_generation_exceptional_cases.py

Issue 29887585: Issue #5352 - generate_static_pages cannot deal with directories being turned into regular pages (Closed)
Patch Set: Addressed comments from Patch Set #2 Created Oct. 4, 2018, 6:31 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tests/expected_output/en/sitemap ('k') | tests/test_site/pages/foo/bar.md » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/test_generation_exceptional_cases.py
diff --git a/tests/test_generation_exceptional_cases.py b/tests/test_generation_exceptional_cases.py
new file mode 100644
index 0000000000000000000000000000000000000000..35706590410c524a7bb01bc1369df96d156ea2b6
--- /dev/null
+++ b/tests/test_generation_exceptional_cases.py
@@ -0,0 +1,74 @@
+# This file is part of the Adblock Plus web scripts,
+# Copyright (C) 2006-present eyeo GmbH
+#
+# Adblock Plus is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 3 as
+# published by the Free Software Foundation.
+#
+# Adblock Plus is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
+
+import os
+
+import pytest
+
+from cms.bin.generate_static_pages import generate_pages
+
+
+@pytest.fixture
+def target_dir_with_file(tmpdir):
+ target_dir = tmpdir.mkdir('out_file').strpath
+ os.mkdir(os.path.join(target_dir, 'en'))
+
+ with open(os.path.join(target_dir, 'en', 'foo'), 'w') as f:
+ f.write('test\n')
+
+ yield target_dir
+
+
+@pytest.fixture
+def target_dir_with_dir(tmpdir):
+ target_dir = tmpdir.mkdir('out_dir').strpath
+ os.makedirs(os.path.join(target_dir, 'en', 'translate'))
+
+ yield target_dir
+
+
+@pytest.fixture
+def target_dir_with_fifo(tmpdir):
+ target_dir = tmpdir.mkdir('out_dir').strpath
+ os.mkdir(os.path.join(target_dir, 'en'))
+ os.mkfifo(os.path.join(target_dir, 'en', 'translate'))
+
+ yield target_dir
+
+
+def test_generate_dir_instead_of_file(temp_site, target_dir_with_file):
+ """Case where a file from previous version becomes a directory."""
+ generate_pages(str(temp_site), str(target_dir_with_file))
+
+ assert os.path.isdir(os.path.join(target_dir_with_file, 'en', 'foo'))
+
+
+def test_generate_file_instead_of_dir(temp_site, target_dir_with_dir):
+ """Case where a directory from previous version becomes a file."""
+ generate_pages(str(temp_site), str(target_dir_with_dir))
+
+ assert os.path.isfile(os.path.join(target_dir_with_dir, 'en', 'translate'))
+
+
+@pytest.mark.script_launch_mode('subprocess')
+def test_generate_fifo_instead_of_file(temp_site, target_dir_with_fifo,
+ script_runner):
+ cmd = ['python', '-m', 'cms.bin.generate_static_pages', str(temp_site),
+ str(target_dir_with_fifo)]
+
+ ret = script_runner.run(*cmd)
+
+ assert not ret.success
+ assert 'It is neither a file, nor a directory!' in ret.stderr
« no previous file with comments | « tests/expected_output/en/sitemap ('k') | tests/test_site/pages/foo/bar.md » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld