qutebrowser/qutebrowser

UnicodeEncodeError with os.path.expanduser

Open

#1,337 opened on 2016年3月10日

GitHub で見る
 (3 comments) (0 reactions) (0 assignees)Python (9,161 stars) (1,014 forks)batch import
bug: exceptiongood first issuepriority: 1 - middle

説明

_________________ test_configtypes_hypothesis[UserStyleSheet] __________________

klass = <class 'qutebrowser.config.configtypes.UserStyleSheet'>

    @pytest.mark.parametrize('klass', gen_classes())
>   @hypothesis.given(strategies.text())
    @hypothesis.example('\x00')
    def test_configtypes_hypothesis(klass, s):

tests/unit/config/test_configtypes_hypothesis.py:46: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
.tox/py34/lib/python3.4/site-packages/hypothesis/core.py:540: in wrapped_test
    print_example=True, is_final=True
.tox/py34/lib/python3.4/site-packages/hypothesis/executors.py:57: in default_new_style_executor
    return function(data)
.tox/py34/lib/python3.4/site-packages/hypothesis/core.py:103: in run
    return test(*args, **kwargs)
tests/unit/config/test_configtypes_hypothesis.py:55: in test_configtypes_hypothesis
    klass().validate(s)
qutebrowser/config/configtypes.py:1309: in validate
    value = os.path.expanduser(value)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

path = '~\x80'

    def expanduser(path):
        """Expand ~ and ~user constructions.  If user or $HOME is unknown,
        do nothing."""
        if isinstance(path, bytes):
            tilde = b'~'
        else:
            tilde = '~'
        if not path.startswith(tilde):
            return path
        sep = _get_sep(path)
        i = path.find(sep, 1)
        if i < 0:
            i = len(path)
        if i == 1:
            if 'HOME' not in os.environ:
                import pwd
                userhome = pwd.getpwuid(os.getuid()).pw_dir
            else:
                userhome = os.environ['HOME']
        else:
            import pwd
            name = path[1:i]
            if isinstance(name, bytes):
                name = str(name, 'ASCII')
            try:
>               pwent = pwd.getpwnam(name)
E               UnicodeEncodeError: 'ascii' codec can't encode character '\x80' in position 0: ordinal not in range(128)

.tox/py34/lib/python3.4/posixpath.py:246: UnicodeEncodeError
---------------------------------- Hypothesis ----------------------------------
Falsifying example: test_configtypes_hypothesis(klass=UserStyleSheet, s='~\x80')

When running tests via Docker:

FROM ubuntu:wily
MAINTAINER Florian Bruhin <me@the-compiler.org>

RUN apt-get -y update && \
    apt-get -y dist-upgrade && \
    apt-get -y install python3-pyqt5 python3-pyqt5.qtwebkit python-tox \
                       python3-sip python3-dev xvfb git dbus
RUN dbus-uuidgen --ensure

RUN useradd user && mkdir /home/user && chown -R user /home/user
USER user
WORKDIR /home/user

CMD git clone /outside qutebrowser.git && cd qutebrowser.git && tox -e py34

コントリビューターガイド