def test_empty(self):
     try:
         do_work(parser, [])
         self.fail()
         pass
     except SystemExit as e:
         self.assertEqual(e.code, 1)
예제 #2
0
    """)
    return parser


if __name__ == '__main__':
    from scripts.exec_with_limit_module import do_work

    # determine batched mode after parsing
    from scripts.core.base import Printer
    argparser.Parser.on_parse += Printer.setup_printer
    parser = create_parser()

    arg_options = argparser.Parser.parse_exec_with_limit(parser)

    # run work
    returncode = do_work(arg_options)
    returncode = returncode.returncode if type(
        returncode) is not int else returncode

    if arg_options.death:
        if returncode == 0:
            Printer.all.err(
                'Command did exit with 0 but should not (--death flag was set)!'
            )
            sys.exit(1)
        else:
            Printer.all.suc('Command did not with 0 (--death flag was set)')
            sys.exit(0)
    else:
        sys.exit(returncode)
def parse(command, debug=False):
    arg_options = argparser.Parser.parse_exec_with_limit(
        script.create_parser(), command.split())
    return do_work(arg_options, debug)
from utils.argparser import ArgParser
from utils.duration import Duration


parser = ArgParser("exec_with_limit.py [-t <time>] [-m <memory>] -- <executable> <arguments>")
# ----------------------------------------------
parser.add('-t', '--limit-time', type=Duration.parse, name='time_limit', placeholder='<time>', docs=[
    'Obligatory wall clock time limit for execution in seconds or in HH:MM:SS format.',
    'For precision use float value'
])
parser.add('-m', '--limit-memory', type=float, name='memory_limit', placeholder='<memory>', docs=[
    'Optional memory limit per node in MB',
    'For precision use float value'
])
parser.add('', '--batch', type=True, name='batch', docs=[
    'Make output of this script more for an off-line reading',
    'In batch mode, stdout and stderr from executed processes will be printed, not saved'
])
# ----------------------------------------------

if __name__ == '__main__':
    from scripts.exec_with_limit_module import do_work

    # for debug only set dir to where script should be
    Paths.base_dir(__file__)
    # Paths.base_dir('/home/jan-hybs/Dokumenty/Smartgit-flow/flow123d/bin/python')

    # run work
    returncode = do_work(parser)
    sys.exit(returncode)
    def test_limits_over(self):
        pypy = do_work(parser, ['-t', '.5', '-m', '100', '--', consumer, '-m', '200', '-t', '1'])
        self.assertNotEqual(pypy.returncode, 0)

        pypy = do_work(parser, ['-t', '.1', '-m', '100', '--', consumer, '-m', '200', '-t', '1'])
        self.assertNotEqual(pypy.returncode, 0)
 def test_limits_ok(self):
     pypy = do_work(parser, ['-t', '2', '-m', '100', '--', consumer, '-m', '10', '-t', '1'])
     self.assertEqual(pypy.returncode, 0)
    def test_memory_limit_ok(self):
        pypy = do_work(parser, ['-m', '100', '--', consumer, '-m', '10', '-t', '1'])
        self.assertEqual(pypy.returncode, 0)

        pypy = do_work(parser, ['--limit-memory', '100', '--', consumer, '-m', '10', '-t', '1'])
        self.assertEqual(pypy.returncode, 0)
 def test_time_limit_over(self):
     pypy = do_work(parser, ['-t', '0.1', '--', consumer, '-t', '2'])
     self.assertNotEqual(pypy.returncode, 0)
    def test_time_limit_ok(self):
        pypy = do_work(parser, ['-t', '1', '--', 'sleep', '0.01'])
        self.assertEqual(pypy.returncode, 0)

        pypy = do_work(parser, ['--limit-time', '1', '--', 'sleep', '0.01'])
        self.assertEqual(pypy.returncode, 0)
 def test_no_limits(self):
     try:
         do_work(parser, ['--', 'sleep', '0.1'])
         self.fail()
     except SystemExit as e:
         self.assertEqual(e.code, 2)
 def test_help(self):
     try:
         do_work(parser, ['--help'])
         self.fail()
     except SystemExit as e:
         self.assertEqual(e.code, 0)
 def test_memory_limit_over(self):
     returncode = do_work(parser, ['-m', '100', '--', consumer, '-m', '200', '-t', '1'])
     self.assertNotEqual(returncode, 0)