Skip to content

Commit

Permalink
pylintrc: re-enable too-many-lines, final patch
Browse files Browse the repository at this point in the history
To get under the 1000 line limit, move ycheck unit
tests into their own directory, and split-up into
sub-files as necessary.

Finally, enable the too-many-lines check in pylintrc.
  • Loading branch information
brianphaley committed Jul 17, 2024
1 parent afaf2e8 commit 55936d2
Show file tree
Hide file tree
Showing 9 changed files with 915 additions and 900 deletions.
1 change: 0 additions & 1 deletion pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,4 @@ disable=
too-many-arguments,
too-many-branches,
too-many-instance-attributes,
too-many-lines,
too-many-locals,
Empty file added tests/unit/ycheck/__init__.py
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
EventProcessingUtils,
)

from . import utils
from .. import utils

EVENT_DEF_INPUT = """
pluginX:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@

import yaml
from hotsos.core.config import HotSOSConfig
from hotsos.core.host_helpers import (
DPKGVersion
)
from hotsos.core.host_helpers.config import IniConfigBase
from hotsos.core.issues.utils import IssuesStore
from hotsos.core.search import ExtraSearchConstraints
Expand All @@ -23,14 +20,8 @@
PropertyCacheRefResolver,
)
from hotsos.core.ycheck.common import GlobalSearcher
from hotsos.core.ycheck.engine.properties.requires.types import (
apt,
binary,
snap,
)
from hotsos.core.plugins import juju

from . import utils
from .. import utils


class TestProperty(YPropertyBase):
Expand Down Expand Up @@ -225,10 +216,6 @@ def __init__(self, name, state, has_instances, start_time):
- apt: python1.0
"""

DPKG_L = """
ii openssh-server 1:8.2p1-4ubuntu0.4 amd64 secure shell (SSH) server, for secure access from remote machines
""" # noqa


class TempScenarioDefs():
""" Context manager to load copies of scenario definitions into a temporary
Expand Down Expand Up @@ -444,323 +431,6 @@ def test_grouped_items_all_true_mixed_types_snap_first(self):
self.assertEqual(issues[0]['message'], 'snapd')


class TestYamlRequiresTypeBinary(utils.BaseTestCase):
""" Tests requires type binary property. """

def test_binary_check_comparison(self):
items = binary.BinCheckItems({'juju': [{'min': '3.0', 'max': '3.2'}]},
bin_handler=juju.JujuBinaryInterface)
self.assertEqual(items.installed, ['juju'])
self.assertEqual(items.not_installed, set())
_bin, versions = list(items)[0]
version = items.packaging_helper.get_version(_bin)
self.assertFalse(DPKGVersion.is_version_within_ranges(version,
versions))

items = binary.BinCheckItems({'juju': [{'min': '2.9', 'max': '3.2'}]},
bin_handler=juju.JujuBinaryInterface)
self.assertEqual(items.installed, ['juju'])
self.assertEqual(items.not_installed, set())
_bin, versions = list(items)[0]
version = items.packaging_helper.get_version(_bin)
self.assertTrue(DPKGVersion.is_version_within_ranges(version,
versions))

items = binary.BinCheckItems({'juju': [{'min': '2.9.2',
'max': '2.9.22'}]},
bin_handler=juju.JujuBinaryInterface)
self.assertEqual(items.installed, ['juju'])
self.assertEqual(items.not_installed, set())
_bin, versions = list(items)[0]
version = items.packaging_helper.get_version(_bin)
self.assertTrue(DPKGVersion.is_version_within_ranges(version,
versions))


class TestYamlRequiresTypeAPT(utils.BaseTestCase):
""" Tests requires type apt property. """

@staticmethod
def load_apt_requires(yaml_content):
return apt.YRequirementTypeAPT(
"requires",
"apt",
yaml.safe_load(yaml_content),
"requires.apt")

@utils.create_data_root({'sos_commands/dpkg/dpkg_-l': DPKG_L})
def test_apt_no_criteria(self):
content = r"""
openssh-server:
"""
self.assertTrue(self.load_apt_requires(content).result)

@utils.create_data_root({'sos_commands/dpkg/dpkg_-l': DPKG_L})
def test_apt_no_criteria_alt_form(self):
content = r"""
- openssh-server
"""
self.assertTrue(self.load_apt_requires(content).result)

@utils.create_data_root({'sos_commands/dpkg/dpkg_-l': DPKG_L})
def test_apt_no_criteria_name_mismatch(self):
# We expect test to fail because no such package exist.
content = r"""
openssh-serverx:
"""
self.assertFalse(self.load_apt_requires(content).result)

@utils.create_data_root({'sos_commands/dpkg/dpkg_-l': DPKG_L})
def test_apt_name_mismatch(self):
content = r"""
openssh-serverx:
- eq: '1:8.2p1-4ubuntu0.4'
"""
self.assertFalse(self.load_apt_requires(content).result)

@utils.create_data_root({'sos_commands/dpkg/dpkg_-l': DPKG_L})
def test_apt_gt_single_true(self):
content = r"""
openssh-server:
- gt: '1:8.2'
"""
self.assertTrue(self.load_apt_requires(content).result)

@utils.create_data_root({'sos_commands/dpkg/dpkg_-l': DPKG_L})
def test_apt_gt_single_false(self):
content = r"""
openssh-server:
- gt: '1:8.2p1-4ubuntu0.4'
"""
self.assertFalse(self.load_apt_requires(content).result)

@utils.create_data_root({'sos_commands/dpkg/dpkg_-l': DPKG_L})
def test_apt_ge_single_true(self):
content = r"""
openssh-server:
- ge: '1:8.2'
"""
self.assertTrue(self.load_apt_requires(content).result)

@utils.create_data_root({'sos_commands/dpkg/dpkg_-l': DPKG_L})
def test_apt_ge_single_false(self):
content = r"""
openssh-server:
- ge: '1:8.2p1-4ubuntu0.5'
"""
self.assertFalse(self.load_apt_requires(content).result)

@utils.create_data_root({'sos_commands/dpkg/dpkg_-l': DPKG_L})
def test_apt_lt_single_true(self):
content = r"""
openssh-server:
- lt: '1:8.2p1-4ubuntu0.5'
"""
self.assertTrue(self.load_apt_requires(content).result)

@utils.create_data_root({'sos_commands/dpkg/dpkg_-l': DPKG_L})
def test_apt_lt_single_false(self):
content = r"""
openssh-server:
- lt: '1:8.2p1-4ubuntu0.3'
"""
self.assertFalse(self.load_apt_requires(content).result)

@utils.create_data_root({'sos_commands/dpkg/dpkg_-l': DPKG_L})
def test_apt_le_single_true(self):
content = r"""
openssh-server:
- le: '1:8.2p1-4ubuntu0.4'
"""
self.assertTrue(self.load_apt_requires(content).result)

@utils.create_data_root({'sos_commands/dpkg/dpkg_-l': DPKG_L})
def test_apt_le_single_false(self):
content = r"""
openssh-server:
- le: '1:8.2p1-4ubuntu0.3'
"""
self.assertFalse(self.load_apt_requires(content).result)

@utils.create_data_root({'sos_commands/dpkg/dpkg_-l': DPKG_L})
def test_apt_eq_single_true(self):
content = r"""
openssh-server:
- eq: '1:8.2p1-4ubuntu0.4'
"""
self.assertTrue(self.load_apt_requires(content).result)

@utils.create_data_root({'sos_commands/dpkg/dpkg_-l': DPKG_L})
def test_apt_eq_single_false(self):
content = r"""
openssh-server:
- eq: '1:8.2p1-4ubuntu0.4.4'
"""
self.assertFalse(self.load_apt_requires(content).result)

@utils.create_data_root({'sos_commands/dpkg/dpkg_-l': DPKG_L})
def test_apt_eq_multiple_true(self):
content = r"""
openssh-server:
- eq: '1:8.2p1-4ubuntu0.1'
- eq: '1:8.2p1-4ubuntu0.2'
- eq: '1:8.2p1-4ubuntu0.3'
- eq: '1:8.2p1-4ubuntu0.4' # <-- should match this
- eq: '1:8.2p1-4ubuntu0.5'
"""
self.assertTrue(self.load_apt_requires(content).result)

@utils.create_data_root({'sos_commands/dpkg/dpkg_-l': DPKG_L})
def test_apt_eq_multiple_false(self):
content = r"""
openssh-server:
- eq: '1:8.2p1-4ubuntu0.1'
- eq: '1:8.2p1-4ubuntu0.2'
- eq: '1:8.2p1-4ubuntu0.3'
- eq: '1:8.2p1-4ubuntu0.5'
- eq: '1:8.2p1-4ubuntu0.6'
"""
self.assertFalse(self.load_apt_requires(content).result)

@utils.create_data_root({'sos_commands/dpkg/dpkg_-l': DPKG_L})
def test_apt_ge_multiple(self):
content = r"""
openssh-server:
- ge: '1:8.9'
- gt: '1:8.1' # <-- should match
lt: '1:8.3'
"""
self.assertTrue(self.load_apt_requires(content).result)

@utils.create_data_root({'sos_commands/dpkg/dpkg_-l': DPKG_L})
def test_apt_mixed(self):
content = r"""
openssh-server:
- ge: '1:8.9 '
- lt: '1:4'
- ge: '1:6.3'
lt: '1:7.2'
"""
self.assertFalse(self.load_apt_requires(content).result)


class TestYamlRequiresTypeSnap(utils.BaseTestCase):
""" Tests requires type snap property. """

def test_snap_revision_within_ranges_no_channel_true(self):
ci = snap.SnapCheckItems('core20')
result = ci.package_info_matches('core20', [
{
'revision': {'min': '1327',
'max': '1328'}
}
])
self.assertTrue(result)

def test_snap_revision_within_ranges_no_channel_false(self):
ci = snap.SnapCheckItems('core20')
result = ci.package_info_matches('core20', [
{
'revision': {'min': '1326',
'max': '1327'}
}
])
self.assertFalse(result)

def test_snap_revision_within_ranges_channel_true(self):
ci = snap.SnapCheckItems('core20')
result = ci.package_info_matches('core20', [
{
'revision': {'min': '1327',
'max': '1328'},
'channel': 'latest/stable'
}
])
self.assertTrue(result)

def test_snap_revision_within_ranges_channel_false(self):
ci = snap.SnapCheckItems('core20')
result = ci.package_info_matches('core20', [
{
'revision': {'min': '1327',
'max': '1328'},
'channel': 'foo'
}
])
self.assertFalse(result)

def test_snap_revision_within_multi_ranges_channel_true(self):
ci = snap.SnapCheckItems('core20')
result = ci.package_info_matches('core20', [
{
'revision': {'min': '1326',
'max': '1327'},
'channel': 'foo'
},
{
'revision': {'min': '1327',
'max': '1328'},
'channel': 'latest/stable'
},
{
'revision': {'min': '1329',
'max': '1330'},
'channel': 'bar'
}
])
self.assertTrue(result)

def test_snap_revision_with_invalid_range(self):
with self.assertRaises(Exception):
snap.SnapCheckItems('core20').package_info_matches('core20', [
{
'revision': {'mix': '1327'}
}
])

def test_snap_version_check_min_max(self):
ci = snap.SnapCheckItems('core20')
result = ci.package_info_matches('core20', [
{
'version': {'min': '20220114',
'max': '20220114'}
}
])
self.assertTrue(result)

def test_snap_version_check_lt(self):
ci = snap.SnapCheckItems('core20')
result = ci.package_info_matches('core20', [
{
'version': {'lt': '20220115'}
}
])
self.assertTrue(result)

def test_snap_version_check_gt_lt(self):
ci = snap.SnapCheckItems('core20')
result = ci.package_info_matches('core20', [
{
'version': {'gt': '20220113',
'lt': '20220115'}
}
])
self.assertTrue(result)

def test_snap_version_check_everything(self):
ci = snap.SnapCheckItems('core20')
print(ci.installed_revisions)
result = ci.package_info_matches('core20', [
{
'version': {'gt': '20220113',
'lt': '20220115'},
'channel': 'latest/stable',
'revision': {'eq': '1328'}
}
])
self.assertTrue(result)


class TestYamlProperties(utils.BaseTestCase):
""" Miscellaneous tests for YAML properties. """

Expand Down
Loading

0 comments on commit 55936d2

Please sign in to comment.