tests/ls-l.py
author Sushil khanchi <sushilkhanchi97@gmail.com>
Thu, 27 Aug 2020 12:24:57 +0530
changeset 45406 fa1a5527f642
parent 43076 2372284d9457
child 45830 c102b704edb5
permissions -rwxr-xr-x
tests: add a --retest test to demonstrate a fix in next patch As you see above the added lines, there was only one test failed. So the output should be: "running 1 tests using 1 parallel processes" Next patch will be fixing this. Differential Revision: https://phab.mercurial-scm.org/D8964

#!/usr/bin/env python

# like ls -l, but do not print date, user, or non-common mode bit, to avoid
# using globs in tests.
from __future__ import absolute_import, print_function

import os
import stat
import sys


def modestr(st):
    mode = st.st_mode
    result = ''
    if mode & stat.S_IFDIR:
        result += 'd'
    else:
        result += '-'
    for owner in ['USR', 'GRP', 'OTH']:
        for action in ['R', 'W', 'X']:
            if mode & getattr(stat, 'S_I%s%s' % (action, owner)):
                result += action.lower()
            else:
                result += '-'
    return result


def sizestr(st):
    if st.st_mode & stat.S_IFREG:
        return '%7d' % st.st_size
    else:
        # do not show size for non regular files
        return ' ' * 7


os.chdir((sys.argv[1:] + ['.'])[0])

for name in sorted(os.listdir('.')):
    st = os.stat(name)
    print('%s %s %s' % (modestr(st), sizestr(st), name))