Beispiel #1
0
def test_invalid_variable_value(tmp):
    argv = ['generate', 'test2', tmp.dir, '--defaults']

    with GenerateApp(argv=argv) as app:
        msg = "Invalid Response.*"
        with raises(AssertionError, match=msg):
            app.run()
Beispiel #2
0
def test_prompt(tmp):
    argv = ['generate', 'test1', tmp.dir]

    with GenerateApp(argv=argv) as app:
        msg = "reading from stdin while output is captured"
        with raises(OSError, message=msg):
            app.run()
Beispiel #3
0
def test_copy(tmp, rando):
    with TestApp(extensions=['jinja2'], template_handler='jinja2') as app:
        # create a template src
        os.makedirs(os.path.join(tmp.dir, 'src'))
        with open(os.path.join(tmp.dir, 'src', 'take-me'), 'w') as f:
            f.write('{{ rando }}')

        with open(os.path.join(tmp.dir, 'src', 'ignore-me'), 'w') as f:
            f.write('{{ rando }}')

        with open(os.path.join(tmp.dir, 'src', 'exclude-me'), 'w') as f:
            f.write('{{ rando }}')

        # copy to dest

        app.template.copy(os.path.join(tmp.dir, 'src'),
                          os.path.join(tmp.dir, 'dest'),
                          {'rando': rando},
                          exclude=['.*exclude-me.*'],
                          ignore=['.*ignore-me.*'])

        # assert variables are interpolated

        print(os.listdir(tmp.dir))
        print(os.listdir(os.path.join(tmp.dir, 'src')))
        print(os.listdir(os.path.join(tmp.dir, 'dest')))
        with open(os.path.join(tmp.dir, 'dest', 'take-me'), 'r') as f:
            assert f.read() == rando

        # assert files are ignored/excluded

        with open(os.path.join(tmp.dir, 'dest', 'exclude-me'), 'r') as f:
            assert f.read() == '{{ rando }}'

        assert not os.path.exists(os.path.join(tmp.dir, 'dest', 'ignore-me'))

        # copy again with and without force

        with raises(AssertionError, match='Destination file already exists:'):
            app.template.copy(os.path.join(tmp.dir, 'src'),
                              os.path.join(tmp.dir, 'dest'),
                              {'rando': rando},
                              exclude=['.*exclude-me.*'],
                              ignore=['.*ignore-me.*'])

        app.template.copy(os.path.join(tmp.dir, 'src'),
                          os.path.join(tmp.dir, 'dest'),
                          {'rando': rando},
                          exclude=['.*exclude-me.*'],
                          ignore=['.*ignore-me.*'],
                          force=True)

        # again with explicit none ignore/exclude for coverage

        app.template.copy(os.path.join(tmp.dir, 'src'),
                          os.path.join(tmp.dir, 'dest'),
                          {'rando': rando},
                          exclude=None,
                          ignore=None,
                          force=True)
Beispiel #4
0
def test_invalid_variable_value(tmp):
    argv = ['generate', 'test2', tmp.dir, '--defaults']

    with GenerateApp(argv=argv) as app:
        msg = "Invalid Response (must match: '.*not-bar1.*')"
        with raises(AssertionError, message=msg):
            app.run()
Beispiel #5
0
def test_generate(tmp):
    argv = ['generate', 'test1', tmp.dir, '--defaults']

    with GenerateApp(argv=argv) as app:
        app.run()

        # should have everything
        assert exists_join(tmp.dir, 'take-me')
        res = open(os.path.join(tmp.dir, 'take-me'), 'r').read()
        assert res.find('bar1') >= 0
        assert res.find('bar2') >= 0
        assert res.find('BAR3') >= 0
        assert res.find('Bar4') >= 0
        assert res.find('bar5') >= 0
        assert res.find('bar6') >= 0

        # copied but not rendered
        assert exists_join(tmp.dir, 'exclude-me')
        res = open(os.path.join(tmp.dir, 'exclude-me'), 'r').read()
        assert re.match(r'.*foo1 => \{\{ foo1 \}\}.*', res)

        # should not have been copied
        assert not exists_join(tmp.dir, 'ignore-me')

    # test generate again to trigger already exists

    with GenerateApp(argv=argv) as app:
        with raises(AssertionError, match='Destination file already exists'):
            app.run()
Beispiel #6
0
def test_watchdog_app_paths_bad_spec(tmp):
    class MyApp(WatchdogApp):
        class Meta:
            watchdog_paths = [[tmp.dir, WatchdogEventHandler]]

    with raises(FrameworkError, match="Watchdog path spec must be a tuple"):
        with MyApp():
            pass
Beispiel #7
0
def test_copy(tmp, rando):
    with TestApp(extensions=['jinja2'], template_handler='jinja2') as app:
        # create a template src
        os.makedirs(os.path.join(tmp.dir, 'src'))
        with open(os.path.join(tmp.dir, 'src', 'take-me'), 'w') as f:
            f.write('{{ rando }}')

        with open(os.path.join(tmp.dir, 'src', 'ignore-me'), 'w') as f:
            f.write('{{ rando }}')

        with open(os.path.join(tmp.dir, 'src', 'exclude-me'), 'w') as f:
            f.write('{{ rando }}')

        # copy to dest

        app.template.copy(os.path.join(tmp.dir, 'src'),
                          os.path.join(tmp.dir, 'dest'), {'rando': rando},
                          exclude=['.*exclude-me.*'],
                          ignore=['.*ignore-me.*'])

        # assert variables are interpolated

        print(os.listdir(tmp.dir))
        print(os.listdir(os.path.join(tmp.dir, 'src')))
        print(os.listdir(os.path.join(tmp.dir, 'dest')))
        with open(os.path.join(tmp.dir, 'dest', 'take-me'), 'r') as f:
            assert f.read() == rando

        # assert files are ignored/excluded

        with open(os.path.join(tmp.dir, 'dest', 'exclude-me'), 'r') as f:
            assert f.read() == '{{ rando }}'

        assert not os.path.exists(os.path.join(tmp.dir, 'dest', 'ignore-me'))

        # copy again with and without force

        with raises(AssertionError, match='Destination file already exists:'):
            app.template.copy(os.path.join(tmp.dir, 'src'),
                              os.path.join(tmp.dir, 'dest'), {'rando': rando},
                              exclude=['.*exclude-me.*'],
                              ignore=['.*ignore-me.*'])

        app.template.copy(os.path.join(tmp.dir, 'src'),
                          os.path.join(tmp.dir, 'dest'), {'rando': rando},
                          exclude=['.*exclude-me.*'],
                          ignore=['.*ignore-me.*'],
                          force=True)

        # again with explicit none ignore/exclude for coverage

        app.template.copy(os.path.join(tmp.dir, 'src'),
                          os.path.join(tmp.dir, 'dest'), {'rando': rando},
                          exclude=None,
                          ignore=None,
                          force=True)
def test_watchdog_app_paths_bad_spec(tmp):
    class MyApp(WatchdogApp):
        class Meta:
            watchdog_paths = [
                [tmp.dir, WatchdogEventHandler]
            ]

    with raises(FrameworkError, match="Watchdog path spec must be a tuple"):
        with MyApp():
            pass
Beispiel #9
0
def test_clone(tmp):
    # first test for already exists
    argv = ['generate', 'test1', '--clone', tmp.dir]
    with raises(AssertionError, match='(.*)already exists(.*)'):
        with GenerateApp(argv=argv) as app:
            app.run()

    # then force it
    argv = ['generate', 'test1', '--clone', tmp.dir, '--force']
    with GenerateApp(argv=argv) as app:
        app.run()

    assert exists_join(tmp.dir, '.generate.yml')
def test_mustache_bad_module():
    with MustacheApp() as app:
        msg = "Could not locate template: bad_template.mustache"
        with raises(FrameworkError, match=msg):
            app._meta.template_module = 'this_is_a_bogus_module'
            app.render(dict(foo='bar'), 'bad_template.mustache')
def test_mustache_none_template():
    with MustacheApp() as app:
        msg = "Invalid template path 'None'."
        with raises(FrameworkError, match=msg):
            app.render(dict(foo='bar'), None)
def test_mustache_nonexistent_template():
    with MustacheApp() as app:
        msg = "Could not locate template: missing_template.mustache"
        with raises(FrameworkError, match=msg):
            app.render(dict(foo='bar'), 'missing_template.mustache')
Beispiel #13
0
def test_mustache_bad_module():
    with MustacheApp() as app:
        msg = "Could not locate template: bad_template.mustache"
        with raises(FrameworkError, match=msg):
            app._meta.template_module = 'this_is_a_bogus_module'
            app.render(dict(foo='bar'), 'bad_template.mustache')
Beispiel #14
0
def test_mustache_none_template():
    with MustacheApp() as app:
        msg = "Invalid template path 'None'."
        with raises(FrameworkError, match=msg):
            app.render(dict(foo='bar'), None)
Beispiel #15
0
def test_mustache_nonexistent_template():
    with MustacheApp() as app:
        msg = "Could not locate template: missing_template.mustache"
        with raises(FrameworkError, match=msg):
            app.render(dict(foo='bar'), 'missing_template.mustache')
Beispiel #16
0
def test_main(tmp):
    with raises(SystemExit):
        main()
Beispiel #17
0
def test_jinja2_bad_module():
    with Jinja2App() as app:
        msg = "Could not locate template: bad_template.jinja2"
        with raises(FrameworkError, match=msg):
            app._meta.template_module = 'this_is_a_bogus_module'
            app.render(dict(foo='bar'), 'bad_template.jinja2')
Beispiel #18
0
def test_jinja2_nonexistent_template():
    with Jinja2App() as app:
        msg = "Could not locate template: missing_template.jinja2"
        with raises(FrameworkError, match=msg):
            app.render(dict(foo='bar'), 'missing_template.jinja2')
Beispiel #19
0
def test_jinja2_bad_template():
    with Jinja2App() as app:
        with raises(jinja2.exceptions.TemplateSyntaxError):
            app.render(dict(foo='bar'), 'bad_template.jinja2')