Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework "context" interface #62

Open
wants to merge 8 commits into
base: lenient_setting_values_BASIS
Choose a base branch
from

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

@@ -499,7 +514,7 @@ def test_nop(self):
def test_active_str(self):
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

@@ -513,7 +528,7 @@ def client():
pass

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


def test_args_str(self):
client = "client"
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

@@ -562,30 +579,168 @@ def service2():
client = "client"
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
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.

1 participant