aboutsummaryrefslogtreecommitdiff
path: root/tests/test_merge.py
blob: 168d2cc3c70bd498383bfc183c0d1b35f5006f4e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
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)