def test_watch_not_needed(self):
        """

        :return:
        """

        support.create_project(self, 'betty')
        support.add_step(self)
        project = cd.project.internal_project
        project.current_step = project.steps[0]

        self.assertFalse(
            reloading.refresh(mime_text),
            Message('Should not reload if the step has not been run before')
        )

        support.run_command('run')

        project.current_step = project.steps[0]

        self.assertFalse(
            reloading.refresh(mime_text),
            Message('Should not reload if module has not changed recently')
        )

        project.current_step = None
        support.run_command('close')
Beispiel #2
0
    def test_print_start(self):
        """ should properly print at the beginning of a step """

        response = support.create_project(self, 'chicago')
        self.assertFalse(
            response.failed,
            Message('should have created project', response=response)
        )

        print_string = string.ascii_lowercase

        code = '\n'.join([
            'import cauldron as cd',
            'print("{}")'.format(print_string),
            'cd.display.text("Hello World")'
        ])

        support.add_step(self, contents=code)

        response = support.run_command('run -f')
        self.assertFalse(
            response.failed,
            Message('should have run step', response=response)
        )

        project = cauldron.project.get_internal_project()
        dom = project.steps[0].dom  # type: str

        self.assertEqual(
            dom.count(print_string),
            2,
            'should have printed ascii lowercase'
        )
    def test_standard_error(self):
        """ should include standard error output """

        response = support.create_project(self, 'bozeman')
        self.assertFalse(
            response.failed,
            Message('should have created project', response=response))

        error_string = 'This is a standard error test'

        code = '\n'.join(
            ['import sys', 'sys.stderr.write("{}")'.format(error_string)])

        support.add_step(self, contents=code)

        response = support.run_command('run -f')
        self.assertFalse(response.failed,
                         Message('should have run step', response=response))

        project = cauldron.project.get_internal_project()

        self.assertTrue(project.steps[0].dom.find(error_string) > 0,
                        'should have included error string')

        self.assertTrue(project.steps[0].dom.find('cd-StdErr') > 0,
                        'should have included StdErr dom')
Beispiel #4
0
    def assert_has_error_code(self, response, code: str):
        """

        :param response:
        :param code:
        :return:
        """

        self.assertTrue(
            response.failed,
            Message('Did not Fail',
                    'Response should have failed if expecting an error',
                    response=response))

        self.assertGreater(
            len(response.errors), 0,
            Message('No Errors Found',
                    'There should have been an error in the response',
                    response=response))

        codes = [error.code for error in response.errors]

        self.assertIn(
            code, codes,
            Message('Error Code Not Found',
                    'The error code "{}" was not found in the response errors',
                    response=response))
    def test_solo_error(self):
        """ should display an error """

        response = support.create_project(self, 'bismark')
        self.assertFalse(
            response.failed,
            Message('should have created project', response=response))

        code = 'x = 1 + "abcdefg"'

        support.add_step(self, contents=code)

        response = support.run_command('run -f')
        self.assertTrue(response.failed,
                        Message('should have failed', response=response))

        project = cauldron.project.internal_project

        self.assertTrue(project.steps[0].dom.find('cd-CodeError') > 0,
                        'should have included error dom')

        self.assertTrue(project.steps[0].dom.find('abcdefg') > 0,
                        'should have included error line of code')

        support.run_command('close')
Beispiel #6
0
    def test_print_solo(self):
        """ should properly print in a step that does nothing but print """
        response = support.create_project(self, 'minneapolis')
        self.assertFalse(
            response.failed,
            Message('should have created project', response=response)
        )

        print_string = string.ascii_lowercase

        code = '\n'.join([
            'values = [x ** 2 for x in range(100)]',
            'print("{}")'.format(print_string)
        ])

        support.add_step(self, contents=code)

        response = support.run_command('run -f')
        self.assertFalse(
            response.failed,
            Message('should have run step', response=response)
        )

        project = cauldron.project.get_internal_project()
        dom = project.steps[0].dom  # type: str

        self.assertEqual(
            dom.count(print_string),
            2,
            'should have printed ascii lowercase'
        )
Beispiel #7
0
    def test_print_multiple(self):
        """ should properly print multiple times within a step """

        response = support.create_project(self, 'omaha')
        self.assertFalse(
            response.failed,
            Message('should have created project', response=response))

        code = '\n'.join([
            'import cauldron as cd', 'import string',
            'print(string.ascii_lowercase)', 'cd.display.text("Hello World")',
            'print(string.ascii_uppercase)', 'print(string.hexdigits)'
        ])

        support.add_step(self, contents=code)

        response = support.run_command('run -f')
        self.assertFalse(response.failed,
                         Message('should have run step', response=response))

        project = cauldron.project.internal_project
        dom = project.steps[0].dom  # type: str

        self.assertEqual(dom.count(string.ascii_lowercase), 1,
                         'should have printed ascii lowercase')

        self.assertEqual(dom.count(string.ascii_uppercase), 1,
                         'should have printed ascii uppercase')

        self.assertEqual(dom.count(string.hexdigits), 1,
                         'should have printed hex digits')

        support.run_command('close')
Beispiel #8
0
    def test_modify_move(self):
        """

        :return:
        """

        support.create_project(self, 'harvey')
        support.add_step(self, contents='#S1')
        support.add_step(self, contents='#S2')

        r = support.run_command('steps list')
        step = r.data['steps'][-1]

        r = support.run_command(
            'steps modify {} --position=0'.format(step['name'])
        )
        self.assertFalse(r.failed, Message(
            'Failed to move step 2 to the beginning',
            response=r
        ))

        r = support.run_command('steps list')
        step = r.data['steps'][0]

        with open(step['source_path'], 'r') as f:
            contents = f.read()

        self.assertEqual(contents.strip(), '#S2', Message(
            'Step 2 should now be Step 1',
            response=r
        ))

        support.run_command('close')
Beispiel #9
0
    def test_steps_modify(self):
        """
        """

        response = support.create_project(self, 'lindsey')
        self.assertFalse(
            response.failed,
            Message(
                'should not have failed to create project',
                response=response
            )
        )

        project = cauldron.project.internal_project
        directory = project.source_directory

        r = support.run_command('steps add first.py')
        self.assertFalse(r.failed, 'should not have failed')
        self.assertTrue(os.path.exists(os.path.join(directory, 'S01-first.py')))

        r = support.run_command('steps modify S01-first.py --name="second.py"')
        self.assertFalse(r.failed, 'should not have failed')
        self.assertFalse(
            os.path.exists(os.path.join(directory, 'S01-first.py'))
        )
        self.assertTrue(
            os.path.exists(os.path.join(directory, 'S01-second.py'))
        )

        support.run_command('close')
Beispiel #10
0
    def test_slow_printing(self):
        """Should not repeat print statements during slow running steps"""
        response = support.create_project(self, 'duluth')
        self.assertFalse(
            response.failed,
            Message('should have created project', response=response)
        )

        code = '\n'.join([
            'import time',
            'for letter in "BCFHMNOPRSTUVWX":',
            '    print("{}AT".format(letter))',
            '    time.sleep(0.5)'
        ])

        support.add_step(self, contents=code)
        response = commander.execute('run', '-f')
        response.thread.join(2)

        step = cauldron.project.get_internal_project().steps[0]
        dom = step.dumps()
        self.assertEqual(dom.count('BAT'), 1, 'first check failed')

        response.thread.join(1)
        dom = step.dumps()
        self.assertEqual(dom.count('BAT'), 1, 'second check failed')

        response.thread.join()
        dom = step.dumps()
        self.assertEqual(dom.count('BAT'), 1, 'third check failed')
        self.assertLess(dom.count('SAT'), 2, 'fourth check failed')
Beispiel #11
0
    def assert_no_errors(self, response: environ.Response):
        """ asserts that the response object contains no errors """

        self.assertEqual(
            0, len(response.errors),
            Message('Errors found',
                    'should not have had errors',
                    response=response))
    def test_watch_not_needed(self):
        """Don't reload modules that haven't changed."""
        support.create_project(self, 'betty')
        support.add_step(self)
        project = cd.project.get_internal_project()
        project.current_step = project.steps[0]

        self.assertFalse(
            reloading.refresh(mime_text),
            Message('Expect no reload if the step has not been run before.'))

        support.run_command('run')
        project.current_step = project.steps[0]

        self.assertFalse(
            reloading.refresh(mime_text),
            Message('Expect no reload if module has not changed recently.'))
Beispiel #13
0
    def test_list_all(self):
        """ should list configurations """

        response = support.run_command('configure --list')
        self.assertFalse(
            response.failed,
            Message('Failed To List Configurations'
                    'should not have failed',
                    response=response))
Beispiel #14
0
    def test_purge_all(self):
        """ should purge current results directory """

        response = support.run_command('purge --force --all')
        self.assertFalse(
            response.failed,
            Message('FAILED PURGE ALL',
                    'should not have failed to purge all in results directory',
                    response=response))
Beispiel #15
0
def create_project(
        tester: scaffolds.ResultsTest,
        name: str,
        path: str = None,
        forget: bool = True,
        confirm: bool = True,
        remote_connection: cli.CommandContext = None,
        **kwargs
) -> 'environ.Response':
    """

    :param tester:
    :param name:
    :param path:
    :param forget:
    :param confirm:
    :param remote_connection:
    :param kwargs:
    :return:
    """

    version = ''.join(['{}'.format(s) for s in sys.version_info])

    if path is None:
        path = tester.get_temp_path('project-{}-{}-'.format(name, version))

    args = [name, path]
    for key, value in kwargs.items():
        args.append('--{}="{}"'.format(key, value))

    if forget:
        args.append('--forget')

    args = ' '.join([a for a in args if a and len(a) > 0])

    r = commander.execute('create', args, remote_connection=remote_connection)
    if r.thread:
        r.thread.join()

    # Prevent threading race conditions
    check_count = 0
    while confirm and r.success and not cauldron.project.internal_project:
        if check_count > 100:
            break

        check_count += 1
        time.sleep(0.25)

    if confirm:
        tester.assertFalse(r.failed, Message(
            'support.create_project',
            ['project should have been created'],
            response=r
        ))
        tester.assertIsNotNone(cauldron.project.internal_project)

    return r
    def test_watch_bad_argument(self):
        """

        :return:
        """

        self.assertFalse(
            reloading.refresh(datetime, force=True),
            Message('Should not reload not a module')
        )
    def test_watch_recursive(self):
        """

        :return:
        """

        self.assertTrue(
            reloading.refresh('email', recursive=True, force=True),
            Message('Should reload the email module')
        )
    def test_watch_good_argument(self):
        """

        :return:
        """

        self.assertTrue(
            reloading.refresh('datetime', force=True),
            Message('Should reload the datetime module')
        )
Beispiel #19
0
    def assert_has_success_code(self, response, code: str):
        """

        :param response:
        :param code:
        """

        self.assertGreater(
            len(response.messages), 0,
            Message('No Messages Found',
                    'There should have been a message in the response',
                    response=response))

        codes = [message.code for message in response.messages]

        self.assertIn(
            code, codes,
            Message('Notification Code Not Found',
                    'The code "{}" was not found in the response messages',
                    response=response))
Beispiel #20
0
    def test_snapshot_fail(self):
        """
        """

        support.run_command('close')

        r = support.run_command('snapshot add fake --no-show')
        self.assertTrue(r.failed, Message(
            'should have failed with no project',
            response=r
        ))
Beispiel #21
0
    def test_snapshot_open(self):
        """
        """

        r = support.create_project(self, 'gerald')
        self.assertFalse(r.failed)
        self.assertIsNotNone(cauldron.project.internal_project)

        r = support.run_command('snapshot add fake --no-show')
        self.assertFalse(r.failed, Message(
            'should have created snapshot',
            response=r
        ))

        r = support.run_command('snapshot open fake --no-show')
        self.assertFalse(r.failed, Message(
            'should have opened snapshot',
            response=r
        ))

        support.run_command('close')
Beispiel #22
0
    def test_snapshot_no_command(self):
        """
        """

        support.create_project(self, 'ted')

        r = support.run_command('snapshot')
        self.assertTrue(r.failed, Message(
            'Should fail if there is no command action',
            response=r
        ))

        support.run_command('close')
Beispiel #23
0
    def run_project(self, project_id: str, project_directory: str):
        directory = self.get_temp_path(project_id)
        result = run_project(project_directory, directory)

        self.assertFalse(
            result.response.failed,
            Message('Failed to run project', response=result.response))
        self.assertTrue(os.path.exists(result.results_directory))
        self.assertTrue(
            os.path.exists(
                os.path.join(result.results_directory, 'display.html')))
        self.assertTrue(os.path.exists(result.logging_path))
        self.assertTrue(os.path.getsize(result.logging_path) > 0)
        self.assertTrue(os.path.exists(result.reader_path))
Beispiel #24
0
    def test_steps_list(self):
        """Should list steps"""
        support.create_project(self, 'angelica')
        r = support.run_command('steps list')
        self.assertEqual(
            len(r.data['steps']), 0,
            Message('New project should have no steps to list', response=r))

        for v in ['a.py', 'b.md', 'c.html', 'd.rst']:
            r = support.run_command('steps add "{}"'.format(v))
            self.assertFalse(r.failed, 'should not have failed')

        r = support.run_command('steps list')
        self.assertFalse(r.failed, 'should not have failed')
Beispiel #25
0
    def test_remote(self):
        """Should function remotely"""
        support.create_project(self, 'nails')
        project = cauldron.project.get_internal_project()

        support.run_remote_command('open "{}" --forget'.format(
            project.source_directory))
        project = cauldron.project.get_internal_project()

        added_response = support.run_remote_command('steps add')
        self.assertTrue(added_response.success,
                        Message('Add Step Failed', response=added_response))

        self.assertEqual(len(project.steps), 1)
Beispiel #26
0
    def run_project(self, project_id: str, project_directory: str):
        directory = self.get_temp_path(project_id)
        output_directory = os.path.join(directory, 'test', 'results')
        logging_path = os.path.join(directory, 'logging', 'test.log')

        response = cauldron.run_project(project_directory=project_directory,
                                        output_directory=output_directory,
                                        logging_path=logging_path)

        self.assertFalse(response.failed,
                         Message('Failed to run project', response=response))
        self.assertTrue(os.path.exists(output_directory))
        self.assertTrue(
            os.path.exists(os.path.join(output_directory, 'display.html')))
        self.assertTrue(os.path.exists(logging_path))
        self.assertTrue(os.path.getsize(logging_path) > 0)
Beispiel #27
0
    def test_snapshot_remove_all(self):
        """
        """

        support.create_project(self, 'veronica')
        support.run_command('snapshot add first --no-show')
        support.run_command('snapshot add second --no-show')

        patch_target = 'cauldron.cli.commands.snapshot.actions.query.confirm'
        with patch(patch_target, return_value=True):
            r = support.run_command('snapshot remove')
            self.assertFalse(r.failed, Message(
                'should have removed all snapshots',
                response=r
            ))

        support.run_command('close')
    def test_failed_step_changes(self, get_running_step_changes):
        """ should fail if unable to get changes for the running step """

        get_running_step_changes.side_effect = ValueError('Fake Error')

        active_response = self.activate_execution('failed-step-changes')

        run_status = self.get('/run-status/{}'.format(
            active_response.identifier))
        self.assertEqual(run_status.flask.status_code, 200)

        response = run_status.response
        self.assertFalse(response.failed,
                         Message('Failed Response', response=response))
        self.assertEqual(response.data['run_status'], 'running')
        self.assertIsNone(response.data['step_changes'])

        self.deactivate_execution(active_response.identifier)
    def test_not_running(self):
        """ should succeed even if the step is no longer running """

        active_response = self.activate_execution('no-step-running', False)

        run_status = self.get('/run-status/{}'.format(
            active_response.identifier))
        self.assertEqual(run_status.flask.status_code, 200)

        response = run_status.response
        self.assertFalse(response.failed,
                         Message('Response Failed', response=response))
        self.assertEqual(response.data['run_status'], 'complete')

        self.assertNotIn(active_response.identifier,
                         server_runner.active_execution_responses)

        self.deactivate_execution(active_response.identifier)
 def test_watch_recursive(self):
     """Should reload the email module."""
     self.assertTrue(reloading.refresh('email', recursive=True, force=True),
                     Message('Expected email module to be reloaded.'))