tests/test-bugzilla.t
author Manuel Jacob <me@manueljacob.de>
Mon, 11 Jul 2022 01:51:20 +0200
branchstable
changeset 49378 094a5fa3cf52
parent 48876 42d2b31cee0b
permissions -rw-r--r--
procutil: make stream detection in make_line_buffered more correct and strict In make_line_buffered(), we don’t want to wrap the stream if we know that lines get flushed to the underlying raw stream already. Previously, the heuristic was too optimistic. It assumed that any stream which is not an instance of io.BufferedIOBase doesn’t need wrapping. However, there are buffered streams that aren’t instances of io.BufferedIOBase, like Mercurial’s own winstdout. The new logic is different in two ways: First, only for the check, if unwraps any combination of WriteAllWrapper and winstdout. Second, it skips wrapping the stream only if it is an instance of io.RawIOBase (or already wrapped). If it is an instance of io.BufferedIOBase, it gets wrapped. In any other case, the function raises an exception. This ensures that, if an unknown stream is passed or we add another wrapper in the future, we don’t wrap the stream if it’s already line buffered or not wrap the stream if it’s not line buffered. In fact, this was already helpful during development of this change. Without it, I possibly would have forgot that WriteAllWrapper needs to be ignored for the check, leading to unnecessary wrapping if stdout is unbuffered. The alternative would have been to always wrap unknown streams. However, I don’t think that anyone would benefit from being less strict. We can expect streams from the standard library to be subclassing either io.RawIOBase or io.BufferedIOBase, so running Mercurial in the standard way should not regress by this change. Py2exe might replace sys.stdout and sys.stderr, but that currently breaks Mercurial anyway and also these streams don’t claim to be interactive, so this function is not called for them.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
28950
9e1c9f016b72 bugzilla: do not load style file if template is specified (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
     1
mock bugzilla driver for testing template output:
9e1c9f016b72 bugzilla: do not load style file if template is specified (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
     2
9e1c9f016b72 bugzilla: do not load style file if template is specified (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
     3
  $ cat <<EOF > bzmock.py
9e1c9f016b72 bugzilla: do not load style file if template is specified (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
     4
  > from mercurial import extensions
41343
7370f302be71 py3: port test-bugzilla.t to Python 3
Augie Fackler <augie@google.com>
parents: 38070
diff changeset
     5
  > from mercurial import pycompat
33432
fbfecd1dbfb5 configitems: register the 'bugzilla.mocklog' config
Boris Feld <boris.feld@octobus.net>
parents: 29102
diff changeset
     6
  > from mercurial import registrar
41343
7370f302be71 py3: port test-bugzilla.t to Python 3
Augie Fackler <augie@google.com>
parents: 38070
diff changeset
     7
  > from mercurial.utils import stringutil
28950
9e1c9f016b72 bugzilla: do not load style file if template is specified (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
     8
  > 
33432
fbfecd1dbfb5 configitems: register the 'bugzilla.mocklog' config
Boris Feld <boris.feld@octobus.net>
parents: 29102
diff changeset
     9
  > configtable = {}
fbfecd1dbfb5 configitems: register the 'bugzilla.mocklog' config
Boris Feld <boris.feld@octobus.net>
parents: 29102
diff changeset
    10
  > configitem = registrar.configitem(configtable)
fbfecd1dbfb5 configitems: register the 'bugzilla.mocklog' config
Boris Feld <boris.feld@octobus.net>
parents: 29102
diff changeset
    11
  > 
38070
fc3cca406b2e py3: add b'' prefixes in tests/test-bugzilla.t
Pulkit Goyal <7895pulkit@gmail.com>
parents: 35393
diff changeset
    12
  > configitem(b'bugzilla', b'mocklog',
33432
fbfecd1dbfb5 configitems: register the 'bugzilla.mocklog' config
Boris Feld <boris.feld@octobus.net>
parents: 29102
diff changeset
    13
  >     default=None,
fbfecd1dbfb5 configitems: register the 'bugzilla.mocklog' config
Boris Feld <boris.feld@octobus.net>
parents: 29102
diff changeset
    14
  > )
28950
9e1c9f016b72 bugzilla: do not load style file if template is specified (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    15
  > def extsetup(ui):
38070
fc3cca406b2e py3: add b'' prefixes in tests/test-bugzilla.t
Pulkit Goyal <7895pulkit@gmail.com>
parents: 35393
diff changeset
    16
  >     bugzilla = extensions.find(b'bugzilla')
28950
9e1c9f016b72 bugzilla: do not load style file if template is specified (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    17
  >     class bzmock(bugzilla.bzaccess):
9e1c9f016b72 bugzilla: do not load style file if template is specified (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    18
  >         def __init__(self, ui):
9e1c9f016b72 bugzilla: do not load style file if template is specified (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    19
  >             super(bzmock, self).__init__(ui)
38070
fc3cca406b2e py3: add b'' prefixes in tests/test-bugzilla.t
Pulkit Goyal <7895pulkit@gmail.com>
parents: 35393
diff changeset
    20
  >             self._logfile = ui.config(b'bugzilla', b'mocklog')
28950
9e1c9f016b72 bugzilla: do not load style file if template is specified (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    21
  >         def updatebug(self, bugid, newstate, text, committer):
41343
7370f302be71 py3: port test-bugzilla.t to Python 3
Augie Fackler <augie@google.com>
parents: 38070
diff changeset
    22
  >             with open(pycompat.fsdecode(self._logfile), 'ab') as f:
7370f302be71 py3: port test-bugzilla.t to Python 3
Augie Fackler <augie@google.com>
parents: 38070
diff changeset
    23
  >                 f.write(b'update bugid=%s, newstate=%s, committer=%s\n'
7370f302be71 py3: port test-bugzilla.t to Python 3
Augie Fackler <augie@google.com>
parents: 38070
diff changeset
    24
  >                         % (stringutil.pprint(bugid),
7370f302be71 py3: port test-bugzilla.t to Python 3
Augie Fackler <augie@google.com>
parents: 38070
diff changeset
    25
  >                            stringutil.pprint(newstate),
7370f302be71 py3: port test-bugzilla.t to Python 3
Augie Fackler <augie@google.com>
parents: 38070
diff changeset
    26
  >                            stringutil.pprint(committer)))
7370f302be71 py3: port test-bugzilla.t to Python 3
Augie Fackler <augie@google.com>
parents: 38070
diff changeset
    27
  >                 f.write(b'----\n' + text + b'\n----\n')
28950
9e1c9f016b72 bugzilla: do not load style file if template is specified (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    28
  >         def notify(self, bugs, committer):
41343
7370f302be71 py3: port test-bugzilla.t to Python 3
Augie Fackler <augie@google.com>
parents: 38070
diff changeset
    29
  >             with open(pycompat.fsdecode(self._logfile), 'ab') as f:
7370f302be71 py3: port test-bugzilla.t to Python 3
Augie Fackler <augie@google.com>
parents: 38070
diff changeset
    30
  >                 f.write(b'notify bugs=%s, committer=%s\n'
7370f302be71 py3: port test-bugzilla.t to Python 3
Augie Fackler <augie@google.com>
parents: 38070
diff changeset
    31
  >                         % (stringutil.pprint(bugs),
7370f302be71 py3: port test-bugzilla.t to Python 3
Augie Fackler <augie@google.com>
parents: 38070
diff changeset
    32
  >                            stringutil.pprint(committer)))
38070
fc3cca406b2e py3: add b'' prefixes in tests/test-bugzilla.t
Pulkit Goyal <7895pulkit@gmail.com>
parents: 35393
diff changeset
    33
  >     bugzilla.bugzilla._versions[b'mock'] = bzmock
28950
9e1c9f016b72 bugzilla: do not load style file if template is specified (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    34
  > EOF
9e1c9f016b72 bugzilla: do not load style file if template is specified (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    35
9e1c9f016b72 bugzilla: do not load style file if template is specified (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    36
set up mock repository:
9e1c9f016b72 bugzilla: do not load style file if template is specified (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    37
9e1c9f016b72 bugzilla: do not load style file if template is specified (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    38
  $ hg init mockremote
9e1c9f016b72 bugzilla: do not load style file if template is specified (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    39
  $ cat <<EOF > mockremote/.hg/hgrc
9e1c9f016b72 bugzilla: do not load style file if template is specified (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    40
  > [extensions]
9e1c9f016b72 bugzilla: do not load style file if template is specified (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    41
  > bugzilla =
9e1c9f016b72 bugzilla: do not load style file if template is specified (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    42
  > bzmock = $TESTTMP/bzmock.py
9e1c9f016b72 bugzilla: do not load style file if template is specified (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    43
  > 
9e1c9f016b72 bugzilla: do not load style file if template is specified (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    44
  > [bugzilla]
9e1c9f016b72 bugzilla: do not load style file if template is specified (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    45
  > version = mock
9e1c9f016b72 bugzilla: do not load style file if template is specified (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    46
  > mocklog = $TESTTMP/bzmock.log
9e1c9f016b72 bugzilla: do not load style file if template is specified (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    47
  > 
9e1c9f016b72 bugzilla: do not load style file if template is specified (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    48
  > [hooks]
9e1c9f016b72 bugzilla: do not load style file if template is specified (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    49
  > incoming.bugzilla = python:hgext.bugzilla.hook
9e1c9f016b72 bugzilla: do not load style file if template is specified (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    50
  > 
9e1c9f016b72 bugzilla: do not load style file if template is specified (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    51
  > [web]
9e1c9f016b72 bugzilla: do not load style file if template is specified (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    52
  > baseurl=http://example.org/hg
9e1c9f016b72 bugzilla: do not load style file if template is specified (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    53
  > 
9e1c9f016b72 bugzilla: do not load style file if template is specified (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    54
  > %include $TESTTMP/bzstyle.hgrc
9e1c9f016b72 bugzilla: do not load style file if template is specified (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    55
  > EOF
9e1c9f016b72 bugzilla: do not load style file if template is specified (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    56
9e1c9f016b72 bugzilla: do not load style file if template is specified (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    57
  $ hg clone -q mockremote mocklocal
9e1c9f016b72 bugzilla: do not load style file if template is specified (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    58
9e1c9f016b72 bugzilla: do not load style file if template is specified (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    59
push with default template:
9e1c9f016b72 bugzilla: do not load style file if template is specified (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    60
9e1c9f016b72 bugzilla: do not load style file if template is specified (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    61
  $ echo '[bugzilla]' > bzstyle.hgrc
9e1c9f016b72 bugzilla: do not load style file if template is specified (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    62
  $ echo foo > mocklocal/foo
9e1c9f016b72 bugzilla: do not load style file if template is specified (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    63
  $ hg ci -R mocklocal -Aqm 'Fixes bug 123'
9e1c9f016b72 bugzilla: do not load style file if template is specified (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    64
  $ hg -R mocklocal push -q
9e1c9f016b72 bugzilla: do not load style file if template is specified (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    65
  $ cat bzmock.log && rm bzmock.log
9e1c9f016b72 bugzilla: do not load style file if template is specified (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    66
  update bugid=123, newstate={}, committer='test'
9e1c9f016b72 bugzilla: do not load style file if template is specified (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    67
  ----
35393
4441705b7111 tests: remove (glob) annotations that were only for '\' matches
Matt Harbison <matt_harbison@yahoo.com>
parents: 33432
diff changeset
    68
  changeset 7875a8342c6f in repo $TESTTMP/mockremote refers to bug 123.
28950
9e1c9f016b72 bugzilla: do not load style file if template is specified (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    69
  details:
9e1c9f016b72 bugzilla: do not load style file if template is specified (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    70
  	Fixes bug 123
9e1c9f016b72 bugzilla: do not load style file if template is specified (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    71
  ----
9e1c9f016b72 bugzilla: do not load style file if template is specified (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    72
  notify bugs={123: {}}, committer='test'
9e1c9f016b72 bugzilla: do not load style file if template is specified (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    73
9e1c9f016b72 bugzilla: do not load style file if template is specified (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    74
push with style:
9e1c9f016b72 bugzilla: do not load style file if template is specified (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    75
9e1c9f016b72 bugzilla: do not load style file if template is specified (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    76
  $ cat <<EOF > bzstyle.map
9e1c9f016b72 bugzilla: do not load style file if template is specified (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    77
  > changeset = "{node|short} refers to bug {bug}."
9e1c9f016b72 bugzilla: do not load style file if template is specified (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    78
  > EOF
9e1c9f016b72 bugzilla: do not load style file if template is specified (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    79
  $ echo "style = $TESTTMP/bzstyle.map" >> bzstyle.hgrc
9e1c9f016b72 bugzilla: do not load style file if template is specified (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    80
  $ echo foo >> mocklocal/foo
9e1c9f016b72 bugzilla: do not load style file if template is specified (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    81
  $ hg ci -R mocklocal -qm 'Fixes bug 456'
9e1c9f016b72 bugzilla: do not load style file if template is specified (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    82
  $ hg -R mocklocal push -q
9e1c9f016b72 bugzilla: do not load style file if template is specified (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    83
  $ cat bzmock.log && rm bzmock.log
9e1c9f016b72 bugzilla: do not load style file if template is specified (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    84
  update bugid=456, newstate={}, committer='test'
9e1c9f016b72 bugzilla: do not load style file if template is specified (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    85
  ----
9e1c9f016b72 bugzilla: do not load style file if template is specified (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    86
  2808b172464b refers to bug 456.
9e1c9f016b72 bugzilla: do not load style file if template is specified (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    87
  ----
9e1c9f016b72 bugzilla: do not load style file if template is specified (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    88
  notify bugs={456: {}}, committer='test'
9e1c9f016b72 bugzilla: do not load style file if template is specified (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    89
9e1c9f016b72 bugzilla: do not load style file if template is specified (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    90
push with template (overrides style):
9e1c9f016b72 bugzilla: do not load style file if template is specified (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    91
9e1c9f016b72 bugzilla: do not load style file if template is specified (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    92
  $ cat <<EOF >> bzstyle.hgrc
9e1c9f016b72 bugzilla: do not load style file if template is specified (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    93
  > template = Changeset {node|short} in {root|basename}.
9e1c9f016b72 bugzilla: do not load style file if template is specified (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    94
  >            {hgweb}/rev/{node|short}\n
9e1c9f016b72 bugzilla: do not load style file if template is specified (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    95
  >            {desc}
9e1c9f016b72 bugzilla: do not load style file if template is specified (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    96
  > EOF
9e1c9f016b72 bugzilla: do not load style file if template is specified (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    97
  $ echo foo >> mocklocal/foo
9e1c9f016b72 bugzilla: do not load style file if template is specified (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    98
  $ hg ci -R mocklocal -qm 'Fixes bug 789'
9e1c9f016b72 bugzilla: do not load style file if template is specified (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
    99
  $ hg -R mocklocal push -q
9e1c9f016b72 bugzilla: do not load style file if template is specified (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
   100
  $ cat bzmock.log && rm bzmock.log
9e1c9f016b72 bugzilla: do not load style file if template is specified (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
   101
  update bugid=789, newstate={}, committer='test'
9e1c9f016b72 bugzilla: do not load style file if template is specified (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
   102
  ----
9e1c9f016b72 bugzilla: do not load style file if template is specified (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
   103
  Changeset a770f3e409f2 in mockremote.
9e1c9f016b72 bugzilla: do not load style file if template is specified (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
   104
  http://example.org/hg/rev/a770f3e409f2
9e1c9f016b72 bugzilla: do not load style file if template is specified (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
   105
  
9e1c9f016b72 bugzilla: do not load style file if template is specified (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
   106
  Fixes bug 789
9e1c9f016b72 bugzilla: do not load style file if template is specified (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
   107
  ----
9e1c9f016b72 bugzilla: do not load style file if template is specified (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
   108
  notify bugs={789: {}}, committer='test'