sapling/eden/scm/tests/seq.py
Durham Goode 945a516c74 py3: fix tests on Windows
Summary: This fixes various tests on Windows. Many of these fixes were ported from upstream.

Reviewed By: markbt

Differential Revision: D27174617

fbshipit-source-id: b9f36ad0714793f2b76db32c1d840284b744a841
2021-03-29 12:56:48 -07:00

48 lines
1.1 KiB
Python
Executable File

#!/usr/bin/env python
#
# A portable replacement for 'seq'
#
# Usage:
# seq STOP [1, STOP] stepping by 1
# seq START STOP [START, STOP] stepping by 1
# seq START STEP STOP [START, STOP] stepping by STEP
from __future__ import absolute_import, print_function
import os
import sys
# Make print() below output \n line separators, and not \r\n, on Windows. This
# is necessary for test consistency since tests assume \n separators
# everywhere, and otherwise files/commit hashes can change.
#
# (Note: just using `print(sep="\n")` or `sys.stdout.write("%d\n")` is
# insufficient if stdout is in O_TEXT mode.)
if sys.platform == "win32":
import os, msvcrt
msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)
if sys.version_info[0] >= 3:
xrange = range
start = 1
if len(sys.argv) > 2:
start = int(sys.argv[1])
step = 1
if len(sys.argv) > 3:
step = int(sys.argv[2])
stop = int(sys.argv[-1]) + 1
if sys.version_info[0] >= 3:
with os.fdopen(sys.stdout.fileno(), "wb") as stdout:
for i in xrange(start, stop, step):
stdout.write(b"%i\n" % i)
else:
for i in xrange(start, stop, step):
print(i)