Skip to content
Merged
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
23 changes: 11 additions & 12 deletions tests/test_libentry.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
import unittest
import json
import os
from pathlib import Path
import shutil
import pygit2
import OMPython

from ompackagemanager.updateinfo import new_libentry, getgitrepo
from ompackagemanager.updateinfo import new_libentry


class TestNewLibentry(unittest.TestCase):
@classmethod
def setUpClass(cls):
"""Clone git repositories, start OMC session."""

def checkout_repo(github_repo: str, refname: str) -> str:
def checkout_repo(github_repo: str, refname: str) -> Path:
"""Clone and checkout a git repository from GitHub"""
giturl = "https://github.com/%s.git" % github_repo
repopath = os.path.join(cls.cache_dir, github_repo.split("/")[-1])
repopath = cls.cache_dir.joinpath(github_repo.split("/")[-1])

if not os.path.exists(repopath):
if not repopath.is_dir():
pygit2.clone_repository(giturl, repopath)
gitrepo = pygit2.Repository(repopath)

Expand All @@ -32,10 +31,10 @@ def checkout_repo(github_repo: str, refname: str) -> str:
gitrepo.get(refname),
strategy=pygit2.GIT_CHECKOUT_FORCE | pygit2.GIT_CHECKOUT_RECREATE_MISSING)

return os.path.normpath(os.path.join(gitrepo.path, os.pardir))
return Path(gitrepo.path).joinpath().parent.resolve()

cls.cache_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), "tmp-cache")
os.makedirs(cls.cache_dir, exist_ok=True)
cls.cache_dir = Path(__file__).parent.joinpath("tmp-cache")
Path.mkdir(cls.cache_dir, parents=True, exist_ok=True)

cls.omc = OMPython.OMCSessionZMQ()
cls.omc.sendExpression('setCommandLineOptions("--std=latest")')
Expand Down Expand Up @@ -76,15 +75,15 @@ def test_aixlib_tag_version(self):

# Load package.mo
repopath = self.aixlib_path
hits = [os.path.join(repopath, "AixLib", "package.mo")]
hits = [str(repopath.joinpath("AixLib", "package.mo"))]
self.omc.sendExpression('loadFile("%s", uses=false)' % hits[0])

libentry = new_libentry(
libname=libname,
tagName=tagName,
entry=entry,
hits=hits,
repopath=repopath,
repopath=str(repopath),
omc=self.omc
)

Expand Down Expand Up @@ -128,7 +127,7 @@ def test_modelica_master_version(self):

# Load package.mo
repopath = self.msl_path
hits = [os.path.join(repopath, "Modelica", "package.mo")]
hits = [str(repopath.joinpath("Modelica", "package.mo"))]
self.omc.sendExpression('clear()')
self.omc.sendExpression('loadFile("%s", uses=false)' % hits[0])

Expand All @@ -137,7 +136,7 @@ def test_modelica_master_version(self):
tagName=branch,
entry=entry,
hits=hits,
repopath=repopath,
repopath=str(repopath),
omc=self.omc
)

Expand Down
28 changes: 25 additions & 3 deletions tests/test_main.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,30 @@
import unittest
from io import StringIO
from pathlib import Path
import sys

from ompackagemanager import __main__


class TestCLI(unittest.TestCase):
def test_run_check_missing(self):
class TestCaseBase(unittest.TestCase):
def assertIsFile(self, path: Path):
if not Path(path).resolve().is_file():
raise AssertionError("File does not exist: %s" % str(path))


class TestCLI(TestCaseBase):
def setUp(self) -> None:
"""Remove index.json"""
self.index_file = Path(__file__).parents[1].joinpath("index.json")
if self.index_file.is_file():
self.index_file.unlink()

def tearDown(self):
"""Remove index.json"""
if self.index_file.is_file():
self.index_file.unlink()

def test_run_check_missing(self) -> None:
saved_stdout = sys.stdout
try:
out = StringIO()
Expand All @@ -27,11 +45,15 @@ def test_run_check_missing(self):
modelica-3rdparty/ShipSIM
modelica-3rdparty/SMEHV
modelica-3rdparty/ThermoSysPro
modelica-3rdparty/urdfmodelica
''', out.getvalue())
finally:
sys.stdout = saved_stdout

def test_run_genindex(self) -> None:
__main__.main(["genindex"])

self.assertIsFile(self.index_file)


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