CoolFace
Apppublic

Aluode/PerceptionLabPortable

sourceHugging Faceupdated 9mo agoView on Hugging Face
0likes
test_cmd.py108 linesDownload Raw Back to tests
1"""Tests for distutils.cmd."""2 3import os4from distutils import debug5from distutils.cmd import Command6from distutils.dist import Distribution7from distutils.errors import DistutilsOptionError8 9import pytest10 11 12class MyCmd(Command):13    def initialize_options(self):14        pass15 16 17@pytest.fixture18def cmd(request):19    return MyCmd(Distribution())20 21 22class TestCommand:23    def test_ensure_string_list(self, cmd):24        cmd.not_string_list = ['one', 2, 'three']25        cmd.yes_string_list = ['one', 'two', 'three']26        cmd.not_string_list2 = object()27        cmd.yes_string_list2 = 'ok'28        cmd.ensure_string_list('yes_string_list')29        cmd.ensure_string_list('yes_string_list2')30 31        with pytest.raises(DistutilsOptionError):32            cmd.ensure_string_list('not_string_list')33 34        with pytest.raises(DistutilsOptionError):35            cmd.ensure_string_list('not_string_list2')36 37        cmd.option1 = 'ok,dok'38        cmd.ensure_string_list('option1')39        assert cmd.option1 == ['ok', 'dok']40 41        cmd.option2 = ['xxx', 'www']42        cmd.ensure_string_list('option2')43 44        cmd.option3 = ['ok', 2]45        with pytest.raises(DistutilsOptionError):46            cmd.ensure_string_list('option3')47 48    def test_make_file(self, cmd):49        # making sure it raises when infiles is not a string or a list/tuple50        with pytest.raises(TypeError):51            cmd.make_file(infiles=True, outfile='', func='func', args=())52 53        # making sure execute gets called properly54        def _execute(func, args, exec_msg, level):55            assert exec_msg == 'generating out from in'56 57        cmd.force = True58        cmd.execute = _execute59        cmd.make_file(infiles='in', outfile='out', func='func', args=())60 61    def test_dump_options(self, cmd):62        msgs = []63 64        def _announce(msg, level):65            msgs.append(msg)66 67        cmd.announce = _announce68        cmd.option1 = 169        cmd.option2 = 170        cmd.user_options = [('option1', '', ''), ('option2', '', '')]71        cmd.dump_options()72 73        wanted = ["command options for 'MyCmd':", '  option1 = 1', '  option2 = 1']74        assert msgs == wanted75 76    def test_ensure_string(self, cmd):77        cmd.option1 = 'ok'78        cmd.ensure_string('option1')79 80        cmd.option2 = None81        cmd.ensure_string('option2', 'xxx')82        assert hasattr(cmd, 'option2')83 84        cmd.option3 = 185        with pytest.raises(DistutilsOptionError):86            cmd.ensure_string('option3')87 88    def test_ensure_filename(self, cmd):89        cmd.option1 = __file__90        cmd.ensure_filename('option1')91        cmd.option2 = 'xxx'92        with pytest.raises(DistutilsOptionError):93            cmd.ensure_filename('option2')94 95    def test_ensure_dirname(self, cmd):96        cmd.option1 = os.path.dirname(__file__) or os.curdir97        cmd.ensure_dirname('option1')98        cmd.option2 = 'xxx'99        with pytest.raises(DistutilsOptionError):100            cmd.ensure_dirname('option2')101 102    def test_debug_print(self, cmd, capsys, monkeypatch):103        cmd.debug_print('xxx')104        assert capsys.readouterr().out == ''105        monkeypatch.setattr(debug, 'DEBUG', True)106        cmd.debug_print('xxx')107        assert capsys.readouterr().out == 'xxx\n'108 
Aluode/PerceptionLabPortable · CoolFace