neithere / argh

An argparse wrapper that doesn't make you say "argh" each time you deal with it.
http://argh.rtfd.org
GNU Lesser General Public License v3.0
369 stars 56 forks source link

test_unknown_args and test_encoding fail on Windows #74

Closed aldanor closed 10 years ago

aldanor commented 10 years ago

test_unknown_args in test_integration.py seems to fail on Windows for Python 2.7, 3.3 and 3.4 when the tests are run via py.test (Anaconda Python distribution):

______________________________ test_unknown_args ______________________________

    def test_unknown_args():

        def cmd(foo=1):
            return foo

        p = DebugArghParser()
        p.set_default_command(cmd)

        assert run(p, '--foo 1') == R(out='1\n', err='')
        assert run(p, '--bar 1', exit=True) == 'unrecognized arguments: --bar 1'
>       assert run(p, '--bar 1', exit=False,
                   kwargs={'skip_unknown_args': True}) == \
               R(out='usage: py.test [-h] [-f FOO]\n\n', err='')
E       assert CmdResult(out...\n\n', err='') == CmdResult(out=...\n\n', err='')
E         At index 0 diff: 'usage: py.test-script.py [-h] [-f FOO]\n\n' != 'usage: py.test [-h] [-f FOO]\n\n'

test\test_integration.py:773: AssertionError

test_encoding only seems to fail in Python 2:

________________________________ test_encoding ________________________________

    def test_encoding():
        "Unicode is accepted as prompt message"
        raw_input_mock = mock.MagicMock()

        argh.io._input = raw_input_mock

        msg = 'привет'
        if sys.version_info <= (3,0):
            msg = msg.decode('utf-8')

>       argh.confirm(msg)

test\test_interaction.py:67: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
argh\interaction.py:72: in confirm
    choice = safe_input(prompt)
argh\io.py:41: in safe_input
    prompt = prompt.encode(encoding)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <encodings.cp1252.Codec instance at 0x000000000235D6C8>
input = '\u043f\u0440\u0438\u0432\u0435\u0442? (y/n)', errors = 'strict'

    def encode(self,input,errors='strict'):
>       return codecs.charmap_encode(input,errors,encoding_table)
E       UnicodeEncodeError: 'charmap' codec can't encode characters in position 0-5: character maps to <undefined>

..\envs\py27\lib\encodings\cp1252.py:12: UnicodeEncodeError
neithere commented 10 years ago

I'm afraid I don't have any version of Windows anywhere at all, so there's no way I could test Argh on that particular platform. If you wish the problem to be fixed, please submit a patch (or create a pull request). Besides, the only thing I remember about CLI in Windows (about ten years ago) is that it was absolutely insanely horrible, so I'm not sure if supporting the Microsoft stuff is a good idea.

Closing the issue as wontfix until there's a patch.

aldanor commented 10 years ago

Alright, I'll check it out later and see if I can fix it. It's probably just the tests themselves that are faiiling and not the core functionality. Probably has to do with the fact that there are no shebangs on Windows and sys.argv may be getting all messed up (that and stupid encoding issues).