tests/test-status-inprocess.py
author Pulkit Goyal <7895pulkit@gmail.com>
Wed, 02 Dec 2020 13:55:17 +0530
changeset 46083 81c1f5d1801f
parent 45830 c102b704edb5
child 47500 23f5ed6dbcb1
permissions -rwxr-xr-x
procutils: don't try to get `.buffer` if sys.stdin is None While hunting down following test failure of test-chg.t on Python 3, I stumbled the case when `.buffer` is not available as sys.stdin is None. --- /home/pulkit/repo/hg-committed/tests/test-chg.t +++ /home/pulkit/repo/hg-committed/tests/test-chg.t.err @@ -203,7 +203,31 @@ $ CHGDEBUG=1 chg version -q 0<&- chg: debug: * stdio fds are missing (glob) chg: debug: * execute original hg (glob) - Mercurial Distributed SCM * (glob) + Traceback (most recent call last): + File "/tmp/hgtests.avspvsq4/install/bin/hg", line 43, in <module> + dispatch.run() + File "/usr/lib/python3.6/importlib/util.py", line 233, in __getattribute__ + self.__spec__.loader.exec_module(self) + File "<frozen importlib._bootstrap_external>", line 678, in exec_module + File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed + File "/tmp/hgtests.avspvsq4/install/lib/python/mercurial/dispatch.py", line 726, in <module> + class lazyaliasentry(object): + File "/tmp/hgtests.avspvsq4/install/lib/python/mercurial/dispatch.py", line 737, in lazyaliasentry + @util.propertycache + File "/usr/lib/python3.6/importlib/util.py", line 233, in __getattribute__ + self.__spec__.loader.exec_module(self) + File "<frozen importlib._bootstrap_external>", line 678, in exec_module + File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed + File "/tmp/hgtests.avspvsq4/install/lib/python/mercurial/util.py", line 3473, in <module> + f=procutil.stderr, + File "/usr/lib/python3.6/importlib/util.py", line 233, in __getattribute__ + self.__spec__.loader.exec_module(self) + File "<frozen importlib._bootstrap_external>", line 678, in exec_module + File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed + File "/tmp/hgtests.avspvsq4/install/lib/python/mercurial/utils/procutil.py", line 127, in <module> + stdin = sys.stdin.buffer + AttributeError: 'NoneType' object has no attribute 'buffer' + [1] server lifecycle ---------------- Differential Revision: https://phab.mercurial-scm.org/D9500
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
45830
c102b704edb5 global: use python3 in shebangs
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43076
diff changeset
     1
#!/usr/bin/env python3
28766
7f7cd44cd6d5 py3: use print_function in test-status-inprocess.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 28765
diff changeset
     2
from __future__ import absolute_import, print_function
28843
2c7e6f363138 tests: stop direct symbol import of mercurial modules in test-status-inprocess
Yuya Nishihara <yuya@tcha.org>
parents: 28824
diff changeset
     3
37901
bbff7170f665 tests: fix test-status-inprocess.py on Python 3
Augie Fackler <augie@google.com>
parents: 37660
diff changeset
     4
import sys
bbff7170f665 tests: fix test-status-inprocess.py on Python 3
Augie Fackler <augie@google.com>
parents: 37660
diff changeset
     5
28843
2c7e6f363138 tests: stop direct symbol import of mercurial modules in test-status-inprocess
Yuya Nishihara <yuya@tcha.org>
parents: 28824
diff changeset
     6
from mercurial import (
2c7e6f363138 tests: stop direct symbol import of mercurial modules in test-status-inprocess
Yuya Nishihara <yuya@tcha.org>
parents: 28824
diff changeset
     7
    commands,
2c7e6f363138 tests: stop direct symbol import of mercurial modules in test-status-inprocess
Yuya Nishihara <yuya@tcha.org>
parents: 28824
diff changeset
     8
    localrepo,
2c7e6f363138 tests: stop direct symbol import of mercurial modules in test-status-inprocess
Yuya Nishihara <yuya@tcha.org>
parents: 28824
diff changeset
     9
    ui as uimod,
28765
7779f9dfd938 py3: use absolute_import in test-status-inprocess.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 10905
diff changeset
    10
)
10838
07dbafd3a0e2 add a test for the inprocess status dirstate race
Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
parents:
diff changeset
    11
37901
bbff7170f665 tests: fix test-status-inprocess.py on Python 3
Augie Fackler <augie@google.com>
parents: 37660
diff changeset
    12
print_ = print
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39548
diff changeset
    13
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39548
diff changeset
    14
37901
bbff7170f665 tests: fix test-status-inprocess.py on Python 3
Augie Fackler <augie@google.com>
parents: 37660
diff changeset
    15
def print(*args, **kwargs):
bbff7170f665 tests: fix test-status-inprocess.py on Python 3
Augie Fackler <augie@google.com>
parents: 37660
diff changeset
    16
    """print() wrapper that flushes stdout buffers to avoid py3 buffer issues
bbff7170f665 tests: fix test-status-inprocess.py on Python 3
Augie Fackler <augie@google.com>
parents: 37660
diff changeset
    17
bbff7170f665 tests: fix test-status-inprocess.py on Python 3
Augie Fackler <augie@google.com>
parents: 37660
diff changeset
    18
    We could also just write directly to sys.stdout.buffer the way the
bbff7170f665 tests: fix test-status-inprocess.py on Python 3
Augie Fackler <augie@google.com>
parents: 37660
diff changeset
    19
    ui object will, but this was easier for porting the test.
bbff7170f665 tests: fix test-status-inprocess.py on Python 3
Augie Fackler <augie@google.com>
parents: 37660
diff changeset
    20
    """
bbff7170f665 tests: fix test-status-inprocess.py on Python 3
Augie Fackler <augie@google.com>
parents: 37660
diff changeset
    21
    print_(*args, **kwargs)
bbff7170f665 tests: fix test-status-inprocess.py on Python 3
Augie Fackler <augie@google.com>
parents: 37660
diff changeset
    22
    sys.stdout.flush()
bbff7170f665 tests: fix test-status-inprocess.py on Python 3
Augie Fackler <augie@google.com>
parents: 37660
diff changeset
    23
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 39548
diff changeset
    24
30559
d83ca854fa21 ui: factor out ui.load() to create a ui without loading configs (API)
Yuya Nishihara <yuya@tcha.org>
parents: 28843
diff changeset
    25
u = uimod.ui.load()
10838
07dbafd3a0e2 add a test for the inprocess status dirstate race
Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
parents:
diff changeset
    26
28766
7f7cd44cd6d5 py3: use print_function in test-status-inprocess.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 28765
diff changeset
    27
print('% creating repo')
39548
7ce9dea3a14a localrepo: move repo creation logic out of localrepository.__init__ (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37901
diff changeset
    28
repo = localrepo.instance(u, b'.', create=True)
10838
07dbafd3a0e2 add a test for the inprocess status dirstate race
Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
parents:
diff changeset
    29
07dbafd3a0e2 add a test for the inprocess status dirstate race
Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
parents:
diff changeset
    30
f = open('test.py', 'w')
07dbafd3a0e2 add a test for the inprocess status dirstate race
Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
parents:
diff changeset
    31
try:
07dbafd3a0e2 add a test for the inprocess status dirstate race
Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
parents:
diff changeset
    32
    f.write('foo\n')
07dbafd3a0e2 add a test for the inprocess status dirstate race
Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
parents:
diff changeset
    33
finally:
07dbafd3a0e2 add a test for the inprocess status dirstate race
Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
parents:
diff changeset
    34
    f.close
07dbafd3a0e2 add a test for the inprocess status dirstate race
Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
parents:
diff changeset
    35
28766
7f7cd44cd6d5 py3: use print_function in test-status-inprocess.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 28765
diff changeset
    36
print('% add and commit')
37660
9dfa4e9ed45d py3: add b'' prefixes to tests/test-status-inprocess.py
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30559
diff changeset
    37
commands.add(u, repo, b'test.py')
9dfa4e9ed45d py3: add b'' prefixes to tests/test-status-inprocess.py
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30559
diff changeset
    38
commands.commit(u, repo, message=b'*')
28843
2c7e6f363138 tests: stop direct symbol import of mercurial modules in test-status-inprocess
Yuya Nishihara <yuya@tcha.org>
parents: 28824
diff changeset
    39
commands.status(u, repo, clean=True)
10838
07dbafd3a0e2 add a test for the inprocess status dirstate race
Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
parents:
diff changeset
    40
07dbafd3a0e2 add a test for the inprocess status dirstate race
Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
parents:
diff changeset
    41
28766
7f7cd44cd6d5 py3: use print_function in test-status-inprocess.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 28765
diff changeset
    42
print('% change')
10838
07dbafd3a0e2 add a test for the inprocess status dirstate race
Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
parents:
diff changeset
    43
f = open('test.py', 'w')
07dbafd3a0e2 add a test for the inprocess status dirstate race
Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
parents:
diff changeset
    44
try:
07dbafd3a0e2 add a test for the inprocess status dirstate race
Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
parents:
diff changeset
    45
    f.write('bar\n')
07dbafd3a0e2 add a test for the inprocess status dirstate race
Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
parents:
diff changeset
    46
finally:
07dbafd3a0e2 add a test for the inprocess status dirstate race
Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
parents:
diff changeset
    47
    f.close()
07dbafd3a0e2 add a test for the inprocess status dirstate race
Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
parents:
diff changeset
    48
07dbafd3a0e2 add a test for the inprocess status dirstate race
Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
parents:
diff changeset
    49
# this would return clean instead of changed before the fix
28843
2c7e6f363138 tests: stop direct symbol import of mercurial modules in test-status-inprocess
Yuya Nishihara <yuya@tcha.org>
parents: 28824
diff changeset
    50
commands.status(u, repo, clean=True, modified=True)