Skip to content

Commit

Permalink
Update parser tests (#944)
Browse files Browse the repository at this point in the history
Since we no longer have reliable name, find a best matching package in parsed packages for each sample and compare sample with it
  • Loading branch information
AMDmi3 committed Nov 12, 2019
1 parent 5f196b0 commit 2723c72
Showing 1 changed file with 35 additions and 42 deletions.
77 changes: 35 additions & 42 deletions repology/test/test_parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def setUp(self) -> None:
self.maxDiff = None
self.packages = list(repoproc.iter_parse(reponames=['have_testdata']))

def check_package(self, name: str, reference: Dict[str, Any]) -> None:
def check_package(self, reference: Dict[str, Any]) -> None:
reference_with_default: Dict[str, Any] = {
# repo must be filled
# family must be filled
Expand Down Expand Up @@ -77,40 +77,46 @@ def check_package(self, name: str, reference: Dict[str, Any]) -> None:
'versionclass',
]

reference_with_default.update(reference)

def sort_lists(what: Dict[str, Any]) -> Dict[str, Any]:
def normalize_fields(what: Dict[str, Any]) -> Dict[str, Any]:
output = {}
for key, value in what.items():
if isinstance(value, list):
if key in ignored_fields:
pass
elif isinstance(value, list):
output[key] = sorted(value)
else:
output[key] = value

return output

reference_with_default.update(reference)
reference_with_default = normalize_fields(reference_with_default)

best_match = None
best_match_score = 0

for package in self.packages:
if package.name == name:
actual_fields = package.__dict__
for field in ignored_fields:
actual_fields.pop(field, None)
actual_fields = normalize_fields(package.__dict__)

score = sum(1 for key in actual_fields.keys() if reference_with_default[key] == actual_fields[key])

if score > best_match_score:
best_match_score = score
best_match = package

self.assertEqual(
sort_lists(actual_fields),
sort_lists(reference_with_default)
)
return
if best_match is None:
self.assertFalse('package not found')

self.assertFalse('package not found')
self.assertEqual(normalize_fields(best_match.__dict__), reference_with_default)

def test_freebsd(self) -> None:
self.check_package(
'vorbis-tools',
{
'repo': 'freebsd',
'family': 'freebsd',
'name': 'vorbis-tools',
'keyname': 'audio/vorbis-tools',
'srcname': 'audio/vorbis-tools',
'binname': 'vorbis-tools',
'trackname': 'audio/vorbis-tools',
'visiblename': 'audio/vorbis-tools',
'projectname_seed': 'vorbis-tools',
'version': '1.4.0',
Expand All @@ -125,12 +131,11 @@ def test_freebsd(self) -> None:

def test_gentoo(self) -> None:
self.check_package(
'chromium-bsu',
{
'repo': 'gentoo',
'family': 'gentoo',
'name': 'chromium-bsu',
'keyname': 'games-action/chromium-bsu',
'srcname': 'games-action/chromium-bsu',
'trackname': 'games-action/chromium-bsu',
'visiblename': 'games-action/chromium-bsu',
'projectname_seed': 'chromium-bsu',
'version': '0.9.15.1',
Expand All @@ -145,12 +150,11 @@ def test_gentoo(self) -> None:
}
)
self.check_package(
'asciinema',
{
'repo': 'gentoo',
'family': 'gentoo',
'name': 'asciinema',
'keyname': 'app-misc/asciinema',
'srcname': 'app-misc/asciinema',
'trackname': 'app-misc/asciinema',
'visiblename': 'app-misc/asciinema',
'projectname_seed': 'asciinema',
'version': '1.3.0',
Expand All @@ -165,12 +169,11 @@ def test_gentoo(self) -> None:
}
)
self.check_package(
'away',
{
'repo': 'gentoo',
'family': 'gentoo',
'name': 'away',
'keyname': 'app-misc/away',
'srcname': 'app-misc/away',
'trackname': 'app-misc/away',
'visiblename': 'app-misc/away',
'projectname_seed': 'away',
'version': '0.9.5',
Expand All @@ -185,12 +188,11 @@ def test_gentoo(self) -> None:
}
)
self.check_package(
'aspell',
{
'repo': 'gentoo',
'family': 'gentoo',
'name': 'aspell',
'keyname': 'app-test/aspell',
'srcname': 'app-test/aspell',
'trackname': 'app-test/aspell',
'visiblename': 'app-test/aspell',
'projectname_seed': 'aspell',
'version': '0.60.7_rc1',
Expand All @@ -207,13 +209,13 @@ def test_gentoo(self) -> None:

def test_arch(self) -> None:
self.check_package(
'zlib',
{
'repo': 'arch',
'family': 'arch',
'subrepo': 'core',
'name': 'zlib',
'basename': 'zlib',
'srcname': 'zlib',
'binname': 'zlib',
'trackname': 'zlib',
'visiblename': 'zlib',
'projectname_seed': 'zlib',
'version': '1.2.8',
Expand All @@ -224,13 +226,11 @@ def test_arch(self) -> None:
'homepage': 'http://www.zlib.net/',
'licenses': ['custom'],
'maintainers': [],
'extrafields': {'base': 'zlib'},
}
)

def test_cpan(self) -> None:
self.check_package(
'Acme-Brainfuck',
{
'repo': 'cpan',
'family': 'cpan',
Expand All @@ -248,7 +248,6 @@ def test_cpan(self) -> None:

def test_debian(self) -> None:
self.check_package(
'a52dec',
{
'repo': 'debian_unstable',
'subrepo': 'main',
Expand All @@ -272,7 +271,6 @@ def test_debian(self) -> None:

def test_gobolinux(self) -> None:
self.check_package(
'AutoFS',
{
'repo': 'gobolinux',
'family': 'gobolinux',
Expand All @@ -295,7 +293,6 @@ def test_gobolinux(self) -> None:
def test_slackbuilds(self) -> None:
# multiline DOWNLOAD
self.check_package(
'virtualbox',
{
'repo': 'slackbuilds',
'family': 'slackbuilds',
Expand All @@ -318,7 +315,6 @@ def test_slackbuilds(self) -> None:
)
# different DOWNLOAD and DOWNLOAD_x86_64
self.check_package(
'baudline',
{
'repo': 'slackbuilds',
'family': 'slackbuilds',
Expand All @@ -339,7 +335,6 @@ def test_slackbuilds(self) -> None:
)
# DOWNLOAD_x86_64 is UNSUPPORTED
self.check_package(
'teamviewer',
{
'repo': 'slackbuilds',
'family': 'slackbuilds',
Expand All @@ -359,7 +354,6 @@ def test_slackbuilds(self) -> None:
)
# DOWNLOAD is UNSUPPORTED
self.check_package(
'oracle-xe',
{
'repo': 'slackbuilds',
'family': 'slackbuilds',
Expand All @@ -379,7 +373,6 @@ def test_slackbuilds(self) -> None:
)
# DOWNLOAD_x86_64 is UNTESTED
self.check_package(
'kforth',
{
'repo': 'slackbuilds',
'family': 'slackbuilds',
Expand Down

0 comments on commit 2723c72

Please sign in to comment.