Пример #1
0
    def test_run(self, parse, render):
        with NamedTemporaryFile(mode='w', suffix='.json') as config_file:
            with TemporaryDirectory() as output_directory_path:
                url = 'https://example.com'
                config_dict = {
                    'output': output_directory_path,
                    'base_url': url,
                }
                dump(config_dict, config_file)
                config_file.seek(0)

                with self.assertExit(0):
                    main(['--config', config_file.name, 'generate'])

                self.assertEquals(1, parse.call_count)
                parse_args, parse_kwargs = parse.call_args
                self.assertEquals(1, len(parse_args))
                self.assertIsInstance(parse_args[0], Site)
                self.assertEquals({}, parse_kwargs)

                self.assertEquals(1, render.call_count)
                render_args, render_kwargs = render.call_args
                self.assertEquals(1, len(render_args))
                self.assertIsInstance(render_args[0], Site)
                self.assertEquals({}, render_kwargs)
Пример #2
0
    def test_help_with_invalid_configuration(self, _, __):
        with NamedTemporaryFile(mode='w', suffix='.json') as config_file:
            config_dict = {}
            dump(config_dict, config_file)
            config_file.seek(0)

            with self.assertExit(1):
                main(['--config', config_file.name, '--help'])
Пример #3
0
    def test_configuration_without_help(self, _, __):
        with NamedTemporaryFile(mode='w', suffix='.json') as config_file:
            with TemporaryDirectory() as output_directory_path:
                url = 'https://example.com'
                config_dict = {
                    'output': output_directory_path,
                    'base_url': url,
                }
                dump(config_dict, config_file)
                config_file.seek(0)

                with self.assertExit(2):
                    main(['--config', config_file.name])
Пример #4
0
 def test_with_discovered_configuration(self, _, __):
     with TemporaryDirectory() as cwd:
         with TemporaryDirectory() as output_directory_path:
             with open(join(cwd, 'betty.json'), 'w') as config_file:
                 url = 'https://example.com'
                 config_dict = {
                     'output': output_directory_path,
                     'base_url': url,
                     'plugins': {
                         TestPlugin.name(): {},
                     },
                 }
                 dump(config_dict, config_file)
             original_cwd = getcwd()
             try:
                 chdir(cwd)
                 with self.assertExit(1):
                     main(['test'])
             finally:
                 chdir(original_cwd)
Пример #5
0
 def test_help_without_configuration(self, _, __):
     with self.assertExit(0):
         main(['--help'])
Пример #6
0
 def test_without_arguments(self, _, __):
     with self.assertExit(2):
         main()
Пример #7
0
 def test_with_keyboard_interrupt(self, parser, _, __):
     parser.side_effect = KeyboardInterrupt
     main()
Пример #8
0
from betty import cli

cli.main()