示例#1
0
 def test_repr(self):
     plantuml = self._get_auto_plantuml()
     assert repr(
         plantuml
     ) == '<LocalPlantuml java: {java}, plantuml: {plantuml}>'.format(
         java=repr(where.first('java')),
         plantuml=repr(path),
     )
示例#2
0
{%- endfor %}
#   clang 3.9
{%- for c in builders %}
    - env: DOCKER_TAG=clang-3.9 TESTS={{c}}
{%- endfor %}

# THIS FILE IS AUTOGENERATED -- DO NOT EDIT #
'''

import os
import jinja2
import sys
import where
import subprocess

tpl = jinja2.Template(tpl)
builder_count = int(sys.argv[1])
ymlfn = os.path.join(os.path.dirname(__file__), '.travis.yml')
with open(ymlfn, 'wt') as yml:
    yml.write(tpl.render(builders=range(0, builder_count)))
travis = where.first('travis')
if travis:
    try:
        subprocess.check_call([str(travis), 'lint', ymlfn])
    except subprocess.CalledProcessError as err:
        print('Linting {} failed'.format(ymlfn))
        print(err)
        sys.exit(-1)
else:
    print('Travis linter missing. Try:\ngem install travis')
示例#3
0
def get_py_prefix():
    py = where.first("python") or where.first("python3")
    if not py:
        raise EnvironmentError(
            "No python3 or python executive files were found.")
    return py
示例#4
0
def test_where_first_executes():
    import where
    where.first("python")
示例#5
0
def test_where_first_executes():
    where.first("python")
示例#6
0
 def test_local_plantuml(self):
     plantuml = self._get_local_plantuml_by_try_plantuml(
         plantuml=PRIMARY_JAR_PATH)
     assert isinstance(plantuml, LocalPlantuml)
     assert plantuml.java == where.first('java')
     assert plantuml.plantuml == PRIMARY_JAR_PATH
示例#7
0
for modname in modnames:
    del sys.modules[modname]

# Build dependencies if needed
if not os.environ.get("NO_CONTENTS_BUILD"):
    _env = dict(os.environ)
    _env.update(
        dict(
            SOURCEDIR=_DOC_PATH,
            BUILDDIR=os.path.abspath(os.path.join(_DOC_PATH, '..', 'build')),
            PYTHONPATH=':'.join([_PROJ_PATH, _LIBS_PATH]),
            PATH=':'.join([_SHIMS_PATH,
                           os.environ.get('PATH', '')]),
        ))

    pip_cmd = (where.first('pip'), 'install', '-r',
               os.path.join(_PROJ_PATH, 'requirements.txt'))
    print("Install pip requirements {cmd}...".format(cmd=repr(pip_cmd)))
    pip = Popen(pip_cmd,
                stdout=sys.stdout,
                stderr=sys.stderr,
                env=_env,
                cwd=_DOC_PATH)
    if pip.wait() != 0:
        raise ChildProcessError("Pip install failed with %d." %
                                (pip.returncode, ))

    pip_docs_cmd = (where.first('pip'), 'install', '-r',
                    os.path.join(_PROJ_PATH, 'requirements-doc.txt'))
    print("Install pip docs requirements {cmd}...".format(
        cmd=repr(pip_docs_cmd)))
示例#8
0
{%- endfor %}
#   clang 3.9
{%- for c in builders %}
    - env: DOCKER_TAG=clang TESTS={{c}}
{%- endfor %}

# THIS FILE IS AUTOGENERATED -- DO NOT EDIT #
'''

import os
import jinja2
import sys
import where
import subprocess

tpl = jinja2.Template(tpl)
builder_count = int(sys.argv[1])
ymlfn = os.path.join(os.path.dirname(__file__), '.travis.yml')
with open(ymlfn, 'wt') as yml:
    yml.write(tpl.render(builders=range(0, builder_count)))
travis = where.first('travis')
if travis:
    try:
        subprocess.check_call([str(travis), 'lint', ymlfn])
    except subprocess.CalledProcessError as err:
        print('Linting {} failed'.format(ymlfn))
        print(err)
        sys.exit(-1)
else:
    print('Travis linter missing. Try:\ngem install travis')
示例#9
0
def find_java_from_env() -> Optional[str]:
    return where.first('java')
示例#10
0
 def test_java(self):
     plantuml = self._get_auto_plantuml()
     assert plantuml.java == where.first('java')
示例#11
0
 def _get_plantuml(cls,
                   plantuml: str,
                   java: Optional[str] = None) -> LocalPlantuml:
     return LocalPlantuml(
         where.first('java') if java is None else java, plantuml)
示例#12
0
def _get_test_class(version: str, path: str):
    _common_condition = all_func(exist_func(version), is_file_func(path),
                                 lambda: where.first('java'))
    _dead_file_condition = all_func(_common_condition,
                                    is_file_func(DEAD_FILE_PATH))
    _broken_jar_condition = all_func(_common_condition,
                                     is_file_func(BROKEN_JAR_PATH))
    _invalid_jar_condition = all_func(_common_condition,
                                      is_file_func(INVALID_JAR_PATH))
    _helloworld_condition = all_func(_common_condition,
                                     is_file_func(DEMO_HELLOWORLD_PUML))

    # noinspection DuplicatedCode
    class _TestModelsLocal:
        @classmethod
        def _get_plantuml(cls,
                          plantuml: str,
                          java: Optional[str] = None) -> LocalPlantuml:
            return LocalPlantuml(
                where.first('java') if java is None else java, plantuml)

        @classmethod
        def _get_auto_plantuml(cls) -> LocalPlantuml:
            return LocalPlantuml.autoload(plantuml=path)

        @mark_select(_common_condition)
        def test_init_error(self):
            with pytest.raises(ValueError):
                _ = self._get_plantuml(java='', plantuml=path)
            with pytest.raises(FileNotFoundError):
                _ = self._get_plantuml(java='path_not_exist', plantuml=path)
            with pytest.raises(IsADirectoryError):
                _ = self._get_plantuml(java=os.path.dirname(path),
                                       plantuml=path)

            with pytest.raises(ValueError):
                _ = self._get_plantuml(plantuml='')
            with pytest.raises(FileNotFoundError):
                _ = self._get_plantuml(plantuml='path_not_exist')
            with pytest.raises(IsADirectoryError):
                _ = self._get_plantuml(plantuml=os.path.dirname(path))

        @mark_select(_dead_file_condition)
        def test_init_error_dead(self):
            with pytest.raises(PermissionError):
                _ = self._get_plantuml(java=DEAD_FILE_PATH, plantuml=path)
            with pytest.raises(PermissionError):
                _ = self._get_plantuml(plantuml=DEAD_FILE_PATH)

        @mark_select(_common_condition)
        def test_version(self):
            plantuml = self._get_auto_plantuml()
            assert version in plantuml.version
            assert 'plantuml' in plantuml.version.lower()

        @mark_select(_broken_jar_condition)
        def test_version_broken(self):
            plantuml = self._get_plantuml(plantuml=BROKEN_JAR_PATH)
            with pytest.raises(LocalPlantumlExecuteError) as e:
                _ = plantuml.version

            err = e.value
            assert err.exitcode == 1
            assert "invalid or corrupt jarfile" in err.stderr.lower()

        @mark_select(_invalid_jar_condition)
        def test_version_invalid(self):
            plantuml = self._get_plantuml(plantuml=INVALID_JAR_PATH)
            with pytest.raises(ValueError):
                _ = plantuml.version

        @mark_select(_common_condition)
        def test_java(self):
            plantuml = self._get_auto_plantuml()
            assert plantuml.java == where.first('java')

        @mark_select(_common_condition)
        def test_plantuml(self):
            plantuml = self._get_auto_plantuml()
            assert plantuml.plantuml == path

        @mark_select(_common_condition)
        def test_repr(self):
            plantuml = self._get_auto_plantuml()
            assert repr(
                plantuml
            ) == '<LocalPlantuml java: {java}, plantuml: {plantuml}>'.format(
                java=repr(where.first('java')),
                plantuml=repr(path),
            )

        @mark_select(_common_condition)
        def test_check_and_test(self):
            plantuml = self._get_auto_plantuml()
            plantuml.check()
            assert plantuml.test()

        _EXPECTED_TXT_LENGTH_FOR_HELLOWORLD = 224
        _EXPECTED_PNG_LENGTH_FOR_HELLOWORLD_1 = 2211
        _EXPECTED_PNG_LENGTH_FOR_HELLOWORLD_2 = 3020
        _EXPECTED_SVG_LENGTH_FOR_HELLOWORLD = 2771
        _EXPECTED_EPS_LENGTH_FOR_HELLOWORLD = 11926

        @mark_select(_helloworld_condition)
        def test_dump_txt(self):
            plantuml = self._get_auto_plantuml()
            code = Path(DEMO_HELLOWORLD_PUML).read_text()
            txt_result = plantuml.dump_txt(code)

            assert 'Bob' in txt_result
            assert 'Alice' in txt_result
            assert 'hello' in txt_result

            assert self._EXPECTED_TXT_LENGTH_FOR_HELLOWORLD * 0.8 < len(
                txt_result) < self._EXPECTED_TXT_LENGTH_FOR_HELLOWORLD * 1.2

        @mark_select(_helloworld_condition)
        def test_dump_binary_txt(self):
            plantuml = self._get_auto_plantuml()
            code = Path(DEMO_HELLOWORLD_PUML).read_text()

            _data = plantuml.dump_binary('txt', code)
            assert isinstance(_data, bytes)
            assert self._EXPECTED_TXT_LENGTH_FOR_HELLOWORLD * 0.8 < len(
                _data) < self._EXPECTED_TXT_LENGTH_FOR_HELLOWORLD * 1.2

        @mark_select(_helloworld_condition)
        def test_dump_binary_png(self):
            plantuml = self._get_auto_plantuml()
            code = Path(DEMO_HELLOWORLD_PUML).read_text()

            _data = plantuml.dump_binary('png', code)
            assert isinstance(_data, bytes)
            assert (self._EXPECTED_PNG_LENGTH_FOR_HELLOWORLD_1 * 0.8 < len(_data) <
                    self._EXPECTED_PNG_LENGTH_FOR_HELLOWORLD_1 * 1.2) or \
                   (self._EXPECTED_PNG_LENGTH_FOR_HELLOWORLD_2 * 0.8 < len(_data) <
                    self._EXPECTED_PNG_LENGTH_FOR_HELLOWORLD_2 * 1.2)

        @mark_select(_helloworld_condition)
        def test_dump_binary_svg(self):
            plantuml = self._get_auto_plantuml()
            code = Path(DEMO_HELLOWORLD_PUML).read_text()

            _data = plantuml.dump_binary('svg', code)
            assert isinstance(_data, bytes)
            assert self._EXPECTED_SVG_LENGTH_FOR_HELLOWORLD * 0.8 < len(
                _data) < self._EXPECTED_SVG_LENGTH_FOR_HELLOWORLD * 1.2

        @mark_select(_helloworld_condition)
        def test_dump_binary_eps(self):
            plantuml = self._get_auto_plantuml()
            code = Path(DEMO_HELLOWORLD_PUML).read_text()

            _data = plantuml.dump_binary('eps', code)
            assert isinstance(_data, bytes)
            assert self._EXPECTED_EPS_LENGTH_FOR_HELLOWORLD * 0.8 < len(
                _data) < self._EXPECTED_EPS_LENGTH_FOR_HELLOWORLD * 1.2

        @mark_select(_helloworld_condition)
        def test_dump_file_txt(self):
            plantuml = self._get_auto_plantuml()
            code = Path(DEMO_HELLOWORLD_PUML).read_text()

            with NamedTemporaryFile() as file:
                plantuml.dump(file.name, 'txt', code)
                assert os.path.exists(file.name)
                assert self._EXPECTED_TXT_LENGTH_FOR_HELLOWORLD * 0.8 < os.path.getsize(
                    file.name) < self._EXPECTED_TXT_LENGTH_FOR_HELLOWORLD * 1.2

        @mark_select(_helloworld_condition)
        def test_dump_file_png(self):
            plantuml = self._get_auto_plantuml()
            code = Path(DEMO_HELLOWORLD_PUML).read_text()

            with NamedTemporaryFile() as file:
                plantuml.dump(file.name, 'png', code)
                assert os.path.exists(file.name)
                assert (self._EXPECTED_PNG_LENGTH_FOR_HELLOWORLD_1 * 0.8 < os.path.getsize(file.name) <
                        self._EXPECTED_PNG_LENGTH_FOR_HELLOWORLD_1 * 1.2) or \
                       (self._EXPECTED_PNG_LENGTH_FOR_HELLOWORLD_2 * 0.8 < os.path.getsize(file.name) <
                        self._EXPECTED_PNG_LENGTH_FOR_HELLOWORLD_2 * 1.2)

        @mark_select(_helloworld_condition)
        def test_dump_file_svg(self):
            plantuml = self._get_auto_plantuml()
            code = Path(DEMO_HELLOWORLD_PUML).read_text()

            with NamedTemporaryFile() as file:
                plantuml.dump(file.name, 'svg', code)
                assert os.path.exists(file.name)
                assert self._EXPECTED_SVG_LENGTH_FOR_HELLOWORLD * 0.8 < os.path.getsize(
                    file.name) < self._EXPECTED_SVG_LENGTH_FOR_HELLOWORLD * 1.2

        @mark_select(_helloworld_condition)
        def test_dump_file_eps(self):
            plantuml = self._get_auto_plantuml()
            code = Path(DEMO_HELLOWORLD_PUML).read_text()

            with NamedTemporaryFile() as file:
                plantuml.dump(file.name, 'eps', code)
                assert os.path.exists(file.name)
                assert self._EXPECTED_EPS_LENGTH_FOR_HELLOWORLD * 0.8 < os.path.getsize(
                    file.name) < self._EXPECTED_EPS_LENGTH_FOR_HELLOWORLD * 1.2

    return _TestModelsLocal