| OLD | NEW | 
|---|
| (Empty) |  | 
|  | 1 # This file is part of Adblock Plus <https://adblockplus.org/>, | 
|  | 2 # Copyright (C) 2006-2016 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 from __future__ import print_function, unicode_literals | 
|  | 17 | 
|  | 18 import os | 
|  | 19 import subprocess | 
|  | 20 try: | 
|  | 21     from StringIO import StringIO | 
|  | 22 except: | 
|  | 23     from io import StringIO | 
|  | 24 | 
|  | 25 import mock | 
|  | 26 import pytest | 
|  | 27 | 
|  | 28 import patchconv | 
|  | 29 | 
|  | 30 TEST_DIR = os.path.dirname(__file__) | 
|  | 31 | 
|  | 32 | 
|  | 33 def get_test_cases(): | 
|  | 34     for filename in os.listdir(TEST_DIR): | 
|  | 35         if filename.endswith('.txt'): | 
|  | 36             yield filename | 
|  | 37 | 
|  | 38 | 
|  | 39 @pytest.fixture(params=list(get_test_cases())) | 
|  | 40 def patch_data(request): | 
|  | 41     data = {'input': [], 'expect': []} | 
|  | 42     current = [] | 
|  | 43     with open(os.path.join(TEST_DIR, request.param)) as file: | 
|  | 44         for line in file: | 
|  | 45             print(line, end='') | 
|  | 46             if line.startswith('INPUT'): | 
|  | 47                 current = data['input'] | 
|  | 48             elif line.startswith('EXPECT'): | 
|  | 49                 current = data['expect'] | 
|  | 50             elif not line.startswith('#'): | 
|  | 51                 if line.startswith('    '): | 
|  | 52                     current.append(line[4:]) | 
|  | 53                 else: | 
|  | 54                     current.append('') | 
|  | 55     return data | 
|  | 56 | 
|  | 57 | 
|  | 58 def test_convert(patch_data): | 
|  | 59     got = list(patchconv.rietveld_to_git(patch_data['input'])) | 
|  | 60     print('GOT') | 
|  | 61     for line in got: | 
|  | 62         print('    ' + line, end='') | 
|  | 63     assert got == patch_data['expect'] | 
|  | 64 | 
|  | 65 | 
|  | 66 def test_script(): | 
|  | 67     process = subprocess.Popen( | 
|  | 68         ['patchconv'], stdin=subprocess.PIPE, stdout=subprocess.PIPE | 
|  | 69     ) | 
|  | 70     in_patch = '''Index: README.txt | 
|  | 71 =================================================================== | 
|  | 72 --- a/README.txt | 
|  | 73 ''' | 
|  | 74     expect = '''diff --git a/README.txt b/README.txt | 
|  | 75 --- a/README.txt | 
|  | 76 ''' | 
|  | 77     out, err = process.communicate(input=in_patch.encode('ascii')) | 
|  | 78     assert out == expect.encode('ascii') | 
|  | 79 | 
|  | 80     stdin = StringIO(in_patch) | 
|  | 81     stdout = StringIO() | 
|  | 82     with mock.patch('sys.stdin', stdin), mock.patch('sys.stdout', stdout): | 
|  | 83         patchconv.main() | 
|  | 84     assert stdout.getvalue() == expect | 
| OLD | NEW | 
|---|