aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tests/test_conda.py26
-rw-r--r--tests/test_merge.py63
2 files changed, 89 insertions, 0 deletions
diff --git a/tests/test_conda.py b/tests/test_conda.py
new file mode 100644
index 0000000..6dfa4de
--- /dev/null
+++ b/tests/test_conda.py
@@ -0,0 +1,26 @@
+import os
+import pytest
+from delivery_merge import conda
+
+
+class TestConda:
+ def setup_class(self):
+ self.version = '4.5.12'
+ self.prefix = conda.conda_installer(self.version)
+ assert os.path.exists(self.prefix)
+
+ def teardown_class(self):
+ pass
+
+ def test_init_path(self):
+ conda.conda_init_path(self.prefix)
+ assert os.environ.get('PATH', '').startswith(self.prefix)
+
+ def test_shell_wrapper(self):
+ output = conda.conda('info').stdout.decode()
+ assert self.prefix in output
+ assert self.version in output
+
+ def test_env_load(self):
+ with conda.conda_env_load('base') as _:
+ assert os.environ.get('CONDA_PREFIX', '')
diff --git a/tests/test_merge.py b/tests/test_merge.py
new file mode 100644
index 0000000..168d2cc
--- /dev/null
+++ b/tests/test_merge.py
@@ -0,0 +1,63 @@
+import pytest
+from delivery_merge import merge
+
+
+COMMENTS_DELIM = [';', '#']
+COMMENTS = """; comment
+; comment ; comment
+;comment;comment
+;comment#comment
+data ; comment
+data ; comment
+data; comment
+data;comment
+# comment
+# comment # comment
+#comment#comment
+#comment;comment
+data # comment
+data # comment
+data# comment
+data#comment
+"""
+DMFILE = """
+; Example
+python # dmfile
+nomkl
+numpy>=1.16.3
+
+"""
+DMFILE_INVALID = f"""
+{DMFILE}
+invalid package specification
+"""
+
+class TestMerge:
+ def setup_class(self):
+ self.input_file = 'sample.dm'
+ self.input_file_invalid = 'sample_invalid.dm'
+ self.input_file_empty = 'sample_empty.dm'
+ open(self.input_file, 'w+').write(DMFILE)
+ open(self.input_file_invalid, 'w+').write(DMFILE_INVALID)
+ open(self.input_file_empty, 'w+').write("")
+
+ def teardown_class(self):
+ pass
+
+ @pytest.mark.parametrize('comments', [x for x in COMMENTS.splitlines()])
+ def test_comment_find(self, comments):
+ index = merge.comment_find(comments)
+ assert comments[index] in COMMENTS_DELIM
+
+ def test_dmfile(self):
+ data = merge.dmfile(self.input_file)
+ assert COMMENTS_DELIM not in data
+ assert all([merge.DMFILE_RE.match(x) for x in data])
+
+ def test_dmfile_raises_InvalidPackageSpec(self):
+ with pytest.raises(merge.InvalidPackageSpec):
+ merge.dmfile(self.input_file_invalid)
+
+ def test_dmfile_raises_EmptyPackageSpec(self):
+ with pytest.raises(merge.EmptyPackageSpec):
+ merge.dmfile(self.input_file_empty)