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

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

Issue 29459580: Issue 5250 - Add copyright update script (Closed) Base URL: https://hg.adblockplus.org/codingtools
Left Patch Set: Minor formatting fixes Created July 4, 2017, 3:13 p.m.
Right Patch Set: Fix indentation and default args Created July 17, 2017, 1:22 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') | update-copyright/tox.ini » ('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 #!/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
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 61
62 62
63 def test_extract_urls(): 63 def test_extract_urls():
64 data_url = urllib.parse.urljoin('file:///', data_path) 64 data_url = urllib.parse.urljoin('file:///', data_path)
65 urls = [data_url + '/repo_1/', 65 urls = [data_url + '/repo_1/',
66 data_url + '/repo_2/'] 66 data_url + '/repo_2/']
67 assert urls == extract_urls(os.path.join(data_url, 'hg_page.html')) 67 assert urls == extract_urls(os.path.join(data_url, 'hg_page.html'))
68 68
69 69
70 def test_text_replacement(temp_repo): 70 def test_text_replacement(temp_repo):
71 updated = 0
71 filename = temp_repo.join('sample_file.py').strpath 72 filename = temp_repo.join('sample_file.py').strpath
72 text_replace(temp_repo.strpath, filename) 73 text_replace(temp_repo.strpath, filename)
73 with open(filename) as file: 74 with open(filename) as file:
74 text = file.read() 75 text = file.read()
75 pattern = re.compile(r'(copyright.*?\d{4})(?:-\d{4})?\s+eyeo gmbh', 76 pattern = re.compile(r'(copyright.*?\d{4})(?:-\d{4})?\s+eyeo gmbh',
76 re.I) 77 re.I)
77 for year in re.finditer(pattern, text): 78 for year in re.finditer(pattern, text):
78 dates = re.search(r'(\d{4})-(\d{4})', year.group(0)) 79 dates = re.search(r'(\d{4})-(\d{4})', year.group(0))
79 assert dates.group(2) == str(datetime.datetime.now().year) 80 if dates.group(2) == str(datetime.datetime.now().year):
81 updated += 1
82
83 # test that non-eyeo copyright information are left alone
84 assert '2014 example' in text
85 # test for copyright information in both strings and comments
86 assert updated == 2
80 87
81 88
82 def test_hg_commit(temp_repo, temp_dir): 89 def test_hg_commit(temp_repo, temp_dir):
83 directory = str(temp_dir) 90 directory = str(temp_dir)
84 repo = str(temp_repo) 91 repo = str(temp_repo)
85 subprocess.check_call(['hg', 'clone', repo, directory]) 92 subprocess.check_call(['hg', 'clone', repo, directory])
86 open(os.path.join(directory, 'foo'), 'w').close() 93 open(os.path.join(directory, 'foo'), 'w').close()
87 subprocess.check_call(['hg', 'add', '--repository', directory]) 94 subprocess.check_call(['hg', 'add', '--repository', directory])
88 hg_commit(directory, repo) 95 hg_commit(directory, repo)
89 96
90 # Make sure both files contain the commmit message from hg log 97 # Make sure both files contain the commmit message from hg log
91 log_1 = subprocess.run(['hg', 'log', '--repository', repo], 98 log_1 = subprocess.run(['hg', 'log', '--repository', repo],
92 stdout=subprocess.PIPE) 99 stdout=subprocess.PIPE)
93 assert 'Noissue - Updated copyright year' in str(log_1.stdout) 100 assert 'Noissue - Updated copyright year' in str(log_1.stdout)
94 101
95 102
96 def test_all(base_dir): 103 def test_all(base_dir):
97 main(urllib.parse.urljoin('file:///', os.path.join( 104 main(urllib.parse.urljoin('file:///', os.path.join(
98 base_dir, 'hg_page.html')), None) 105 base_dir, 'hg_page.html')), None)
99 106
100 # assert hg log for repo_1 107 # assert hg log for repo_1
101 log_1 = subprocess.run(['hg', 'log', '--repository', 108 log_1 = subprocess.run(['hg', 'log', '--repository',
102 os.path.join(base_dir, 'repo_1')], 109 os.path.join(base_dir, 'repo_1')],
103 stdout=subprocess.PIPE) 110 stdout=subprocess.PIPE)
104 assert 'Noissue - Updated copyright year' in str(log_1.stdout) 111 assert 'Noissue - Updated copyright year' in str(log_1.stdout)
105 112
106 # assert the .patch file for repo_2 113 # assert the .patch file for repo_2
107 assert'Noissue - Updated copyright year' in open('repo_2.patch').read() 114 assert'Noissue - Updated copyright year' in open('repo_2.patch').read()
108 subprocess.call(['rm', 'repo_2.patch']) # cleanup 115 subprocess.call(['rm', 'repo_2.patch']) # cleanup
LEFTRIGHT

Powered by Google App Engine
This is Rietveld