blob: 5ebb5d1f3b490e71271da8b0b4e9a25c89e2891b [file] [log] [blame]
# Copyright 2020 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Tests for dependency_lib."""
import os
from chromite.lib import dependency_lib
from chromite.lib import osutils
def test_parse_ebuild_cache_entry_md5_cache(tmp_path):
"""Verify parsing eclasses from md5 cache style files."""
expected = [
('eclass1', 'abc123'),
('eclass2', '123abc'),
('eclass3', 'def789'),
]
eclass_str = '\t'.join('\t'.join(x) for x in expected)
contents = f"""
KEYWORDS=*
LICENSE=license
PROPERTIES=live
RDEPEND=>=foo/bar-0.0.1:= foo/baz:=
SLOT=0/0
_eclasses_={eclass_str}
_md5=123456
"""
cache_file = os.path.join(tmp_path, 'cache_file')
osutils.WriteFile(cache_file, contents)
# pylint: disable=protected-access
result = dependency_lib._parse_ebuild_cache_entry(cache_file)
assert set(expected) == set(result)
def test_parse_ebuild_cache_entry_edb_cache(tmp_path):
"""Verify parsing eclasses from edb cache style files."""
expected = [
('eclass1', 'abc123'),
('eclass2', '123abc'),
('eclass3', 'def789'),
]
eclass_str = '\t'.join('\t'.join((c, '/some/path', d)) for (c, d) in expected)
contents = f"""
KEYWORDS=*
LICENSE=license
PROPERTIES=live
RDEPEND=>=foo/bar-0.0.1:= foo/baz:=
SLOT=0/0
_eclasses_={eclass_str}
_md5=123456
"""
cache_file = os.path.join(tmp_path, 'cache_file')
osutils.WriteFile(cache_file, contents)
# pylint: disable=protected-access
result = dependency_lib._parse_ebuild_cache_entry(cache_file)
assert set(expected) == set(result)