File: test_conventions.py

package info (click to toggle)
rdflib 7.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 77,852 kB
  • sloc: python: 59,555; sh: 153; makefile: 83; ruby: 74; xml: 45
file content (46 lines) | stat: -rw-r--r-- 1,352 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import os.path
import pkgutil

import rdflib

"""
Test module naming conventions

modules should all be lower-case initial
"""


class TestA:
    def module_names(self, path=None, names=None, parent=""):
        skip_as_ignorably_private = ["embeddedRDF", "OpenID", "DublinCore", "RDFVOC"]

        if path is None:
            path = rdflib.__path__
        if names is None:
            names = set()

            # TODO: handle cases where len(path) is not 1
            assert (
                len(path) == 1
            ), "We're assuming the path has exactly one item in it for now"
            path = path[0]

        for importer, name, ispkg in pkgutil.iter_modules([path]):
            if ispkg:
                result = self.module_names(
                    path=os.path.join(path, name), names=names, parent=name
                )
                names.union(result)
            else:
                # namespaces are an exception to this rule
                if (
                    name != name.lower()
                    and name not in skip_as_ignorably_private
                    and parent != "namespace"
                ):
                    names.add(name)
        return names

    def test_module_names(self):
        names = self.module_names()
        assert names == set(), "module names '%s' are not lower case" % names