-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add --dry-run, transform before ignore
- Loading branch information
1 parent
cc09cff
commit ca6720f
Showing
2 changed files
with
66 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,10 +13,11 @@ | |
|
||
class Test_Context: | ||
|
||
def __init__(self, capture=False, verbose=False): | ||
def __init__(self, capture=False, verbose=False, dry_run=False): | ||
self.now_calls = 0 | ||
self.now_time = "" | ||
self.verbose = verbose | ||
self.dry_run = dry_run | ||
self.capture = capture | ||
self.out = '' | ||
|
||
|
@@ -77,15 +78,34 @@ def test_urls_from(self): | |
name = "url-check" | ||
workdir = os.path.join(gits_dir, name) | ||
file = "url-check.test.py" | ||
our_ignore_patters = ['^http[s]\?://bogus.gov'] | ||
ctx = Test_Context() | ||
found = uc.urls_from(workdir, file, our_ignore_patters, ctx) | ||
transform_urls = [ | ||
'https://example.com/one.html).', | ||
'https://example.com/obsolete.html', | ||
'https://example.com/three.html', | ||
] | ||
transforms = [ | ||
f"sed 's@obsolete\\[email protected]@g'", | ||
f"sed 's@TEMPFIX\\[email protected]@g'", | ||
f"sed 's@\\(.*html\\)[\\.,):!]*$@\\1@g'", | ||
] | ||
ignores = ['^http[s]\?://bogus.gov'] | ||
# ctx = Test_Context() | ||
ctx = Test_Context(capture=True) | ||
found = uc.urls_from(workdir, file, transforms, ignores, ctx) | ||
print(ctx.out) | ||
self.assertIn("https://example.org/", found) | ||
self.assertNotIn("http://bogus.gov", found) | ||
self.assertIn(paren_url, found) | ||
self.assertIn('http://example.org/' + 'b-(baz)', found) | ||
self.assertNotIn('http://example.org/' + 'b-(baz))', found) | ||
self.assertIn('http://example.org/index.html', found) | ||
# transforms | ||
self.assertNotIn('https://example.com/' + 'one.html).', found) | ||
self.assertNotIn('https://example.com/' + 'obsolete.html', found) | ||
self.assertNotIn('https://example.com/' + 'TEMPFIX.html', found) | ||
self.assertIn('https://example.com/' + 'one.html', found) | ||
self.assertIn('https://example.com/' + 'two.html', found) | ||
self.assertIn('https://example.com/' + 'three.html', found) | ||
|
||
def test_clear_previous_used(self): | ||
name1 = "blog.example.net" | ||
|
@@ -201,32 +221,6 @@ def test_read_repos_files(self): | |
self.assertIn("url-check.test.py", repo_files[repo_name]) | ||
self.assertNotIn("README.md", repo_files[repo_name]) | ||
|
||
def test_transform_urls(self): | ||
ctx = Test_Context() | ||
ctx.capture = True | ||
ctx.verbose = True | ||
transforms = [] | ||
urls = [ | ||
'https://example.org/one.html', | ||
'https://example.org/obsolete.html', | ||
'https://example.org/three.html', | ||
] | ||
transformed = uc.transform_urls(transforms, urls, ctx) | ||
self.assertEqual(transformed, urls) | ||
|
||
transforms = [ | ||
f"sed 's@obsolete\\[email protected])@g'", | ||
f"sed 's@foo@two@g'", | ||
f"sed 's@\\(example.org/.*\\)[\\.,)]$@\\1@g'", | ||
] | ||
expected_urls = [ | ||
'https://example.org/one.html', | ||
'https://example.org/two.html', | ||
'https://example.org/three.html', | ||
] | ||
transformed = uc.transform_urls(transforms, urls, ctx) | ||
self.assertEqual(transformed, expected_urls, ctx.out) | ||
|
||
def test_remove_unused(self): | ||
url3 = "https://example.org/three.html" | ||
checks = { | ||
|