コード例 #1
0
ファイル: test_factory.py プロジェクト: glevava/pyessv
def test_create():
    """Test creating an authority.

    """
    def _test(func, typeof):
        """Inner test.

        """
        node = func()
        tu.assert_object(node, typeof)
        assert node == load(node.namespace)


    for factory, typeof in (
        (tu.create_authority, LIB.Authority),
        (tu.create_scope, LIB.Scope),
        (tu.create_collection_01, LIB.Collection),
        (tu.create_collection_02, LIB.Collection),
        (tu.create_collection_03, LIB.Collection),
        (tu.create_term_01, LIB.Term),
        (tu.create_term_02, LIB.Term),
        (tu.create_term_03, LIB.Term)
        ):
        tu.init(_test, 'create --> {}'.format(factory.__name__[7:]))
        yield _test, factory, typeof
コード例 #2
0
ファイル: test_codecs.py プロジェクト: glevava/pyessv
def test_encode():
    """pyessv-tests: encode.

    """
    def _test(node, encoding):
        """Inner test.

        """
        representation = encode(node, encoding)
        assert isinstance(representation,
                          _ENCODING_REPRESENTATION_TYPE[encoding])
        decoded = decode(representation, encoding)
        assert isinstance(decoded, type(node))
        for field in STANDARD_NODE_FIELDS:
            assert getattr(decoded, field) == getattr(node, field)

    for node_factory in (tu.create_authority, tu.create_scope,
                         tu.create_collection_01, tu.create_collection_02,
                         tu.create_collection_03, tu.create_term_01,
                         tu.create_term_02, tu.create_term_03):
        node = node_factory()
        for encoding in ENCODING_SET:
            desc = 'codecs: {} --> {}'.format(node_factory.__name__[7:],
                                              encoding)
            tu.init(_test, desc)
            yield _test, node, encoding
コード例 #3
0
def test_parse_identifiers():
    """pyessv-tests: parsing: identifiers

    """
    def positive_test(parser, project, identifier):
        parser(project, identifier)

    @nose.tools.raises(LIB.TemplateParsingError)
    def negative_test(parser, project, identifier):
        parser(project, identifier)

    # Iterate identifiers & perform +ve / -ve tests:
    for project, parser, seperator, identifiers in _CONFIG:
        assert inspect.isfunction(parser)
        for identifier in identifiers:
            # ... +ve test:
            desc = 'identifier parsing test (+ve) --> {} :: {}'.format(
                project, identifier)
            tu.init(positive_test, desc)
            yield positive_test, parser, project, identifier

            # ... -ve tests:
            for invalid_identifier in _get_invalid_identifiers(
                    identifier, seperator):
                desc = 'identifier parsing test (-ve) --> {} :: {}'.format(
                    project, invalid_identifier)
                tu.init(negative_test, desc)
                yield negative_test, parser, project, invalid_identifier
コード例 #4
0
def test_iterability():
    """Test iterability of domain model.

    """
    def _test(node, keys):
        """Inner test.

        """
        assert iter(node)
        assert len(node) == len(keys)
        for key in keys:
            assert key in node
            assert node[key] is not None

    for node_factory, keys in (
        (tu.create_authority, [tum.SCOPE_NAME]),
        (tu.create_scope, [
            tum.COLLECTION_01_NAME, tum.COLLECTION_02_NAME,
            tum.COLLECTION_03_NAME
        ]),
        (tu.create_collection_01, [tum.TERM_01_NAME]),
        (tu.create_collection_02, [tum.TERM_02_NAME]),
        (tu.create_collection_03, [tum.TERM_03_NAME]),
    ):
        desc = 'iterate --> {}'.format(node_factory.__name__[7:])
        tu.init(_test, desc)
        yield _test, node_factory(), keys
コード例 #5
0
def test_parse_name():
    """Test parsing of names at various levels.

    """
    for typekey, canonical_name, alternative_names, parent in _INPUTS:
        for alternative_name in alternative_names:
            for name, expected, strictness in _get_config(
                    canonical_name, alternative_name):
                desc = 'parse --> {}: {} [strictness={}]'.format(
                    typekey, name, strictness)
                tu.init(_test_parse_name, desc)
                yield _test_parse_name, typekey, name, expected, strictness, parent
コード例 #6
0
ファイル: _test_governance.py プロジェクト: glevava/pyessv
def test():
    """pyessv-tests: governance: accept term

    """

    for func, status, desc in (
        (pyessv.accept, pyessv.GOVERNANCE_STATUS_ACCEPTED, 'accept'),
            # (pyessv.reject, pyessv.GOVERNANCE_STATUS_REJECTED, 'reject'),
            # (pyessv.reset, pyessv.GOVERNANCE_STATUS_PENDING, 'reset'),
            # (pyessv.deprecate, pyessv.GOVERNANCE_STATUS_DEPRECATED, 'deprecate')
    ):
        tu.init(_test, 'governance', '{} term'.format(desc))
        yield _test, func, status
コード例 #7
0
ファイル: test_validation.py プロジェクト: glevava/pyessv
def test_node():
    """Tests node validation.

    """
    for node_factory in (tu.create_authority, tu.create_scope,
                         tu.create_collection_01, tu.create_collection_02,
                         tu.create_collection_03, tu.create_term_01,
                         tu.create_term_02, tu.create_term_03):
        node = node_factory()
        for attr, invalid in _TEST_INFO[type(node)]:
            tu.init(
                _test_node_attr,
                'validate --> {}: {}'.format(node_factory.__name__[7:], attr))
            yield _test_node_attr, node, attr, invalid
コード例 #8
0
def test():
    """pyessv-tests: governance: accept term

    """


    for func, status, desc in (
        (pyessv.accept, pyessv.GOVERNANCE_STATUS_ACCEPTED, "accept"),
        # (pyessv.reject, pyessv.GOVERNANCE_STATUS_REJECTED, "reject"),
        # (pyessv.reset, pyessv.GOVERNANCE_STATUS_PENDING, "reset"),
        # (pyessv.deprecate, pyessv.GOVERNANCE_STATUS_DEPRECATED, "deprecate")
        ):
        tu.init(_test, 'governance', "{} term".format(desc))
        yield _test, func, status
コード例 #9
0
def test_expressions():
    """pyessv-tests: expression: valid.

    """
    def _do_positive_test(template, parser):
        parser.parse(_VALID[template])

    @nose.tools.raises(ValueError)
    def _do_negative_test(template, parser):
        parser.parse(_INVALID[template])

    _setup()
    for template in _TEMPLATES:
        tu.init(_do_positive_test,
                'parse expression (+ve) :: {}'.format(template))
        yield _do_positive_test, template, _PARSERS[template]
        tu.init(_do_negative_test,
                'parse expression (-ve) :: {}'.format(template))
        yield _do_negative_test, template, _PARSERS[template]
コード例 #10
0
def test_create():
    """Test creating a term.

    """
    @nose.with_setup(tu.setup, tu.teardown)
    def test_create_01():
        """Create term."""
        term = tu.create_term()
        tu.assert_object(term, pyessv.Term)
        tu.assert_int(pyessv.get_count(), 0)


    @nose.with_setup(_setup, tu.teardown)
    def test_create_02():
        """Create & save term."""
        term = pyessv.get_term(tu.TERM_DOMAIN, tu.TERM_SUBDOMAIN, tu.TERM_KIND, tu.TERM_NAME)
        tu.assert_object(term, pyessv.Term)

    for test in (test_create_01, test_create_02):
        tu.init(test, 'authoring', inspect.getdoc(test))
        yield test
コード例 #11
0
def test_library_exports():
    """Test set of exports exposed by library.

    """
    def _test_member(member, member_type):
        """Test that library exposes the named member.

        """
        assertor = getattr(tu, 'assert_has_{}'.format(member_type))
        assertor(LIB, member)

    for members, member_type, in (
        (_CLASSES, 'class'),
        (_CONSTANTS, 'constant'),
        (_EXCEPTIONS, 'exception'),
        (_FUNCS, 'function'),
    ):
        for member in sorted(members):
            desc = 'library exposes {} --> {}'.format(member_type, member)
            tu.init(_test_member, desc)
            yield _test_member, member, member_type
コード例 #12
0
def test_update():
    """Test updating a term.

    """
    def _update_create_date(term):
        """Update term create date."""
        term.create_date = tu.get_date()

    def _update_description(term):
        """Update term description."""
        term.description = tu.get_uuid()

    def _update_domain(term):
        """Update term domain."""
        term.domain = tu.get_unicode(existing=term.domain)

    def _update_id(term):
        """Update term id."""
        term.idx = tu.get_int(existing=term.idx)

    def _update_kind(term):
        """Update term kind."""
        term.kind = tu.get_unicode(existing=term.kind)

    def _update_name(term):
        """Update term name."""
        term.name = tu.get_unicode(existing=term.name)

    def _update_status(term):
        """Update term status."""
        term.status = tu.get_unicode(existing=term.status)

    def _update_subdomain(term):
        """Update term subdomain."""
        term.subdomain = tu.get_unicode(existing=term.subdomain)

    def _update_uid(term):
        """Update term uid."""
        term.uid = tu.get_uuid()

    def _assert(term):
        """Asserts an update."""
        count = pyessv.get_count()
        pyessv.save(term)
        tu.assert_int(pyessv.get_count(), count)
        term_ = pyessv.get_term(term.domain, term.subdomain, term.kind, term.name)
        tu.assert_terms(term, term_)

    @nose.with_setup(_setup, tu.teardown)
    def _test(update_callback):
        """Performs update test."""
        term = tu.get_term()
        update_callback(term)
        _assert(term)

    for func  in (
        _update_create_date,
        _update_description,
        _update_domain,
        _update_id,
        _update_kind,
        _update_name,
        _update_status,
        _update_subdomain,
        _update_uid
        ):
        tu.init(_test, 'authoring', inspect.getdoc(func))
        yield _test, func