LEFT | RIGHT |
(no file at all) | |
| 1 # This file is part of the Adblock Plus web scripts, |
| 2 # Copyright (C) 2006-present eyeo GmbH |
| 3 # |
| 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 |
| 6 # published by the Free Software Foundation. |
| 7 # |
| 8 # Adblock Plus is distributed in the hope that it will be useful, |
| 9 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 # GNU General Public License for more details. |
| 12 # |
| 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/>. |
| 15 |
| 16 import os |
| 17 |
| 18 import pytest |
| 19 |
| 20 from cms.bin.generate_static_pages import generate_pages |
| 21 |
| 22 |
| 23 @pytest.fixture |
| 24 def target_dir_with_file(tmpdir): |
| 25 target_dir = tmpdir.mkdir('out_file').strpath |
| 26 os.mkdir(os.path.join(target_dir, 'en')) |
| 27 |
| 28 with open(os.path.join(target_dir, 'en', 'foo'), 'w') as f: |
| 29 f.write('test\n') |
| 30 |
| 31 yield target_dir |
| 32 |
| 33 |
| 34 @pytest.fixture |
| 35 def target_dir_with_dir(tmpdir): |
| 36 target_dir = tmpdir.mkdir('out_dir').strpath |
| 37 os.makedirs(os.path.join(target_dir, 'en', 'translate')) |
| 38 |
| 39 yield target_dir |
| 40 |
| 41 |
| 42 @pytest.fixture |
| 43 def target_dir_with_fifo(tmpdir): |
| 44 target_dir = tmpdir.mkdir('out_dir').strpath |
| 45 os.mkdir(os.path.join(target_dir, 'en')) |
| 46 os.mkfifo(os.path.join(target_dir, 'en', 'translate')) |
| 47 |
| 48 yield target_dir |
| 49 |
| 50 |
| 51 def test_generate_dir_instead_of_file(temp_site, target_dir_with_file): |
| 52 """Case where a file from previous version becomes a directory.""" |
| 53 generate_pages(str(temp_site), str(target_dir_with_file)) |
| 54 |
| 55 assert os.path.isdir(os.path.join(target_dir_with_file, 'en', 'foo')) |
| 56 |
| 57 |
| 58 def test_generate_file_instead_of_dir(temp_site, target_dir_with_dir): |
| 59 """Case where a directory from previous version becomes a file.""" |
| 60 generate_pages(str(temp_site), str(target_dir_with_dir)) |
| 61 |
| 62 assert os.path.isfile(os.path.join(target_dir_with_dir, 'en', 'translate')) |
| 63 |
| 64 |
| 65 def test_generate_fifo_instead_of_file(temp_site, target_dir_with_fifo, |
| 66 script_runner): |
| 67 """Case with an unsupported item encountered (FIFO).""" |
| 68 with pytest.raises(Exception) as exp: |
| 69 generate_pages(str(temp_site), str(target_dir_with_fifo)) |
| 70 |
| 71 assert 'It is neither a file, nor a directory!' in str(exp.value) |
LEFT | RIGHT |