예제 #1
0
def test_register_resource_empty():
    context = Context()
    resource = Mock()
    resource.get_resource_keys.return_value = None

    # should just ignore
    context.register_resource(resource)
예제 #2
0
def test_register_resource_two_resources():
    context = Context()
    resource = Mock()
    resource.get_resource_keys.return_value = [890, 981]

    context.resources = {123: "hoho", 567: "bebe"} # in real, "hoho" and "bebe" will be resource instances
    context.current_resource_set = Mock()

    context.register_resource(resource)

    assert context.current_resource_set.mock_calls == [call.add_item(resource), call.add_item(resource)]
예제 #3
0
def test_register_resource_conflicts():
    context = Context()
    resource = Mock()
    resource2 = Mock()
    resource.get_resource_keys.return_value = [123]

    context.resources = {123: resource2} # in real, "hoho" and "bebe" will be resource instances
    context.current_resource_set = Mock()

    context.register_resource(resource)

    assert resource2.mock_calls == [call.resolve_conflict(resource)]
    assert context.current_resource_set.mock_calls == [call.add_item(resource2)]
예제 #4
0
def test_resource_set_begin_end():
    context = Context()
    assert len(context.resource_set_stack) == 0
    assert context.current_resource_set is None
    assert len(context.resource_set_list) == 0

    resource_set = Mock()
    resource_set.name = 'foo'
    context.resource_set_begin(resource_set)

    assert len(context.resource_set_stack) == 2
    assert len(context.resource_set_list) == 2
    assert context.current_resource_set == resource_set

    context.resource_set_end()

    assert len(context.resource_set_stack) == 1
    assert len(context.resource_set_list) == 2
    assert context.current_resource_set == context.root_resource_set
예제 #5
0
파일: settings.py 프로젝트: ribozz/cratis
    def pre_setup(cls):
        super(Common, cls).pre_setup()

        cls.load_features()

        ctx = Context()

        with pw.resource_set(ctx, name='main'):
            for feature in cls.FEATURES:
                requirements = []
                for req in feature.get_required_packages(cls):
                    requirements.append(req)

                if requirements:
                    ctx.apply(
                        pw.pip_package(*requirements)
                    )

        changes = ctx.changeset()

        if changes.needed():

            if len(sys.argv) == 2 and sys.argv[1] == '--requirements':
                print('\nChanges to be applied:\n')
                for item in changes.items:
                    print('\t - %s' % item.description)

                changes.commit()

                exit(0)

            else:
                print('\nSome required packages are not installed:\n')
                for item in changes.items:
                    print('\t - %s' % item.description)

                print 'Execute "cratis --requirements" to install those'

                exit(1)
예제 #6
0
파일: cli.py 프로젝트: pywizard/pywizard
def apply_action(args):
    """
    Handles pywizard execution
    """

    path = args.path

    context = Context()

    with pw.resource_set(context, name='main', rollback=args.rollback):
        execute(path, context)

    if args.tree:
        more_indent = re.compile(r'^(\s*)', re.MULTILINE)
        print(more_indent.sub(r'\1\1\1', context.to_xml().prettify()))

    changes = context.changeset()

    if changes.needed():
        if not args.force:
            print('\nChanges to be applied:\n')
            for item in changes.items:
                print('\t - %s' % item.description)

        if not args.dry:
            if args.force or yn_choice('\nApply?', default='n'):
                changes.commit()

                print('\nChanges has been successfully applied.\n')

            else:
                print('\nNo changes has been made.\n')

    else:
        print('\nNo changes needed.\n')

    logging.info('Pywizard execution completed')
예제 #7
0
def test_create_file(tmpdir):
    """
    @type tmpdir: py._path.local.LocalPath
    """
    tmp_file1 = tmpdir.join('foo1.txt')
    tmp_file2 = tmpdir.join('foo2.txt')
    tmp_file3 = tmpdir.join('foo3.txt')

    assert not tmp_file1.exists()
    assert not tmp_file2.exists()
    assert not tmp_file3.exists()

    ctx = Context()

    ctx.apply(
        pw.file(str(tmp_file1), 'foo1')
    )

    with resource_set(ctx, name='Fooo'):

        ctx.apply(
            pw.file(str(tmp_file2), 'foo2'),
            pw.file(str(tmp_file3), 'foo3')
        )

    changes = ctx.changeset()
    assert changes.needed()

    assert not tmp_file1.exists()
    assert not tmp_file2.exists()
    assert not tmp_file3.exists()

    changes.commit()

    assert tmp_file1.exists()
    assert tmp_file2.exists()
    assert tmp_file3.exists()

    assert 'foo1' == tmp_file1.read()
    assert 'foo2' == tmp_file2.read()
    assert 'foo3' == tmp_file3.read()