Skip to content

Commit

Permalink
test: add test to commands of tvm
Browse files Browse the repository at this point in the history
  • Loading branch information
JuanDavidBuitrago authored and Alec4r committed Aug 10, 2022
1 parent db1d198 commit f4f9606
Show file tree
Hide file tree
Showing 10 changed files with 151 additions and 19 deletions.
6 changes: 0 additions & 6 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,6 @@ def test_should_fail_if_version_does_not_exist():
assert 'Could not find target: v0.0.99' in result.stdout


def test_should_fail_if_version_is_not_installed():
runner = CliRunner()
result = runner.invoke(uninstall, ["v0.0.99"])
assert 'Nothing to uninstall' in result.stdout


def test_should_return_all_tvm_project_commands():
runner = CliRunner()
result = runner.invoke(projects)
Expand Down
32 changes: 32 additions & 0 deletions tests/version_manager/application/test_tutor_plugin_installer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import pytest

from tests.version_manager.infrastructure.version_manager_in_memory_repository import (
VersionManagerInMemoryRepository,
)
from tvm.version_manager.application.tutor_plugin_installer import TutorPluginInstaller


def test_should_install_the_tutor_plugin():
# Given
options = ["tutor-mfe"]
repository = VersionManagerInMemoryRepository()

# When
installer = TutorPluginInstaller(repository=repository)
installer(options)

# Then
assert options in repository.PLUGINS_INSTALLED


def test_should_fail_if_not_add_tutor_plugin():
# Given
options = []
repository = VersionManagerInMemoryRepository()

# When
installer = TutorPluginInstaller(repository=repository)

# Then
with pytest.raises(Exception) as format_err:
installer(options)
34 changes: 34 additions & 0 deletions tests/version_manager/application/test_tutor_plugin_uninstaller.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import pytest

from tests.version_manager.infrastructure.version_manager_in_memory_repository import (
VersionManagerInMemoryRepository,
)
from tvm.version_manager.application.tutor_plugin_uninstaller import (
TutorPluginUninstaller,
)


def test_should_uninstall_the_tutor_plugin():
# Given
options = "codejail"
repository = VersionManagerInMemoryRepository()

# When
uninstaller = TutorPluginUninstaller(repository=repository)
uninstaller(options)

# Then
assert options not in repository.VERSIONS_INSTALLED


def test_should_fail_if_not_add_tutor_plugin():
# Given
options = "tutor-mfe"
repository = VersionManagerInMemoryRepository()

# When
uninstaller = TutorPluginUninstaller(repository=repository)

# Then
with pytest.raises(Exception) as format_err:
uninstaller(options)
17 changes: 17 additions & 0 deletions tests/version_manager/application/test_tutor_version_enabler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from tests.version_manager.infrastructure.version_manager_in_memory_repository import (
VersionManagerInMemoryRepository,
)
from tvm.version_manager.application.tutor_version_enabler import TutorVersionEnabler


def test_should_enabler_the_tutor_version():
# Given
version = "v1.2.3"
repository = VersionManagerInMemoryRepository()

# When
enabler = TutorVersionEnabler(repository=repository)
enabler(version=version)

# Then
assert version in repository.VERSIONS_INSTALLED
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import pytest

from tests.version_manager.infrastructure.version_manager_in_memory_repository import VersionManagerInMemoryRepository
from tvm.version_manager.application.tutor_version_installer import TutorVersionInstaller
from tvm.version_manager.domain.tutor_version_format_error import TutorVersionFormatError
from tests.version_manager.infrastructure.version_manager_in_memory_repository import (
VersionManagerInMemoryRepository,
)
from tvm.version_manager.application.tutor_version_installer import (
TutorVersionInstaller,
)
from tvm.version_manager.domain.tutor_version_format_error import (
TutorVersionFormatError,
)


def test_should_fail_if_version_format_is_not_valid():
Expand Down
19 changes: 19 additions & 0 deletions tests/version_manager/application/test_tutor_version_lister.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from tests.version_manager.infrastructure.version_manager_in_memory_repository import (
VersionManagerInMemoryRepository,
)
from tvm.version_manager.application.tutor_vesion_lister import TutorVersionLister


def test_should_list_tutor_versions():
# Given
limit = 10
list_versions = []
for version in range(limit):
list_versions.append(f"v1.2.{version}")
repository = VersionManagerInMemoryRepository()

# When
lister = TutorVersionLister(repository=repository)

# Then
assert list_versions == lister(limit=limit)
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from tests.version_manager.infrastructure.version_manager_in_memory_repository import (
VersionManagerInMemoryRepository,
)
from tvm.version_manager.application.tutor_version_uninstaller import (
TutorVersionUninstaller,
)


def test_should_uninstall_the_tutor_version():
# Given
version = "v1.2.4"
repository = VersionManagerInMemoryRepository()

# When
uninstaller = TutorVersionUninstaller(repository=repository)
uninstaller(version=version)

# Then
assert version not in repository.VERSIONS_INSTALLED
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
from typing import List, Optional

from tvm.version_manager.domain.tutor_version import TutorVersion
from tvm.version_manager.domain.version_manager_repository import VersionManagerRepository
from tvm.version_manager.domain.version_manager_repository import (
VersionManagerRepository,
)


class VersionManagerInMemoryRepository(VersionManagerRepository):
VERSIONS_INSTALLED = []
VERSIONS_INSTALLED = ["v1.2.4"]
PLUGINS_INSTALLED = ["codejail"]
LIST_VERSIONS = []
for version in range(20):
LIST_VERSIONS.append(f"v1.2.{version}")

def list_versions(self, limit: int) -> List[TutorVersion]:
pass
return self.LIST_VERSIONS[0:limit]

@staticmethod
def local_versions(tvm_path: str) -> List[TutorVersion]:
Expand All @@ -25,17 +31,24 @@ def find_version(self, version: TutorVersion) -> Optional[TutorVersion]:
return version if version in self.VERSIONS_INSTALLED else None

def uninstall_version(self, version: TutorVersion) -> None:
pass
if version in self.VERSIONS_INSTALLED:
self.VERSIONS_INSTALLED.clear()

def use_version(self, version: TutorVersion) -> None:
pass
self.VERSIONS_INSTALLED[0] = version

@staticmethod
def version_is_installed(version: str) -> None:
pass

def install_plugin(self, options: List) -> None:
pass
if options:
self.PLUGINS_INSTALLED.append(options)
else:
raise Exception(f"Error running venv commands: None")

def uninstall_plugin(self, options: List) -> None:
pass
if options == self.PLUGINS_INSTALLED[0]:
self.PLUGINS_INSTALLED.clear()
else:
raise Exception(f"Error running venv commands: None")
3 changes: 1 addition & 2 deletions tvm/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -525,8 +525,7 @@ def uninstall_plugin(options):
options.insert(0, "uninstall")
options.append("-y")
uninstaller(options)
# click.echo(run_on_tutor_venv('pip', options))



@click.group(
name="config",
Expand Down
1 change: 0 additions & 1 deletion tvm/version_manager/application/tutor_plugin_installer.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from tvm.version_manager.domain.tutor_version import TutorVersion
from tvm.version_manager.domain.version_manager_repository import VersionManagerRepository


Expand Down

0 comments on commit f4f9606

Please sign in to comment.