Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Setup initial unit tests for conductor #329

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pros/conductor/conductor.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from typing import *

import click
from semantic_version import Spec, Version
from semantic_version import Spec, Version, SimpleSpec

from pros.common import *
from pros.conductor.project import TemplateAction
Expand Down Expand Up @@ -191,7 +191,7 @@ def resolve_template(self, identifier: Union[str, BaseTemplate], **kwargs) -> Op
logger(__name__).info(f'Candidates: {", ".join([str(t) for t in templates])}')
if not any(templates):
return None
query.version = str(Spec(query.version or '>0').select([Version(t.version) for t in templates]))
query.version = str(SimpleSpec(query.version or '>0').select([Version(t.version) for t in templates]))
v = Version(query.version)
v.prerelease = v.prerelease if len(v.prerelease) else ('',)
v.build = v.build if len(v.build) else ('',)
Expand Down
10 changes: 8 additions & 2 deletions pros/conductor/templates/base_template.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import *

from semantic_version import Spec, Version
from semantic_version import Spec, Version, SimpleSpec

from pros.common import ui

Expand Down Expand Up @@ -30,7 +30,7 @@ def satisfies(self, query: 'BaseTemplate', kernel_version: Union[str, Version] =
return False
if query.target and self.target != query.target:
return False
if query.version and Version(self.version) not in Spec(query.version):
if query.version and Version(self.version) not in SimpleSpec(query.version):
return False
if kernel_version and isinstance(kernel_version, str):
kernel_version = Version(kernel_version)
Expand Down Expand Up @@ -62,6 +62,12 @@ def __eq__(self, other):
else:
return super().__eq__(other)

def __ge__(self, other):
if isinstance(other, BaseTemplate):
return self.identifier >= other.identifier
else:
return super().__ge__(other)

def __hash__(self):
return self.identifier.__hash__()

Expand Down
Empty file added test/__init__.py
Empty file.
19 changes: 19 additions & 0 deletions test/test_conductor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from pros.conductor import Conductor
from pros.conductor.templates import LocalTemplate
import unittest


class TestConductor(unittest.TestCase):
### using __init__() with the unittest module causes errors, setUp is recognized by the module and should be used instead.
# setUp will run before every unit test
def setUp(self):
self._conductor = Conductor()

def test_resolve_template(self):
okapilib_template = LocalTemplate(name="okapilib", version="5.0.0")
resolved_template = self._conductor.resolve_template(identifier="okapilib")
self.assertTrue(resolved_template >= okapilib_template)


if __name__ == "__main__":
unittest.main()
Loading