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

Delta Between Two Patch Sets: update-copyright/tests/test_update_copyright.py

Issue 29493601: Issue 5431 - Fix test for copyright update script (Closed) Base URL: https://hg.adblockplus.org/codingtools
Left Patch Set: Create sample_file from tmpdir_factory Created Aug. 3, 2017, 6:20 p.m.
Right Patch Set: Clean-up and remove duplicate code Created Aug. 5, 2017, 6:40 p.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 | « update-copyright/tests/data/sample_file.py ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 #!/usr/bin/env python3 1 #!/usr/bin/env python3
2 2
3 import os 3 import os
4 import re 4 import re
5 import datetime 5 import datetime
6 import subprocess 6 import subprocess
7 import shutil 7 import shutil
8 import urllib.parse 8 import urllib.parse
9 9
10 import pytest 10 import pytest
11 11
12 from update_copyright import extract_urls, text_replace, hg_commit, main 12 from update_copyright import extract_urls, text_replace, hg_commit, main
13 13
14 data_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'data') 14 data_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'data')
15 15
16 16
17 @pytest.fixture(scope='session') 17 @pytest.fixture(scope='session')
18 def sample_file(tmpdir_factory): 18 def sample_file(tmpdir_factory):
19 text = '# {}right (C) 2006-2015 eyeo GmbH\n'.format('Copy') 19 text = '# {}right (C) 2006-2015 eyeo GmbH\n'.format('Copy')
20 text += "value = '{}right (C) 2006-2016 Eyeo GmbH'\n".format('Copy') 20 text += "value = '{}right (C) 2006-2016 Eyeo GmbH'\n".format('Copy')
21 text += '# {}right (C) 2006-2014 example GmbH'.format('Copy') 21 text += '# {}right (C) 2006-2014 example GmbH'.format('Copy')
22 sample_file = tmpdir_factory.mktemp('sample_dir').join('sample_file.py') 22 sample_file = tmpdir_factory.mktemp('sample_dir').join('sample_file.py')
23 with open(str(sample_file), 'w') as sample_file_path: 23 sample_file.write(text)
Vasily Kuznetsov 2017/08/04 16:54:46 Since now `sample_file` is a `py.path` object, you
rosie 2017/08/05 18:41:07 Done.
24 sample_file_path.write(text)
25 return str(sample_file) 24 return str(sample_file)
26 25
27 26
28 def create_repo(sample_file, path): 27 def create_repo(sample_file, path):
29 subprocess.check_call(['hg', 'init', path]) 28 subprocess.check_call(['hg', 'init', path])
30 with open(os.path.join(path, '.hg', 'hgrc'), 'w+') as hgrc: 29 with open(os.path.join(path, '.hg', 'hgrc'), 'w+') as hgrc:
31 set_user = '[ui]\nusername = Test User <test@example.com>' 30 set_user = '[ui]\nusername = Test User <test@example.com>'
32 hgrc.write(set_user) 31 hgrc.write(set_user)
33 shutil.copy(sample_file, path) 32 shutil.copy(sample_file, path)
34 subprocess.check_call(['hg', 'commit', '-Am', 'Initial commit', 33 subprocess.check_call(['hg', 'commit', '-Am', 'Initial commit',
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 subprocess.check_call(['hg', 'add', '--repository', directory]) 103 subprocess.check_call(['hg', 'add', '--repository', directory])
105 hg_commit(directory, repo) 104 hg_commit(directory, repo)
106 105
107 # Make sure both files contain the commmit message from hg log 106 # Make sure both files contain the commmit message from hg log
108 log_1 = subprocess.run(['hg', 'log', '--repository', repo], 107 log_1 = subprocess.run(['hg', 'log', '--repository', repo],
109 stdout=subprocess.PIPE) 108 stdout=subprocess.PIPE)
110 assert 'Noissue - Updated copyright year' in str(log_1.stdout) 109 assert 'Noissue - Updated copyright year' in str(log_1.stdout)
111 110
112 111
113 def test_all(sample_file, base_dir): 112 def test_all(sample_file, base_dir):
114 # Copy the sample_file to both repos
115 shutil.copy(sample_file, os.path.join(base_dir, 'repo_1'))
Vasily Kuznetsov 2017/08/04 16:54:46 Isn't the sample file already copied to the reposi
rosie 2017/08/05 18:41:08 Done.
116 shutil.copy(sample_file, os.path.join(base_dir, 'repo_2'))
117
118 main(urllib.parse.urljoin('file:///', os.path.join( 113 main(urllib.parse.urljoin('file:///', os.path.join(
119 base_dir, 'hg_page.html')), None) 114 base_dir, 'hg_page.html')), None)
120 115
121 # assert hg log for repo_1 116 # assert hg log for repo_1
122 log_1 = subprocess.run(['hg', 'log', '--repository', 117 log_1 = subprocess.run(['hg', 'log', '--repository',
123 os.path.join(base_dir, 'repo_1')], 118 os.path.join(base_dir, 'repo_1')],
124 stdout=subprocess.PIPE) 119 stdout=subprocess.PIPE)
125 assert 'Noissue - Updated copyright year' in str(log_1.stdout) 120 assert 'Noissue - Updated copyright year' in str(log_1.stdout)
126 121
127 # assert the .patch file for repo_2 122 # assert the .patch file for repo_2
128 assert'Noissue - Updated copyright year' in open('repo_2.patch').read() 123 assert'Noissue - Updated copyright year' in open('repo_2.patch').read()
129 subprocess.call(['rm', 'repo_2.patch']) # cleanup 124 subprocess.call(['rm', 'repo_2.patch']) # cleanup
LEFTRIGHT

Powered by Google App Engine
This is Rietveld