tests: fix test-export-t.py

Summary: The test now completes in 1 second, down from 9 seconds.

Reviewed By: sfilipco

Differential Revision: D17963549

fbshipit-source-id: 5cfae80dd1e4165c015c6fc5a04cec98bc71cbad
This commit is contained in:
Jun Wu 2019-10-17 13:50:14 -07:00 committed by Facebook Github Bot
parent beb5699d39
commit dfd2285def
3 changed files with 38 additions and 38 deletions

View File

@ -1695,7 +1695,7 @@ def export(
mode="wb", mode="wb",
modemap=filemode, modemap=filemode,
) )
dest = fo.name dest = getattr(fo, "name", "<unnamed>")
def write(s, **kw): def write(s, **kw):
fo.write(s) fo.write(s)

View File

@ -9,23 +9,15 @@ from __future__ import absolute_import
from testutil.dott import feature, sh, testtmp # noqa: F401 from testutil.dott import feature, sh, testtmp # noqa: F401
feature.require("false") # test not passing
sh % "hg init repo" sh % "hg init repo"
sh % "cd repo" sh % "cd repo"
sh % "touch foo" sh % "touch foo"
sh % "hg add foo" sh % "hg add foo"
sh % 'for i in 0 1 2 3 4 5 6 7 8 9 10 "11;" do' == r""" for i in range(12):
> echo "foo-$i" >> foo open("foo", "ab").write("foo-%s\n" % i)
> hg ci -m "foo-$i" sh.hg("ci", "-m", "foo-%s" % i)
> done"""
sh % 'for out in %nof%N %%%H %b-%R %h %r "%m;" do' == r""" sh % "hg export -v -o 'foo-%nof%N.patch' 2:tip" == r"""
> echo
> echo "# foo-$out.patch"
> hg export -v -o "foo-$out.patch" 2:tip
> done
# foo-%nof%N.patch
exporting patches: exporting patches:
foo-01of10.patch foo-01of10.patch
foo-02of10.patch foo-02of10.patch
@ -36,9 +28,8 @@ sh % 'for out in %nof%N %%%H %b-%R %h %r "%m;" do' == r"""
foo-07of10.patch foo-07of10.patch
foo-08of10.patch foo-08of10.patch
foo-09of10.patch foo-09of10.patch
foo-10of10.patch foo-10of10.patch"""
sh % "hg export -v -o 'foo-%%%H.patch' 2:tip" == r"""
# foo-%%%H.patch
exporting patches: exporting patches:
foo-%617188a1c80f869a7b66c85134da88a6fb145f67.patch foo-%617188a1c80f869a7b66c85134da88a6fb145f67.patch
foo-%dd41a5ff707a5225204105611ba49cc5c229d55f.patch foo-%dd41a5ff707a5225204105611ba49cc5c229d55f.patch
@ -49,9 +40,8 @@ sh % 'for out in %nof%N %%%H %b-%R %h %r "%m;" do' == r"""
foo-%9688c41894e6931305fa7165a37f6568050b4e9b.patch foo-%9688c41894e6931305fa7165a37f6568050b4e9b.patch
foo-%747d3c68f8ec44bb35816bfcd59aeb50b9654c2f.patch foo-%747d3c68f8ec44bb35816bfcd59aeb50b9654c2f.patch
foo-%5f17a83f5fbd9414006a5e563eab4c8a00729efd.patch foo-%5f17a83f5fbd9414006a5e563eab4c8a00729efd.patch
foo-%f3acbafac161ec68f1598af38f794f28847ca5d3.patch foo-%f3acbafac161ec68f1598af38f794f28847ca5d3.patch"""
sh % "hg export -v -o 'foo-%b-%R.patch' 2:tip" == r"""
# foo-%b-%R.patch
exporting patches: exporting patches:
foo-repo-2.patch foo-repo-2.patch
foo-repo-3.patch foo-repo-3.patch
@ -62,9 +52,8 @@ sh % 'for out in %nof%N %%%H %b-%R %h %r "%m;" do' == r"""
foo-repo-8.patch foo-repo-8.patch
foo-repo-9.patch foo-repo-9.patch
foo-repo-10.patch foo-repo-10.patch
foo-repo-11.patch foo-repo-11.patch"""
sh % "hg export -v -o 'foo-%h.patch' 2:tip" == r"""
# foo-%h.patch
exporting patches: exporting patches:
foo-617188a1c80f.patch foo-617188a1c80f.patch
foo-dd41a5ff707a.patch foo-dd41a5ff707a.patch
@ -75,9 +64,8 @@ sh % 'for out in %nof%N %%%H %b-%R %h %r "%m;" do' == r"""
foo-9688c41894e6.patch foo-9688c41894e6.patch
foo-747d3c68f8ec.patch foo-747d3c68f8ec.patch
foo-5f17a83f5fbd.patch foo-5f17a83f5fbd.patch
foo-f3acbafac161.patch foo-f3acbafac161.patch"""
sh % "hg export -v -o 'foo-%r.patch' 2:tip" == r"""
# foo-%r.patch
exporting patches: exporting patches:
foo-02.patch foo-02.patch
foo-03.patch foo-03.patch
@ -88,9 +76,8 @@ sh % 'for out in %nof%N %%%H %b-%R %h %r "%m;" do' == r"""
foo-08.patch foo-08.patch
foo-09.patch foo-09.patch
foo-10.patch foo-10.patch
foo-11.patch foo-11.patch"""
sh % "hg export -v -o 'foo-%m.patch' 2:tip" == r"""
# foo-%m.patch
exporting patches: exporting patches:
foo-foo_2.patch foo-foo_2.patch
foo-foo_3.patch foo-foo_3.patch
@ -108,21 +95,21 @@ sh % "hg export -v -o foo-%m.patch 2:3" == r"""
exporting patches: exporting patches:
foo-foo_2.patch foo-foo_2.patch
foo-foo_3.patch""" foo-foo_3.patch"""
sh % "grep HG foo-foo_2.patch" | "wc -l" == "\\s*1 (re)" sh % "grep HG foo-foo_2.patch" | "wc -l" == "1"
sh % "grep HG foo-foo_3.patch" | "wc -l" == "\\s*1 (re)" sh % "grep HG foo-foo_3.patch" | "wc -l" == "1"
# Exporting 4 changesets to a file: # Exporting 4 changesets to a file:
sh % "hg export -o export_internal 1 2 3 4" sh % "hg export -o export_internal 1 2 3 4"
sh % "grep HG export_internal" | "wc -l" == "\\s*4 (re)" sh % "grep HG export_internal" | "wc -l" == "4"
# Doing it again clobbers the file rather than appending: # Doing it again clobbers the file rather than appending:
sh % "hg export -o export_internal 1 2 3 4" sh % "hg export -o export_internal 1 2 3 4"
sh % "grep HG export_internal" | "wc -l" == "\\s*4 (re)" sh % "grep HG export_internal" | "wc -l" == "4"
# Exporting 4 changesets to stdout: # Exporting 4 changesets to stdout:
sh % "hg export 1 2 3 4" | "grep HG" | "wc -l" == "\\s*4 (re)" sh % "hg export 1 2 3 4" | "grep HG" | "wc -l" == "4"
# Exporting revision -2 to a file: # Exporting revision -2 to a file:
@ -188,7 +175,7 @@ sh % "hg export -v 1 -o -" == r"""
# Checking if only alphanumeric characters are used in the file name (%m option): # Checking if only alphanumeric characters are used in the file name (%m option):
sh % "echo line" >> "foo" sh % "echo line" >> "foo"
sh % 'hg commit -m " !\\"#$%&(,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_\\`abcdefghijklmnopqrstuvwxyz{|}~"' sh % 'hg commit -m " !\\"#$%&(,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"'
sh % "hg export -v -o %m.patch tip" == r""" sh % "hg export -v -o %m.patch tip" == r"""
exporting patch: exporting patch:
____________0123456789_______ABCDEFGHIJKLMNOPQRSTUVWXYZ______abcdefghijklmnopqrstuvwxyz____.patch""" ____________0123456789_______ABCDEFGHIJKLMNOPQRSTUVWXYZ______abcdefghijklmnopqrstuvwxyz____.patch"""
@ -213,7 +200,7 @@ sh % "hg export" == r"""
foo-11 foo-11
+line""" +line"""
sh % "hg export " == r""" sh % "hg export ''" == r"""
hg: parse error: empty query hg: parse error: empty query
[255]""" [255]"""
sh % "hg export 999" == r""" sh % "hg export 999" == r"""

View File

@ -223,18 +223,31 @@ def true():
return "" return ""
def wc(*args, **kwargs):
stdin = kwargs.get("stdin", "")
linecount = len(stdin.splitlines())
for arg in args:
if arg.startswith("-"):
if arg != "-l":
raise NotImplementedError("wc %s is not implemented" % arg)
else:
linecount += len(open(arg).read().splitlines())
return "%s" % linecount
globals()["["] = test globals()["["] = test
# grep # grep
def grep(pattern, stdin=None): def grep(pattern, *paths, **kwargs):
import re import re
pattern = re.compile(pattern) pattern = re.compile(pattern)
if stdin is None: stdin = kwargs.get("stdin", "")
raise NotImplementedError("this grep implementation requires stdin") for path in paths:
stdin += open(path).read()
return "".join(l for l in stdin.splitlines(True) if pattern.search(l)) return "".join(l for l in stdin.splitlines(True) if pattern.search(l))