Esempio n. 1
0
    def test_single_step(self):
        """ should run single step only """

        support.create_project(self, 'white-bear-lake')
        support.add_step(self)
        support.add_step(self)
        support.add_step(self)

        project = cauldron.project.internal_project

        r = run.execute(context=cli.make_command_context(name=run.NAME),
                        single_step=True)

        self.assertFalse(r.failed)
        self.assertFalse(project.steps[0].is_dirty())
        self.assertTrue(project.steps[1].is_dirty())
        self.assertTrue(project.steps[2].is_dirty())

        r = run.execute(context=cli.make_command_context(name=run.NAME),
                        single_step=True)

        self.assertFalse(r.failed)
        self.assertFalse(project.steps[0].is_dirty())
        self.assertFalse(project.steps[1].is_dirty())
        self.assertTrue(project.steps[2].is_dirty())

        support.run_command('close')
Esempio n. 2
0
    def test_plotly_project(self):
        support.open_project(self, '@examples:time-gender')

        response = support.run_command('run')
        self.assertFalse(response.failed)

        support.run_command('close')
Esempio n. 3
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.internal_project
        dom = project.steps[0].dom  # type: str

        self.assertEqual(dom.count(print_string), 2,
                         'should have printed ascii lowercase')

        support.run_command('close')
Esempio n. 4
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 "BCFHMNOPRS":',
            '    print("{}AT".format(letter))', '    time.sleep(0.5)'
        ])

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

        step = cauldron.project.internal_project.steps[0]

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

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

        response.thread.join()
        dom = step.dumps()
        self.assertEqual(dom.count('BAT'), 1)
        self.assertLess(dom.count('SAT'), 2)

        support.run_command('close')
Esempio n. 5
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')
Esempio n. 6
0
    def test_refresh(self):
        """ should refresh """

        r = support.run_command('open @examples:hello_cauldron')
        r = support.run_command('refresh')
        self.assertFalse(r.failed, 'should not have failed')
        self.assertEqual(r.messages[0].code, 'PROJECT_REFRESHED')
Esempio n. 7
0
    def test_refresh_remote(self):
        """ should refresh """

        support.run_command('open @examples:hello_cauldron')
        r = support.run_remote_command('refresh')
        self.assertFalse(r.failed, 'should not have failed')
        self.assert_has_success_code(r, 'PROJECT_REFRESHED')
Esempio n. 8
0
    def test_list(self):
        """

        :return:
        """

        support.run_command('open --available')
Esempio n. 9
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.internal_project
        dom = project.steps[0].dom  # type: str

        self.assertEqual(dom.count(print_string), 2,
                         'should have printed ascii lowercase')

        support.run_command('close')
Esempio n. 10
0
    def test_steps_modify(self):
        """Should modify a step"""
        response = support.create_project(self, 'lindsey')
        self.assertFalse(
            response.failed,
            Message(
                'should not have failed to create project',
                response=response
            )
        )

        project = cauldron.project.get_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'))
        )
Esempio n. 11
0
    def test_exception(self):
        """
        """

        support.create_project(self, 'brad')
        support.add_step(
            self, 'brad_one.py', cli.reformat(
                """
                import cauldron as cd

                a = dict(
                    one=1,
                    two=['1', '2'],
                    three={'a': True, 'b': False, 'c': True}
                )

                cd.display.inspect(a)
                cd.shared.a = a
                cd.display.workspace()

                """
            )
        )
        support.add_step(self, 'brad_two.py', "1 + 's'")

        r = support.run_command('run .')
        self.assertFalse(r.failed, 'should not have failed')

        r = support.run_command('run .')
        self.assertTrue(r.failed, 'should have failed')
Esempio n. 12
0
    def test_status_remote(self):
        """ """

        support.run_command('open @examples:seaborn')
        r = support.run_remote_command('status')
        self.assertFalse(r.failed, 'should not have failed')
        self.assertEqual(r.messages[0].code, 'STATUS_CREATED')
Esempio n. 13
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')
Esempio n. 14
0
    def test_autocomplete(self):
        """

        :return:
        """

        support.create_project(self, 'gina')
        support.add_step(self, 'a.py')
        support.add_step(self, 'b.py')

        result = support.autocomplete('steps a')
        self.assertIn('add', result)

        result = support.autocomplete('steps modify ')
        self.assertEqual(
            len(result), 2,
            'there are two steps in {}'.format(result)
        )

        result = support.autocomplete('steps modify a.py --')
        self.assertIn('name=', result)

        result = support.autocomplete('steps modify fake.py --position=')
        self.assertEqual(
            len(result), 2,
            'there are two steps in {}'.format(result)
        )

        support.run_command('close')
Esempio n. 15
0
    def test_no_open_project(self):
        """ should fail when no project is open """

        r = support.run_command('reload')
        self.assertTrue(r.failed, 'should have failed')
        self.assertEqual(r.errors[0].code, 'NO_PROJECT_FOUND')
        support.run_command('close')
Esempio n. 16
0
    def test_folders(self):
        """ should create libs and assets folders in project """

        libs_folder = 'libs_folder'
        assets_folder = 'assets_folder'

        result = support.create_project(self,
                                        'marcus',
                                        libs=libs_folder,
                                        assets=assets_folder)
        self.assertFalse(result.failed)

        project = cd.project.internal_project

        items = os.listdir(project.source_directory)

        self.assertIn(libs_folder, items)
        self.assertIn(assets_folder, items)

        self.assertIn(libs_folder, project.settings.fetch('library_folders'))
        self.assertIn(assets_folder, project.settings.fetch('asset_folders'))

        with open(project.source_path, 'r') as f:
            data = json.load(f)

        self.assertEqual(libs_folder, data['library_folders'][0])
        self.assertEqual(assets_folder, data['asset_folders'][0])

        support.run_command('close')
Esempio n. 17
0
    def test_modify_move(self):
        """..."""
        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
        ))
Esempio n. 18
0
    def test_stop_step_no_halt(self):
        """
        Should stop the step early but continue running future steps
        """
        support.create_project(self, 'homer2')
        support.add_step(self, contents='\n'.join([
            'import cauldron as cd',
            'cd.shared.test = 0',
            'cd.shared.other = 0',
            'cd.step.breathe()',
            'cd.shared.test = 1',
            'cd.step.stop()',
            'cd.shared.test = 2'
        ]))
        support.add_step(self, contents='\n'.join([
            'import cauldron as cd',
            'cd.shared.other = 1'
        ]))

        support.run_command('run')
        project = cd.project.get_internal_project()
        step = project.steps[0]

        self.assertEqual(project.shared.fetch('test'), 1)
        self.assertEqual(project.shared.fetch('other'), 1)
        self.assertNotEqual(-1, step.dom.find('cd-StepStop'))
Esempio n. 19
0
    def test_results_path(self):
        """Results path should always be valid"""

        def assert_valid_path(test: str) -> bool:
            return self.assertTrue(
                test is not None and
                len(test) > 0
            )

        support.create_project(self, 'dudley')
        project = cd.project.internal_project

        project._results_path = None
        assert_valid_path(project.results_path)

        results_directory = environ.configs.fetch('results_directory')
        environ.configs.put(results_directory=None, persists=False)

        assert_valid_path(project.results_path)

        project.settings.put('path_results', os.path.realpath('.'))
        assert_valid_path(project.results_path)

        project.settings.put('path_results', None)
        assert_valid_path(project.results_path)

        environ.configs.put(results_directory=results_directory, persists=False)

        support.run_command('close')
Esempio n. 20
0
    def test_show_remote(self):
        """ should show remote url """

        remote_connection = environ.RemoteConnection(
            url='http://my-fake.url',
            active=True
        )

        support.run_remote_command(
            command='open @examples:hello_cauldron',
            remote_connection=remote_connection
        )

        project = cauldron.project.internal_project
        url = project.make_remote_url(remote_connection.url)

        with patch('webbrowser.open') as func:
            r = support.run_remote_command(
                command='show',
                remote_connection=remote_connection
            )
            self.assertFalse(r.failed, 'should not have failed')
            func.assert_called_once_with(url)

        support.run_command('close')
Esempio n. 21
0
    def test_refresh(self):
        """ should refresh """

        r = support.run_command('open @examples:hello_cauldron')
        r = support.run_command('refresh')
        self.assertFalse(r.failed, 'should not have failed')
        self.assertEqual(r.messages[0].code, 'PROJECT_REFRESHED')
Esempio n. 22
0
    def test_clear(self):
        """ should clear variables successfully """

        support.run_command('open @examples:hello_cauldron')
        response = support.run_command('clear')
        self.assertFalse(response.failed, 'should not have failed')
        support.run_command('close')
Esempio n. 23
0
    def test_status_remote(self):
        """ """

        support.run_command('open @examples:seaborn')
        r = support.run_remote_command('status')
        self.assertFalse(r.failed, 'should not have failed')
        self.assertEqual(r.messages[0].code, 'STATUS_CREATED')
Esempio n. 24
0
    def test_list(self):
        """

        :return:
        """

        support.run_command('open --available')
Esempio n. 25
0
    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')
Esempio n. 26
0
    def test_reload(self):
        """ should reload the currently opened project """

        support.run_command('open @examples:hello_cauldron')
        r = support.run_command('reload')
        self.assertFalse(r.failed, 'should not have failed')
        support.run_command('close')
Esempio n. 27
0
    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.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')

        support.run_command('close')
Esempio n. 28
0
    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')
Esempio n. 29
0
    def test_exception(self):
        """
        """

        support.create_project(self, 'brad')
        support.add_step(
            self, 'brad_one.py', cli.reformat(
                """
                import cauldron as cd

                a = dict(
                    one=1,
                    two=['1', '2'],
                    three={'a': True, 'b': False, 'c': True}
                )

                cd.display.inspect(a)
                cd.shared.a = a
                cd.display.workspace()

                """
            )
        )
        support.add_step(self, 'brad_two.py', "1 + 's'")

        r = support.run_command('run .')
        self.assertFalse(r.failed, 'should not have failed')

        r = support.run_command('run .')
        self.assertTrue(r.failed, 'should have failed')
Esempio n. 30
0
    def test_refresh_remote(self):
        """ should refresh """

        support.run_command('open @examples:hello_cauldron')
        r = support.run_remote_command('refresh')
        self.assertFalse(r.failed, 'should not have failed')
        self.assert_has_success_code(r, 'PROJECT_REFRESHED')
Esempio n. 31
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')
Esempio n. 32
0
    def test_set_path(self):
        """ should set a cleaned path"""

        r = support.run_command('configure __test_path ~/abc --forget')
        self.assertFalse(r.failed, 'should not have failed')

        r = support.run_command('configure __test_path --remove')
        self.assertFalse(r.failed, 'should not have failed')
Esempio n. 33
0
    def test_status_with_data(self):
        """ """

        support.run_command('open @examples:hello_text')
        support.run_command('run')
        r = support.run_command('status')
        self.assertFalse(r.failed, 'should not have failed')
        self.assertEqual(r.messages[0].code, 'STATUS_CREATED')
Esempio n. 34
0
    def test_set_path(self):
        """ should set a cleaned path"""

        r = support.run_command('configure __test_path ~/abc --forget')
        self.assertFalse(r.failed, 'should not have failed')

        r = support.run_command('configure __test_path --remove')
        self.assertFalse(r.failed, 'should not have failed')
Esempio n. 35
0
    def test_status_with_data(self):
        """ """

        support.run_command('open @examples:hello_text')
        support.run_command('run')
        r = support.run_command('status')
        self.assertFalse(r.failed, 'should not have failed')
        self.assertEqual(r.messages[0].code, 'STATUS_CREATED')
Esempio n. 36
0
    def test_set_paths(self):
        """ should set multiple clean paths """

        r = support.run_command('configure __test_paths ~/abc ~/def --forget')
        self.assertFalse(r.failed, 'should not have failed')

        r = support.run_command('configure __test_paths --remove')
        self.assertFalse(r.failed, 'should not have failed')
Esempio n. 37
0
    def test_set_persists(self):
        """ should echo does not exist setting """

        r = support.run_command('configure __test__ abc')
        self.assertFalse(r.failed, 'should not have failed')

        r = support.run_command('configure __test__ --remove')
        self.assertFalse(r.failed, 'should not have failed')
Esempio n. 38
0
    def test_set_persists(self):
        """ should echo does not exist setting """

        r = support.run_command('configure __test__ abc')
        self.assertFalse(r.failed, 'should not have failed')

        r = support.run_command('configure __test__ --remove')
        self.assertFalse(r.failed, 'should not have failed')
Esempio n. 39
0
    def test_set_paths(self):
        """ should set multiple clean paths """

        r = support.run_command('configure __test_paths ~/abc ~/def --forget')
        self.assertFalse(r.failed, 'should not have failed')

        r = support.run_command('configure __test_paths --remove')
        self.assertFalse(r.failed, 'should not have failed')
Esempio n. 40
0
    def test_refresh_no_project(self):
        """ should refresh """

        r = support.run_command('refresh')
        self.assertTrue(r.failed, 'should have failed')
        self.assertEqual(r.errors[0].code, 'NO_OPEN_PROJECT')

        support.run_command('close')
Esempio n. 41
0
    def test_show_fail(self):
        """ should fail to show when no project is opened """

        support.run_command('close')

        with patch('webbrowser.open') as func:
            r = support.run_command('show')
            self.assertTrue(r.failed, 'should have failed with no project')
            func.assert_not_called()
Esempio n. 42
0
    def test_no_such_file(self):
        """ should return a 204 status when no such file exists """

        support.create_project(self, 'downloader')

        downloaded = self.get('/download/fake.filename.not_real')
        self.assertEqual(downloaded.flask.status_code, 204)

        support.run_command('close')
Esempio n. 43
0
    def test_status_failure(self, to_console_formatted_string: MagicMock):
        """ """

        to_console_formatted_string.side_effect = ValueError('Fake Error')

        support.run_command('open @examples:hello_text')
        r = support.run_command('status')
        self.assertTrue(r.failed, 'should have failed')
        self.assertEqual(r.errors[0].code, 'STATUS_ERROR')
Esempio n. 44
0
    def test_initialize_failure(self, *args):
        """ should fail if cannot initialize project """
        support.run_command('open @examples:hello_cauldron')

        with patch('cauldron.runner.initialize') as runner_initialize:
            runner_initialize.side_effect = FileNotFoundError('Fake Error')
            r = support.run_command('reload')

        self.assertTrue(r.failed, 'should have failed')
        self.assertEqual(r.errors[0].code, 'PROJECT_INIT_FAILURE')
Esempio n. 45
0
    def test_missing_project_path(self, *args):
        """ should fail if the project directory does not exist """
        support.run_command('open @examples:hello_cauldron')

        with patch('os.path.exists') as path_exists:
            path_exists.return_value = False
            r = support.run_command('reload')

        self.assertTrue(r.failed, 'should have failed')
        self.assertEqual(r.errors[0].code, 'MISSING_PROJECT_PATH')
Esempio n. 46
0
    def test_last(self):
        """

        :return:
        """

        support.run_command('open @examples:seaborn')
        support.run_command('close')
        r = support.run_command('open -l')
        self.assertFalse(r.failed, 'should not have failed')
Esempio n. 47
0
    def test_refresh_write_error(self, project_write: MagicMock):
        """ should refresh """

        project_write.side_effect = IOError('Fake Error')

        support.run_command('open @examples:hello_cauldron')

        r = support.run_command('refresh')
        self.assertTrue(r.failed, 'should have failed')
        self.assertEqual(r.errors[0].code, 'REFRESH_ERROR')
Esempio n. 48
0
    def test_echo_exists(self):
        """ should echo does not exist setting """

        r = support.run_command('configure __test__ hello --forget')
        self.assertFalse(r.failed, 'should not have failed')

        r = support.run_command('configure __test__')
        self.assertFalse(r.failed, 'should not have failed')

        r = support.run_command('configure __test__ --remove')
        self.assertFalse(r.failed, 'should not have failed')
Esempio n. 49
0
    def test_steps_muting(self):
        """Should mute a step"""
        support.create_project(self, 'larry')

        support.run_command('steps add first.py')

        r = support.run_command('steps mute S01-first.py')
        self.assertFalse(r.failed, 'should not have failed')

        r = support.run_command('steps unmute S01-first.py')
        self.assertFalse(r.failed, 'should nto have failed')
Esempio n. 50
0
    def test_steps_remove(self):
        """Should remove a step"""
        support.create_project(self, 'angelica')

        r = support.run_command('steps add first.py')
        self.assertFalse(r.failed, 'should not have failed')

        r = support.run_command('steps remove S01-first.py')
        self.assertFalse(r.failed, 'should not have failed')

        r = support.run_command('steps remove S01-fake.py')
        self.assertTrue(r.failed, 'should have failed')
Esempio n. 51
0
    def test_remove(self):
        """ """

        directory = self.get_temp_path('aliaser')
        path = os.path.join(directory, 'test.text')
        with open(path, 'w+') as f:
            f.write('This is a test')

        support.run_command('alias add test "{}" --temporary'.format(path))
        r = support.run_command('alias remove test --temporary')
        self.assertFalse(r.failed, 'should not have failed')
        self.assertFalse(r.failed, 'should not have failed')
Esempio n. 52
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')
Esempio n. 53
0
    def test_exit(self):
        """
        """

        r = support.run_command('exit')
        self.assertTrue(r.ended, 'should have ended')
        self.assertFalse(r.failed, 'should not have failed')
Esempio n. 54
0
    def test_jinja(self):
        """ should add jinja template to display """

        support.create_project(self, 'starbuck')

        project = cauldron.project.get_internal_project()

        jinja_path = os.path.join(
            project.source_directory,
            'template.html'
        )

        with open(jinja_path, 'w') as fp:
            fp.write('<div>Hello {{ name }}</div>')

        step_contents = '\n'.join([
            'import cauldron as cd',
            'cd.display.jinja("{}", name="starbuck")'.format(
                jinja_path.replace('\\', '\\\\')
            )
        ])

        support.add_step(self, contents=step_contents)

        r = support.run_command('run')
        self.assertFalse(r.failed, 'should not have failed')
Esempio n. 55
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'
        )
Esempio n. 56
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'
        )
Esempio n. 57
0
    def test_invalid_url_error(self, requests_get: MagicMock):
        """ should fail if the url is not valid """

        requests_get.side_effect = request_exceptions.InvalidURL('Fake')

        r = support.run_command('connect "a url"')
        self.assert_has_error_code(r, 'INVALID_URL')
Esempio n. 58
0
    def test_connection_error(self, requests_get: MagicMock):
        """ should fail if the url cannot be connected to """

        requests_get.side_effect = request_exceptions.ConnectionError('Fake')

        r = support.run_command('connect "a url"')
        self.assert_has_error_code(r, 'CONNECTION_ERROR')
Esempio n. 59
0
    def test_other_error(self, requests_get: MagicMock):
        """ should fail if the get request raises an unknown exception """

        requests_get.side_effect = ValueError('Fake')

        r = support.run_command('connect http://some.url')
        self.assert_has_error_code(r, 'CONNECT_COMMAND_ERROR')
Esempio n. 60
0
    def test_bad_status_code(self, requests_get: MagicMock):
        """ should fail if the get request does not have a 200 status code """

        requests_get.return_value = MockResponse(status_code=500)

        r = support.run_command('connect http://some.url')
        self.assert_has_error_code(r, 'CONNECTION_ERROR')