Пример #1
0
    def test_FL_file(self, caplog, tmpdir):
        caplog.set_level(logging.INFO)

        path_str = str(tmpdir).replace('\\', '/')
        log_path = '{}/log.txt'.format(path_str)

        close_loggers = outputting.fancy_logger(log_file=log_path)

        captured = caplog.records
        standard_captured = [k.message for k in captured]

        date = outputting.date()

        correct = ['{}'.format(date),
                   'Log initialised',
                   'The log you are reading was written to {}'.format(log_path)]

        for correct_line, standard_captured_line in itertools.zip_longest(correct, standard_captured):
            assert standard_captured_line == correct_line

        with open(log_path) as log:
            cleaned_log = [l[37:].strip() for l in log.readlines()]
        for correct_line, standard_captured_line in itertools.zip_longest(correct, cleaned_log):
            assert standard_captured_line == correct_line

        close_loggers()
Пример #2
0
    def test_S_config(self, caplog):
        caplog.set_level(logging.INFO)
        config = {'label': None,
                  'config_file': None,
                  'output_path': None,
                  'pickle': False,
                  'min_log_level': 'INFO',
                  'numpy_error_level': 'log'}

        with outputting.Saving(config=config) as saving:
            assert saving is None

        captured = caplog.records

        for level in [k.levelname for k in captured]:
            assert level == 'INFO'

        captured_loggers = [k.name for k in captured]
        correct_loggers = ['Setup', 'Setup', 'Framework', 'Setup']
        for capt, corr in itertools.zip_longest(captured_loggers, correct_loggers):
            assert capt == corr

        standard_captured = [k.message for k in captured]
        correct = ['{}'.format(outputting.date()),
                   'Log initialised',
                   'Beginning task labelled: Untitled',
                   'Shutting down program']

        for correct_line, standard_captured_line in itertools.zip_longest(correct, standard_captured):
            assert standard_captured_line == correct_line
Пример #3
0
    def test_S_folder(self, output_folder, caplog):
        caplog.set_level(logging.INFO)
        output_path = str(output_folder).replace('\\', '/')
        simulation.run(output_path=output_path)

        captured = caplog.records

        for level in [k.levelname for k in captured]:
            assert level == 'INFO'

        captured_loggers = [k.name for k in captured]
        correct_loggers = ['Setup', 'Setup', 'Framework', 'Simulation', 'Setup']
        for capt, corr in itertools.zip_longest(captured_loggers, correct_loggers):
            assert capt == corr

        standard_captured = [k.message.replace('\n', '') for k in captured]
        correct = ['{}'.format(outputting.date()),
                   'Log initialised',
                   'Beginning task labelled: Untitled',
                   "Simulation 0 contains the task Basic: Trials = 100.The model used is QLearn: number_actions = 2, number_cues = 1, number_critics = 2, prior = array([0.5, 0.5]), non_action = 'None', actionCode = {0: 0, 1: 1}, stimulus_shaper = 'model.modelTemplate.Stimulus with ', reward_shaper = 'model.modelTemplate.Rewards with ', decision_function = 'discrete.weightProb with task_responses : 0, 1', alpha = 0.3, beta = 4, expectation = array([[0.5],       [0.5]]).",
                   'Shutting down program']

        for correct_line, standard_captured_line in itertools.zip_longest(correct, standard_captured):
            assert standard_captured_line == correct_line

        assert os.listdir(output_path) == []
Пример #4
0
    def test_S_label(self, caplog, tmpdir):
        caplog.set_level(logging.INFO)

        label = 'label'
        current_date = outputting.date()
        path_str = str(tmpdir)
        path_clean = path_str.replace('\\', '/')
        log_path = '{}/Outputs/{}_{}/log.txt'.format(path_clean, label, current_date)

        config = {'label': label,
                  'config_file': None,
                  'output_path': path_str,
                  'pickle': False,
                  'min_log_level': 'INFO',
                  'numpy_error_level': 'log'}

        with outputting.Saving(config=config) as saving:
            assert callable(saving)

        captured = caplog.records

        for level in [k.levelname for k in captured]:
            assert level == 'INFO'

        captured_loggers = [k.name for k in captured]
        correct_loggers = ['Setup', 'Setup', 'Setup', 'Framework', 'Setup']
        for capt, corr in itertools.zip_longest(captured_loggers, correct_loggers):
            assert capt == corr

        standard_captured = [k.message for k in captured]
        correct = ['{}'.format(current_date),
                   'Log initialised',
                   'The log you are reading was written to {}'.format(log_path),
                   'Beginning task labelled: {}'.format(label),
                   'Shutting down program']

        for correct_line, standard_captured_line in itertools.zip_longest(correct, standard_captured):
            assert standard_captured_line == correct_line

        with open(log_path) as log:
            cleaned_log = [l[37:].strip() for l in log.readlines()]
        for correct_line, standard_captured_line in itertools.zip_longest(correct, cleaned_log):
            assert standard_captured_line == correct_line
Пример #5
0
    def test_S_label(self, output_folder, caplog):
        caplog.set_level(logging.INFO)
        output_path = str(output_folder).replace('\\', '/')
        date = outputting.date()

        simulation.run(label='test', output_path=output_path)

        captured = caplog.records

        for level in [k.levelname for k in captured]:
            assert level == 'INFO'

        captured_loggers = [k.name for k in captured]
        correct_loggers = ['Setup', 'Setup', 'Setup', 'Framework', 'Simulation', 'Setup']
        for capt, corr in itertools.zip_longest(captured_loggers, correct_loggers):
            assert capt == corr

        standard_captured = [k.message.replace('\n', '') for k in captured]
        correct = ['{}'.format(date),
                   'Log initialised',
                   'The log you are reading was written to {}/Outputs/test_{}/log.txt'.format(output_path, date),
                   'Beginning task labelled: test',
                   "Simulation 0 contains the task Basic: Trials = 100.The model used is QLearn: number_actions = 2, number_cues = 1, number_critics = 2, prior = array([0.5, 0.5]), non_action = 'None', actionCode = {0: 0, 1: 1}, stimulus_shaper = 'model.modelTemplate.Stimulus with ', reward_shaper = 'model.modelTemplate.Rewards with ', decision_function = 'discrete.weightProb with task_responses : 0, 1', alpha = 0.3, beta = 4, expectation = array([[0.5],       [0.5]]).",
                   'Shutting down program']

        for correct_line, standard_captured_line in itertools.zip_longest(correct, standard_captured):
            assert standard_captured_line == correct_line

        assert os.path.exists(output_path)
        assert os.path.exists(output_path + '/Outputs')
        folder_path = output_path + '/Outputs/test_{}/'.format(date)
        assert os.path.exists(folder_path)
        assert os.path.exists(folder_path + 'data')
        assert not os.path.exists(folder_path + 'Pickle')

        with open(folder_path + 'log.txt') as log:
            cleaned_log = [l.split('    ')[-1].strip() for l in log.readlines()]
            correct[-2] = correct[-2][:-15]
            final_correct = correct[-1]
            correct[-1] = '[0.5]]).'
            correct.append(final_correct)
        for correct_line, standard_captured_line in itertools.zip_longest(correct, cleaned_log):
            assert standard_captured_line == correct_line
Пример #6
0
    def test_FL_none(self, caplog):
        caplog.set_level(logging.INFO)

        close_loggers = outputting.fancy_logger()

        captured = caplog.records
        standard_captured = [k.message for k in captured]

        for level in [k.levelname for k in captured]:
            assert level == 'INFO'

        for logger in [k.name for k in captured]:
            assert logger == 'Setup'

        correct = ['{}'.format(outputting.date()),
                   'Log initialised']

        for correct_line, standard_captured_line in itertools.zip_longest(correct, standard_captured):
            assert standard_captured_line == correct_line
        close_loggers()
Пример #7
0
    def test_S_none(self, caplog):
        caplog.set_level(logging.INFO)

        with outputting.Saving() as saving:
            captured = caplog.records.copy()
            assert saving is None

        for level in [k.levelname for k in captured]:
            assert level == 'INFO'

        captured_loggers = [k.name for k in captured]
        correct_loggers = ['Setup', 'Setup', 'Framework']
        for capt, corr in itertools.zip_longest(captured_loggers, correct_loggers):
            assert capt == corr

        standard_captured = [k.message for k in captured]
        correct = ['{}'.format(outputting.date()),
                   'Log initialised',
                   'Beginning task labelled: Untitled']

        for correct_line, standard_captured_line in itertools.zip_longest(correct, standard_captured):
            assert standard_captured_line == correct_line