Skip to content

Conversation

@pp-mo
Copy link
Owner

@pp-mo pp-mo commented Jul 1, 2020

Modified to allow settings updates to accommodate non-binary settings values, and making the service names valid as keywords.
This means you can create an (inner) context in which a existing binary-type service is turned "off".
It also supports client value settings with "service_name=control_value"

So, this replaces context(*services, active=client) with context(client, services)
But it also allows :

  • legacy arg form services (list of callable or name) still works. Now equivalent to {svc:True for svc in services}
  • but services can now also be assigned a 'setting value', rather than just "turned on"
  • **kwargs form allows e.g. context(svc1=True, svc2=True) as alternative to context(services=(svc1, svc2)
    • plus of course, the assignment values could now be ~anything (?hashable?)
  • "services" arg can be iterable or dict, so context(client, **services_dict) is same as context(client, services_dict)

Own review below illustrates the key changes by highlighting the modified context usages in tests/unit/common/lenient/test_Lenient.py

TODO: probably more tests for the new stuff

BIG NOTE:
For this, I have re-implemented the basic settings in the Lenient.__dict__, replacing tuples of names with a set of (key, value) pairs.
However, I only did this because I wasn't clear why a tuple is used at present
-- whether for efficiency or so it is hashable.
-- the existing comments do make clear that order is not supposed to matter.
If these factors are not essential, it would still be much nicer to just use dictionaries.
This was all a bit of a pain with the tests, because they all work via implementation details (checking the dict) instead of some public access 😓
But it could be changed again if needed, without too much grief ... Really. Dictionaries would definitely be more natural.

Copy link
Owner Author

@pp-mo pp-mo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These lines point up the changed syntax new capabilites in the 'context' call

client = "client"
pre = self.copy()
with self.lenient.context(active=client):
with self.lenient.context(client):
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NOTE: syntax change


pre = self.copy()
with self.lenient.context(active=client):
with self.lenient.context(client):
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NOTE: syntax change

services = ("service1", "service2")
pre = self.copy()
with self.lenient.context(*services, active=client):
with self.lenient.context(client, services):
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NOTE: syntax change

services = (service1, service2)
pre = self.copy()
with self.lenient.context(*services, active=client):
with self.lenient.context(client, services):
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NOTE: syntax change

client = "client"
services = ("service1", "service2")
pre = self.copy()
with self.lenient.context(client, service1=True, service2=True):
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NOTE: new syntax / capability

# Note: use dict for the keywords, as qualnames are really long !
settings = {qualname1: True, qualname2: False}

with self.lenient.context("client", **settings):
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NOTE: new syntax / capability


client_settings = dict(svc1=True, svc2=False, svc3="seven", svc4=-5.3)

@lenient_client(services=client_settings)
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NOTE: new syntax / capability

def test_setting_modify(self):
pre = self.copy()

with self.lenient.context("client", set1=1, set2=2):
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NOTE: new syntax / capability

@pp-mo pp-mo changed the title Lenient setting values Rework "context" interface Jul 1, 2020
@pp-mo pp-mo closed this Feb 21, 2025
@pp-mo pp-mo deleted the lenient_setting_values branch November 29, 2025 11:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants