File: test_parsers.py

package info (click to toggle)
python-spython 0.3.13-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 736 kB
  • sloc: python: 3,299; sh: 61; makefile: 28
file content (63 lines) | stat: -rw-r--r-- 2,009 bytes parent folder | download
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
#!/usr/bin/python

# Copyright (C) 2017-2024 Vanessa Sochat.

# This Source Code Form is subject to the terms of the
# Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed
# with this file, You can obtain one at http://mozilla.org/MPL/2.0/.

import os

from spython.main.parse.parsers import DockerParser, SingularityParser


def test_get_parser():
    from spython.main.parse.parsers import get_parser

    parser = get_parser("docker")
    assert parser == DockerParser

    parser = get_parser("Dockerfile")
    assert parser == DockerParser

    parser = get_parser("Singularity")
    assert parser == SingularityParser


def test_docker_parser(test_data):
    dockerfile = os.path.join(test_data["root"], "Dockerfile")
    parser = DockerParser(dockerfile)

    assert str(parser) == "[spython-parser][docker]"
    assert "spython-base" in parser.recipe
    recipe = parser.recipe["spython-base"]

    # Test all fields from recipe
    assert recipe.fromHeader == "python:3.5.1"
    assert recipe.cmd == "/code/run_uwsgi.sh"
    assert recipe.entrypoint is None
    assert recipe.workdir == "/code"
    assert recipe.volumes == []
    assert recipe.ports == ["3031"]
    assert recipe.files[0] == ["requirements.txt", "/tmp/requirements.txt"]
    assert recipe.environ == ["PYTHONUNBUFFERED=1"]
    assert recipe.source == dockerfile


def test_singularity_parser(test_data):
    recipefile = os.path.join(test_data["root"], "Singularity")
    parser = SingularityParser(recipefile)

    assert str(parser) == "[spython-parser][singularity]"
    assert "spython-base" in parser.recipe
    recipe = parser.recipe["spython-base"]

    # Test all fields from recipe
    assert recipe.fromHeader == "continuumio/miniconda3"
    assert recipe.cmd == 'exec /opt/conda/bin/spython "$@"'
    assert recipe.entrypoint is None
    assert recipe.workdir is None
    assert recipe.volumes == []
    assert recipe.files == []
    assert recipe.environ == []
    assert recipe.source == recipefile