• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

zopefoundation / zope.app.appsetup / 15518254055

25 Apr 2025 06:42AM UTC coverage: 87.007% (-0.3%) from 87.302%
15518254055

push

github

web-flow
Update Python version support. (#12)

* Drop support for Python 3.7, 3.8.

* Add support for Python 3.12, 3.13.

55 of 78 branches covered (70.51%)

Branch coverage included in aggregate %.

0 of 2 new or added lines in 2 files covered. (0.0%)

2 existing lines in 2 files now uncovered.

474 of 530 relevant lines covered (89.43%)

0.89 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

95.83
/src/zope/app/appsetup/product.py
1
"""Access to product-specific configuration."""
2
import os.path
1✔
3

4
import ZConfig
1✔
5

6

7
_configs = {}
1✔
8
_schema = None
1✔
9

10
try:
1✔
11
    import zope.testing.cleanup
1✔
NEW
12
except ModuleNotFoundError:
×
UNCOV
13
    pass
×
14
else:
15
    zope.testing.cleanup.addCleanUp(_configs.clear)
1✔
16

17

18
def getProductConfiguration(name):
1✔
19
    """Return the product configuration for product `name`.
20

21
    If there is no configuration for `name`, None is returned.
22

23
    """
24
    return _configs.get(name)
1✔
25

26

27
def setProductConfigurations(configs):
1✔
28
    """Initialize product configuration from ZConfig data."""
29
    pconfigs = {}
1✔
30
    for pconfig in configs:
1✔
31
        pconfigs[pconfig.getSectionName()] = pconfig.mapping
1✔
32
    _configs.clear()
1✔
33
    _configs.update(pconfigs)
1✔
34

35

36
def setProductConfiguration(name, mapping):
1✔
37
    """Set the configuration for a single product."""
38
    if mapping is None:
1✔
39
        if name in _configs:
1✔
40
            del _configs[name]
1✔
41
    else:
42
        _configs[name] = mapping
1✔
43

44

45
def saveConfiguration():
1✔
46
    """Retrieve a shallow copy of the configuration state."""
47
    return _configs.copy()
1✔
48

49

50
def restoreConfiguration(state):
1✔
51
    """Restore the configuration state based on a state value."""
52
    _configs.clear()
1✔
53
    _configs.update(state)
1✔
54

55

56
def loadConfiguration(file, url=None):
1✔
57
    global _schema
58
    if _schema is None:
1✔
59
        here = os.path.dirname(os.path.abspath(__file__))
1✔
60
        path = os.path.join(here, "schema", "productconfig.xml")
1✔
61
        _schema = ZConfig.loadSchema(path)
1✔
62
    data, handlers = ZConfig.loadConfigFile(_schema, file, url=url)
1✔
63
    return {sect.getSectionName(): sect.mapping
1✔
64
            for sect in data.product_config}
65

66

67
class FauxConfiguration:
1✔
68
    """Configuration object that can be use from tests.
69

70
    An instance is of this is similar to a <product-config> section from a
71
    zope.conf file in all the ways this module cares about.
72

73
    """
74

75
    def __init__(self, name, mapping):
1✔
76
        self.name = name
1✔
77
        self.mapping = dict(mapping)
1✔
78

79
    def getSectionName(self):
1✔
80
        return self.name
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc