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

Delta Between Two Patch Sets: tests/test_generation_exceptional_cases.py

Issue 29887585: Issue #5352 - generate_static_pages cannot deal with directories being turned into regular pages (Closed)
Left Patch Set: Addressed comments from Patch #1 Created Sept. 24, 2018, 4:05 p.m.
Right Patch Set: Addressed comments from Patch Set #4 Created Oct. 5, 2018, 11:28 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « tests/expected_output/en/sitemap ('k') | tests/test_site/pages/foo/bar.md » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 # This file is part of the Adblock Plus web scripts, 1 # This file is part of the Adblock Plus web scripts,
2 # Copyright (C) 2006-present eyeo GmbH 2 # Copyright (C) 2006-present eyeo GmbH
3 # 3 #
4 # Adblock Plus is free software: you can redistribute it and/or modify 4 # Adblock Plus is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License version 3 as 5 # it under the terms of the GNU General Public License version 3 as
6 # published by the Free Software Foundation. 6 # published by the Free Software Foundation.
7 # 7 #
8 # Adblock Plus is distributed in the hope that it will be useful, 8 # Adblock Plus is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of 9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details. 11 # GNU General Public License for more details.
12 # 12 #
13 # You should have received a copy of the GNU General Public License 13 # You should have received a copy of the GNU General Public License
14 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 14 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
15 15
16 import os 16 import os
17 17
18 import pytest 18 import pytest
19
20 from cms.bin.generate_static_pages import generate_pages
19 21
20 22
21 @pytest.fixture 23 @pytest.fixture
22 def target_dir_with_file(tmpdir): 24 def target_dir_with_file(tmpdir):
23 target_dir = tmpdir.mkdir('out_file').strpath 25 target_dir = tmpdir.mkdir('out_file').strpath
24 os.mkdir(os.path.join(target_dir, 'en')) 26 os.mkdir(os.path.join(target_dir, 'en'))
25 27
26 with open(os.path.join(target_dir, 'en', 'foo'), 'w') as f: 28 with open(os.path.join(target_dir, 'en', 'foo'), 'w') as f:
27 f.write('test\n') 29 f.write('test\n')
28 30
(...skipping 10 matching lines...) Expand all
39 41
40 @pytest.fixture 42 @pytest.fixture
41 def target_dir_with_fifo(tmpdir): 43 def target_dir_with_fifo(tmpdir):
42 target_dir = tmpdir.mkdir('out_dir').strpath 44 target_dir = tmpdir.mkdir('out_dir').strpath
43 os.mkdir(os.path.join(target_dir, 'en')) 45 os.mkdir(os.path.join(target_dir, 'en'))
44 os.mkfifo(os.path.join(target_dir, 'en', 'translate')) 46 os.mkfifo(os.path.join(target_dir, 'en', 'translate'))
45 47
46 yield target_dir 48 yield target_dir
47 49
48 50
49 @pytest.mark.script_launch_mode('subprocess') 51 def test_generate_dir_instead_of_file(temp_site, target_dir_with_file):
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
50 def test_generate_dir_instead_of_file(temp_site, target_dir_with_file, 52 """Case where a file from previous version becomes a directory."""
51 script_runner): 53 generate_pages(str(temp_site), str(target_dir_with_file))
52 cmd = ['python', '-m', 'cms.bin.generate_static_pages', str(temp_site),
53 str(target_dir_with_file)]
54
55 script_runner.run(*cmd)
56 54
57 assert os.path.isdir(os.path.join(target_dir_with_file, 'en', 'foo')) 55 assert os.path.isdir(os.path.join(target_dir_with_file, 'en', 'foo'))
58 56
59 57
60 @pytest.mark.script_launch_mode('subprocess') 58 def test_generate_file_instead_of_dir(temp_site, target_dir_with_dir):
61 def test_generate_file_instead_of_dir(temp_site, target_dir_with_dir, 59 """Case where a directory from previous version becomes a file."""
62 script_runner): 60 generate_pages(str(temp_site), str(target_dir_with_dir))
63 cmd = ['python', '-m', 'cms.bin.generate_static_pages', str(temp_site),
64 str(target_dir_with_dir)]
65
66 script_runner.run(*cmd)
67
68 print(os.listdir(target_dir_with_dir))
69 61
70 assert os.path.isfile(os.path.join(target_dir_with_dir, 'en', 'translate')) 62 assert os.path.isfile(os.path.join(target_dir_with_dir, 'en', 'translate'))
71 63
72 64
73 @pytest.mark.script_launch_mode('subprocess')
74 def test_generate_fifo_instead_of_file(temp_site, target_dir_with_fifo, 65 def test_generate_fifo_instead_of_file(temp_site, target_dir_with_fifo,
75 script_runner): 66 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
76 cmd = ['python', '-m', 'cms.bin.generate_static_pages', str(temp_site), 67 """Case with an unsupported item encountered (FIFO)."""
77 str(target_dir_with_fifo)] 68 with pytest.raises(Exception) as exp:
69 generate_pages(str(temp_site), str(target_dir_with_fifo))
78 70
79 ret = script_runner.run(*cmd) 71 assert 'It is neither a file, nor a directory!' in str(exp.value)
80
81 print(ret.stderr)
82
83 assert not ret.success
84 assert 'It is neither a file, nor a directory!' in ret.stderr
LEFTRIGHT

Powered by Google App Engine
This is Rietveld