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 #1 Created Sept. 24, 2018, 4:05 p.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
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..59846ca527964ac82d283383cd12a91e7f3950f9
--- /dev/null
+++ b/tests/test_generation_exceptional_cases.py
@@ -0,0 +1,84 @@
+# 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
+
+
+@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
+
+
+@pytest.mark.script_launch_mode('subprocess')
Vasily Kuznetsov 2018/09/27 11:05:07 As we've discussed, please try to convert these ge
Tudor Avram 2018/10/04 06:34:18 Done for first two tests. The last one requires so
+def test_generate_dir_instead_of_file(temp_site, target_dir_with_file,
+ script_runner):
+ cmd = ['python', '-m', 'cms.bin.generate_static_pages', str(temp_site),
+ str(target_dir_with_file)]
+
+ script_runner.run(*cmd)
+
+ assert os.path.isdir(os.path.join(target_dir_with_file, 'en', 'foo'))
+
+
+@pytest.mark.script_launch_mode('subprocess')
+def test_generate_file_instead_of_dir(temp_site, target_dir_with_dir,
+ script_runner):
+ cmd = ['python', '-m', 'cms.bin.generate_static_pages', str(temp_site),
+ str(target_dir_with_dir)]
+
+ script_runner.run(*cmd)
+
+ print(os.listdir(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):
Tudor Avram 2018/10/04 06:34:18 For this last test, I would have to mock sys.exit(
Vasily Kuznetsov 2018/10/05 09:40:43 You can catch SystemExit exception in this test. C
+ cmd = ['python', '-m', 'cms.bin.generate_static_pages', str(temp_site),
+ str(target_dir_with_fifo)]
+
+ ret = script_runner.run(*cmd)
+
+ print(ret.stderr)
+
+ assert not ret.success
+ assert 'It is neither a file, nor a directory!' in ret.stderr

Powered by Google App Engine
This is Rietveld