Skip to content

Conversation

albu-diku
Copy link
Contributor

As of this commit fake configuration instances are populated with the same properties, including the same default values, as a genuine Configuration object instance. This ensures that logic under test is going to behave far more as it would with a real configuration object which means a great deal more assurance in the tests.

Achieve this by using the dictionary of defaults that was split out previously to initialize the FakeConfiguration which itself is now a SimpleNamespace. Making it a namespace ensures that attribute lookup, something that normal Configuration objects support, work correctly but in addition forces the attributes to be set "up front". This keeps us honest in the properties we expose.

Since a FakeConfiguration needs to track the real Configuration we also prevent the addition of attributes that not keys of a real configuration. Unfortunarely it seems that a lot of properties are set dynamically as part of loading a configuration, but laythe first steps to a canonical configuration object by making a couple of properties used by existing tests static; existing defaults are re-used to avoid functional change.

@albu-diku albu-diku force-pushed the test/enhance-fake-configuration branch from 40c209e to b451cff Compare April 9, 2025 15:44
@albu-diku albu-diku force-pushed the test/enhance-fake-configuration branch from b451cff to 219c4b4 Compare July 23, 2025 14:09
@albu-diku albu-diku force-pushed the test/enhance-fake-configuration branch 4 times, most recently from 8819c98 to 8bb1fc6 Compare September 2, 2025 14:51
As of this commit fake configuration instances are populated with
the same properties, including the same default values, as a genuine
Configuration object instance. This ensures that logic under test is
going to behave far more as it would with a real configuration object
which means a great deal more assurance in the tests.

Achieve this by using the dictionary of defaults that was split out
previously to initialize the FakeConfiguration which itself is now
a SimpleNamespace. Making it a namespace ensures that attribute lookup,
something that normal Configuration objects support, work correctly but
in addition forces the attributes to be set "up front". This keeps us
honest in the properties we expose.

Since a FakeConfiguration needs to track the real Configuration we also
prevent the addition of attributes that not keys of a real configuration.
Unfortunarely it seems that a lot of properties are set dynamically as
part of loading a configuration, but lay the first steps to a canonical
configuration object by making a couple of properties used by existing
tests static; existing defaults are re-used to avoid functional change.
@albu-diku albu-diku force-pushed the test/enhance-fake-configuration branch from 8bb1fc6 to 403e09e Compare September 3, 2025 10:03
@jonasbardino jonasbardino requested review from a team and removed request for jonasbardino September 3, 2025 15:26
@jonasbardino
Copy link
Contributor

Reassigned the review to all ops to avoid unnecessary bottlenecks.


'arc_clusters': [],

'cloud_services': [],
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder why cloud_services but not the similar jupyter_services needs to be added here ... if I understood the comment about us 'keeping honest' correctly shouldn't the lack of the latter raise a flag? 🤔

'expire_peer': 600,
'language': ['English'],
'user_interface': ['V2', 'V3'],
'new_user_default_ui': 'V2',
Copy link
Contributor

@jonasbardino jonasbardino Oct 13, 2025

Choose a reason for hiding this comment

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

This needs careful testing as we don't want to downgrade running instances to the deprecated V2. On the other hand we need to preserve V2 on GDP instances like SIF for the time being.

return peers_dict

@staticmethod
def as_dict(thing):
Copy link
Contributor

Choose a reason for hiding this comment

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

This one would like a docstring explaining that it filters out internal attributes.
Minor: consider renaming thing to obj if it's always called on objects.



def _generate_namespace_kwargs():
d = dict(_CONFIGURATION_DEFAULTS)
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor: please try hard to avoid single letter names for anything but simple iterator variables as they are horrible to track down across code sections later.

"""

unknown_keys = set(d.keys()) - set(_CONFIGURATION_ARGUMENTS)
assert len(unknown_keys) == 0, \
Copy link
Contributor

Choose a reason for hiding this comment

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

PEP8 recommends to instead rely on the fact that empty lists are logically False as in assert not unknown_keys, ... .
(https://peps.python.org/pep-0008/#programming-recommendations

self.logger = FakeLogger()

@staticmethod
def as_dict(thing):
Copy link
Contributor

Choose a reason for hiding this comment

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

see above

configuration_defaults_keys = set(_CONFIGURATION_DEFAULTS.keys())
mismatched = _CONFIGURATION_ARGUMENTS - configuration_defaults_keys

self.assertEqual(len(mismatched), 0,
Copy link
Contributor

Choose a reason for hiding this comment

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

This one may want to go with the same PEP8 recommendation as above.

# --- BEGIN_HEADER ---
#
# test_tests_support_configsupp - unit test of the corresponding tests module
# Copyright (C) 2003-2024 The MiG Project by the Science HPC Center at UCPH
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor: 2024 -> 2025

_CONFIGURATION_NOFORWARD_KEYS, _without_noforward_keys


class MigSharedInstall_FakeConfiguration(MigTestCase):
Copy link
Contributor

Choose a reason for hiding this comment

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

Classes always want docstrings... you can grab the generic one form other tests.

Copy link
Contributor

@jonasbardino jonasbardino left a comment

Choose a reason for hiding this comment

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

Looks good, but there are some mostly smaller issues as outlined in comments. I think the most important thing here is that it needs thorough testing on at one of our test sites to make sure configuration.py changes don't break user pages or services.

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