tests/test-duplicateoptions.py
author Simon Sapin <simon.sapin@octobus.net>
Fri, 21 Jan 2022 17:54:03 +0100
changeset 48745 94e36b230990
parent 43076 2372284d9457
child 48875 6000f5b25c9b
permissions -rw-r--r--
status: prefer relative paths in Rust code … when the repository root is under the current directory, so the kernel needs to traverse fewer directory in every call to `read_dir` or `symlink_metadata`. Better yet would be to use libc functions like `openat` and `fstatat` to remove such repeated traversals entirely, but the standard library does not provide APIs based on those. Maybe with a crate like https://crates.io/crates/openat instead? Benchmarks of `rhg status` show that this patch is neutral in some configurations, and makes the command up to ~20% faster in others. Below is semi-arbitrary subset of results. The four numeric columns are: time (in seconds) with this changeset’s parent, time with this changeset, time difference (negative is better), time ratio (less than 1 is better). ``` mercurial-dirstate-v1 | default-plain-clean.no-iu.pbr | 0.0061 -> 0.0059: -0.0002 (0.97) mercurial-dirstate-v2 | default-plain-clean.no-iu.pbr | 0.0029 -> 0.0028: -0.0001 (0.97) mozilla-dirstate-v1 | default-plain-clean.no-iu.pbr | 0.2110 -> 0.2102: -0.0007 (1.00) mozilla-dirstate-v2 | default-copies-clean.ignored.pbr | 0.0489 -> 0.0401: -0.0088 (0.82) mozilla-dirstate-v2 | default-copies-clean.no-iu.pbr | 0.0479 -> 0.0393: -0.0085 (0.82) mozilla-dirstate-v2 | default-copies-large.all.pbr | 0.1262 -> 0.1210: -0.0051 (0.96) mozilla-dirstate-v2 | default-copies-small.ignored-unknown.pbr | 0.1262 -> 0.1200: -0.0062 (0.95) mozilla-dirstate-v2 | default-copies-small.ignored.pbr | 0.0536 -> 0.0417: -0.0119 (0.78) mozilla-dirstate-v2 | default-copies-small.no-iu.pbr | 0.0482 -> 0.0393: -0.0089 (0.81) mozilla-dirstate-v2 | default-plain-clean.ignored.pbr | 0.0518 -> 0.0402: -0.0116 (0.78) mozilla-dirstate-v2 | default-plain-clean.no-iu.pbr | 0.0481 -> 0.0392: -0.0088 (0.82) mozilla-dirstate-v2 | default-plain-large.all.pbr | 0.1271 -> 0.1218: -0.0052 (0.96) mozilla-dirstate-v2 | default-plain-small.ignored-unknown.pbr | 0.1225 -> 0.1202: -0.0022 (0.98) mozilla-dirstate-v2 | default-plain-small.ignored.pbr | 0.0510 -> 0.0418: -0.0092 (0.82) mozilla-dirstate-v2 | default-plain-small.no-iu.pbr | 0.0480 -> 0.0394: -0.0086 (0.82) netbeans-dirstate-v1 | default-plain-clean.no-iu.pbr | 0.1442 -> 0.1422: -0.0020 (0.99) netbeans-dirstate-v2 | default-plain-clean.no-iu.pbr | 0.0325 -> 0.0282: -0.0043 (0.87) ``` Differential Revision: https://phab.mercurial-scm.org/D12175
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
28740
e8ecd1aa3f6c py3: use print_function in test-duplicateoptions.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 28739
diff changeset
     1
from __future__ import absolute_import, print_function
14449
7d171c05a631 tests: add a test to check for duplicate command options
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
     2
import os
28739
d289b8847f23 py3: use absolute_import in test-duplicateoptions.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 20622
diff changeset
     3
from mercurial import (
d289b8847f23 py3: use absolute_import in test-duplicateoptions.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 20622
diff changeset
     4
    commands,
d289b8847f23 py3: use absolute_import in test-duplicateoptions.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 20622
diff changeset
     5
    extensions,
28804
ce49c8d4f0bb test-duplicateoptions: alias ui as uimod
Yuya Nishihara <yuya@tcha.org>
parents: 28740
diff changeset
     6
    ui as uimod,
28739
d289b8847f23 py3: use absolute_import in test-duplicateoptions.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 20622
diff changeset
     7
)
14449
7d171c05a631 tests: add a test to check for duplicate command options
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
     8
38340
9abe91a503da graph: improve graph output by using Unicode characters
John Stiles <johnstiles@gmail.com>
parents: 33723
diff changeset
     9
ignore = {b'highlight', b'win32text', b'factotum', b'beautifygraph'}
14449
7d171c05a631 tests: add a test to check for duplicate command options
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    10
40363
c3ad9ef0876c tests: don't emit false failures when sqlite3 is missing
Augie Fackler <augie@google.com>
parents: 38340
diff changeset
    11
try:
c3ad9ef0876c tests: don't emit false failures when sqlite3 is missing
Augie Fackler <augie@google.com>
parents: 38340
diff changeset
    12
    import sqlite3
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
    13
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
    14
    del sqlite3  # unused, just checking that import works
40363
c3ad9ef0876c tests: don't emit false failures when sqlite3 is missing
Augie Fackler <augie@google.com>
parents: 38340
diff changeset
    15
except ImportError:
c3ad9ef0876c tests: don't emit false failures when sqlite3 is missing
Augie Fackler <augie@google.com>
parents: 38340
diff changeset
    16
    ignore.add(b'sqlitestore')
c3ad9ef0876c tests: don't emit false failures when sqlite3 is missing
Augie Fackler <augie@google.com>
parents: 38340
diff changeset
    17
14449
7d171c05a631 tests: add a test to check for duplicate command options
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    18
if os.name != 'nt':
33723
5b2f331d0a33 tests: update duplicateoptions test to use bytestrings everywhere
Augie Fackler <augie@google.com>
parents: 32291
diff changeset
    19
    ignore.add(b'win32mbcs')
14449
7d171c05a631 tests: add a test to check for duplicate command options
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    20
7d171c05a631 tests: add a test to check for duplicate command options
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    21
disabled = [ext for ext in extensions.disabled().keys() if ext not in ignore]
7d171c05a631 tests: add a test to check for duplicate command options
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    22
33723
5b2f331d0a33 tests: update duplicateoptions test to use bytestrings everywhere
Augie Fackler <augie@google.com>
parents: 32291
diff changeset
    23
hgrc = open(os.environ["HGRCPATH"], 'wb')
5b2f331d0a33 tests: update duplicateoptions test to use bytestrings everywhere
Augie Fackler <augie@google.com>
parents: 32291
diff changeset
    24
hgrc.write(b'[extensions]\n')
14449
7d171c05a631 tests: add a test to check for duplicate command options
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    25
7d171c05a631 tests: add a test to check for duplicate command options
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    26
for ext in disabled:
33723
5b2f331d0a33 tests: update duplicateoptions test to use bytestrings everywhere
Augie Fackler <augie@google.com>
parents: 32291
diff changeset
    27
    hgrc.write(ext + b'=\n')
14449
7d171c05a631 tests: add a test to check for duplicate command options
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    28
7d171c05a631 tests: add a test to check for duplicate command options
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    29
hgrc.close()
7d171c05a631 tests: add a test to check for duplicate command options
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    30
30559
d83ca854fa21 ui: factor out ui.load() to create a ui without loading configs (API)
Yuya Nishihara <yuya@tcha.org>
parents: 28804
diff changeset
    31
u = uimod.ui.load()
14449
7d171c05a631 tests: add a test to check for duplicate command options
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    32
extensions.loadall(u)
40729
c93d046d4300 extensions: add "uipopulate" hook, called per instance, not per process
Yuya Nishihara <yuya@tcha.org>
parents: 40376
diff changeset
    33
extensions.populateui(u)
14449
7d171c05a631 tests: add a test to check for duplicate command options
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    34
15099
b1f49efeab65 test: test for options duplicate with global options
Simon Heimberg <simohe@besonet.ch>
parents: 14762
diff changeset
    35
globalshort = set()
b1f49efeab65 test: test for options duplicate with global options
Simon Heimberg <simohe@besonet.ch>
parents: 14762
diff changeset
    36
globallong = set()
b1f49efeab65 test: test for options duplicate with global options
Simon Heimberg <simohe@besonet.ch>
parents: 14762
diff changeset
    37
for option in commands.globalopts:
b1f49efeab65 test: test for options duplicate with global options
Simon Heimberg <simohe@besonet.ch>
parents: 14762
diff changeset
    38
    option[0] and globalshort.add(option[0])
b1f49efeab65 test: test for options duplicate with global options
Simon Heimberg <simohe@besonet.ch>
parents: 14762
diff changeset
    39
    option[1] and globallong.add(option[1])
b1f49efeab65 test: test for options duplicate with global options
Simon Heimberg <simohe@besonet.ch>
parents: 14762
diff changeset
    40
33723
5b2f331d0a33 tests: update duplicateoptions test to use bytestrings everywhere
Augie Fackler <augie@google.com>
parents: 32291
diff changeset
    41
for cmd, entry in commands.table.items():
15099
b1f49efeab65 test: test for options duplicate with global options
Simon Heimberg <simohe@besonet.ch>
parents: 14762
diff changeset
    42
    seenshort = globalshort.copy()
b1f49efeab65 test: test for options duplicate with global options
Simon Heimberg <simohe@besonet.ch>
parents: 14762
diff changeset
    43
    seenlong = globallong.copy()
14449
7d171c05a631 tests: add a test to check for duplicate command options
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    44
    for option in entry[1]:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
    45
        if (option[0] and option[0] in seenshort) or (
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
    46
            option[1] and option[1] in seenlong
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41759
diff changeset
    47
        ):
28740
e8ecd1aa3f6c py3: use print_function in test-duplicateoptions.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 28739
diff changeset
    48
            print("command '" + cmd + "' has duplicate option " + str(option))
14449
7d171c05a631 tests: add a test to check for duplicate command options
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    49
        seenshort.add(option[0])
7d171c05a631 tests: add a test to check for duplicate command options
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    50
        seenlong.add(option[1])