Example #1
0
def main(input_path, output_path):
    count = 0
    total_exps = count_number_files(input_path)
    total_time = time()
    print('Total experiments to run: ' + str(total_exps))
    pathlist = Path(input_path).glob('**/*.json')
    error = None
    for path in pathlist:
        config_path = str(path)
        filename = os.path.basename(os.path.normpath(config_path))
        if config_path.endswith(".json"):
            print('Running exp: ' + filename)
            t = time()
            results_path = output_path + '/' + filename.replace('.json', '')
            os.mkdir(results_path)
            f = open(results_path + '/log.txt', 'w')
            aux = sys.stdout
            sys.stdout = f
            try:
                run(config_path, results_path, False, True)
            except Exception as e:
                error = e
                print('ERROR', error)
                print(traceback.format_exc())
            finally:
                f.close()
                sys.stdout = aux
                count += 1
                if error:
                    print('ERROR', error)
                    error = None
                else:
                    print('Finished exp in ' + str(time() - t) +
                          '. Remaining exps: ' + str(total_exps - count))
    print('Finished exps. Total time: ' + str(time() - total_time))
Example #2
0
 def test_file_not_found(self):
     sys.argv[1:] = ['gg.xml']
     with self.assertRaises(SystemExit) as exc:
         with self.assertLogs(main.logger, level='DEBUG') as cm:
             main.run()
     self.assertEqual(exc.exception.args[0], 1)
     self.assertEqual(cm.output[0], 'ERROR:src.main:file gg.xml not found')
Example #3
0
    def test_no_file(self):
        sys.argv[1:] = []
        with self.assertRaises(SystemExit):
            with patch('sys.stderr', new=StringIO()) as mocked_stderr:
                main.run()

        expected = (
            "usage: python -m unittest [-h] [--start START] "
            "[--end END] [--users USERS] [--output {json,console}] file\n"
            "python -m unittest: error: the following arguments are "
            "required: file\n")
        self.assertEqual(mocked_stderr.getvalue(), expected)
Example #4
0
    def test_success(self):

        sys.argv[1:] = [self.file.name]
        with patch('sys.stdout', new=StringIO()) as mocked_stdout:
            main.run()
        expected = """---
user
date        duration
2007-12-12  1 h, 0 m, 0 s
---
"""
        self.assertEqual(expected, mocked_stdout.getvalue())
Example #5
0
def run_optimized():
    if __debug__:
        # start subprocess
        subp_args = [str(sys.executable), "-O", str(__file__)]
        for arg in sys.argv[1:]:
            subp_args.append(arg)
        #subprocess.Popen(subp_args)
        subprocess.call(subp_args)
    else:
        # running optimized
        # import the game
        from src.main import run
        run()
Example #6
0
def run_debug():
    # running in debug mode
    if u"-profile" in sys.argv:
        import cProfile
        import tempfile
        import os
 
        try:
            cProfile.run('run()', 'profile.txt')
        finally:
            pass
    else:
        run()
Example #7
0
def run_optimized():
    if __debug__:
        # start subprocess
        subp_args = [str(sys.executable), "-O", str(__file__)]
        for arg in sys.argv[1:]:
            subp_args.append(arg)
        #subprocess.Popen(subp_args)
        subprocess.call(subp_args)
    else:
        # running optimized
        # import the game
        from src.main import run
        run()
Example #8
0
 def test_invalid_syntax(self):
     file = open('dd.xml', 'wt')
     file.write('qwd')
     file.close()
     sys.argv[1:] = [file.name]
     with self.assertRaises(SystemExit) as exc:
         with self.assertLogs(main.logger, level='DEBUG') as cm:
             main.run()
     self.assertEqual(exc.exception.args[0], 1)
     self.assertEqual(
         cm.output[0],
         'ERROR:src.main:Invalid syntax: '
         'Document is empty, line 1, column 1',
     )
     os.remove(file.name)
Example #9
0
    def go(self,
           intro: str,
           outro: str,
           base: str,
           target: str,
           *,
           fn_name: Optional[str] = None,
           **kwargs: Any) -> int:
        base = intro + "\n" + base + "\n" + outro
        target = intro + "\n" + target + "\n" + outro
        compiler = Compiler("test/compile.sh", show_errors=True)

        # For debugging, to avoid the auto-deleted directory:
        # target_dir = tempfile.mkdtemp()
        with tempfile.TemporaryDirectory() as target_dir:
            with open(os.path.join(target_dir, "base.c"), "w") as f:
                f.write(base)

            target_o = compiler.compile(target, show_errors=True)
            assert target_o is not None
            shutil.move(target_o, os.path.join(target_dir, "target.o"))

            shutil.copy2("test/compile.sh",
                         os.path.join(target_dir, "compile.sh"))

            if fn_name:
                with open(os.path.join(target_dir, "function.txt"), "w") as f:
                    f.write(fn_name)

            opts = main.Options(directories=[target_dir],
                                stop_on_zero=True,
                                **kwargs)
            return main.run(opts)[0]
def test_coding():
    main.INPUT_WORD = 'Coding'
    main.INPUT_WORD_LIST = ['Cyst', 'Fist', 'Kissed', 'Midst']

    _, words = main.run()

    assert not words
def test_twist():
    main.INPUT_WORD = 'Twist'
    main.INPUT_WORD_LIST = ['Cyst', 'Fist', 'Kissed', 'Midst']

    _, words = main.run()

    assert set(words) == {'Fist', 'Cyst'}
def test_missed():
    main.INPUT_WORD = 'Missed'
    main.INPUT_WORD_LIST = ['Cyst', 'Fist', 'Kissed', 'Midst']

    _, words = main.run()

    assert set(words) == {'Kissed'}
def test_science():
    main.INPUT_WORD = 'Science'
    main.INPUT_WORD_LIST = [
        'Computing', 'Polluting', 'Diluting', 'Commuting', 'Recruiting',
        'Drooping'
    ]

    _, words = main.run()

    assert not words
def test_convoluting():
    main.INPUT_WORD = 'Convoluting'
    main.INPUT_WORD_LIST = [
        'Computing', 'Polluting', 'Diluting', 'Commuting', 'Recruiting',
        'Drooping'
    ]

    _, words = main.run()

    assert set(words) == {'Polluting', 'Diluting'}
def test_disputing():
    main.INPUT_WORD = 'Disputing'
    main.INPUT_WORD_LIST = [
        'Computing', 'Polluting', 'Diluting', 'Commuting', 'Recruiting',
        'Drooping'
    ]

    _, words = main.run()

    assert words == ['Computing']
Example #16
0
 def go(self, filename, fn_name, **kwargs) -> int:
     d = self.tmp_dirs[(filename, fn_name)].name
     score, = main.run(main.Options(directories=[d], stop_on_zero=True, **kwargs))
     return score
Example #17
0
from src.main import run

run()
Example #18
0
def start():
    run()
Example #19
0
 def test(self):
     r = run()
     assert r.status_code == 200
Example #20
0
if __name__ == '__main__':
    # Parse filename.
    parser = argparse.ArgumentParser(description="TODO write description.")
    parser.add_argument('--file', help='Transactions filename')
    args = parser.parse_args()

    username = os.environ['YNAB_USERNAME']
    password = os.environ['YNAB_PASSWORD']

    if not username:
        print("No YNAB username provided")
        sys.exit()

    if not password:
        print("No YNAB password provided")
        sys.exit()

    if not args.file:
        print("Error: No filename provided")
        sys.exit()

    args.email = username
    args.password = password
    args.budgetname = "My Budget"

    # Do not display pynYNAB logs in the console.
    pynynab_logger = logging.getLogger('pynYNAB')
    pynynab_logger.propagate = False

    run(args)
 def go(self, filename, fn_name) -> int:
     d = self.tmp_dirs[(filename, fn_name)].name
     score, = main.run(main.Options(directories=[d]))
     return score
Example #22
0
def test_run_group():
    main.run("group","sae.kpi")
Example #23
0
from src.main import run

while True:
    text = input('pr >')
    result, error = run('<stdin>', text)

    if error:
        print(error)
    else:
        print(result)
Example #24
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Author:zhangcong
# Email:[email protected]

import os
import sys

sys.path.append(os.path.dirname(os.getcwd()))

from src import main

if __name__ == "__main__":
    main.run()
# this script is for running the pipeline

from src import main

if __name__ == "__main__":
    config_map, kwargs = main.parse_args()
    main.run(config_map, **kwargs)
Example #26
0
#! /usr/bin/python3
# -*- coding:utf-8 -*-
from src import main

main.run('127.0.0.1', 8080, True)
Example #27
0
# -*- coding: utf-8 -*-
import sys
from PyQt5.QtGui import QGuiApplication
from src import main

app = QGuiApplication(sys.argv)
main.run(app)
Example #28
0
import src.main as main

if __name__ == "__main__":
	main.run()
Example #29
0
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Author: PanFei Liu

import os
import sys

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

sys.path.append(BASE_DIR)

from src import main

if __name__ == '__main__':
    s = main.run()
Example #30
0
 def test_success_json_output(self):
     sys.argv[1:] = [self.file.name, '--output=json']
     with patch('sys.stdout', new=StringIO()) as mocked_stdout:
         main.run()
     expected = json.dumps({"user": {"2007-12-12": 3600}})
     self.assertEqual(expected, mocked_stdout.getvalue())
Example #31
0
#!/usr/bin/env python


import re
import sys
from src import main

if __name__ == '__main__':
    sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
    sys.exit(main.run())
Example #32
0
def test_run_case():
    main.run("case","kpi.agreement_overlap_check.hotel_count")