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

DM-22802: Changes requested by the DRAGONS team #76

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

Conversation

timj
Copy link
Member

@timj timj commented Jun 16, 2022

This is a rebased version of #44 . It's slightly different than before because python 2 is no longer supported and the code was reformatted with black. The OrderedDict usage was dropped since dict is now ordered and I also protect the AstroData import.

Obvious things we need to think about:

  • How do we make the AstroData supported type something that a user can add without it being hard-coded? Knowing that AstroData.filename should be used seems wrong so we may need to think about whether __str__ can be used or if we have a method that a new type must support.
  • The python/lsst -> DRAGONS file name mangling.

cc/ @chris-simpson

@timj timj mentioned this pull request Jun 16, 2022
@timj
Copy link
Member Author

timj commented Jun 28, 2022

@chris-simpson / @KathleenLabrie what is your current status regarding pex_config usage? Have you made additional changes since this PR was made? Have you stopped using it?

@chris-simpson
Copy link

We're still using a fork. I've make a few more changes I'd have to dig out. Some are associated with our command-line usage (for example, having ListField accept and parse a comma-separated string).

@timj
Copy link
Member Author

timj commented Sep 27, 2023

@ktlim I've had a go at rebasing this again.

@timj timj force-pushed the tickets/DM-22802 branch from a0f71e7 to 9966481 Compare November 5, 2024 22:57
@timj timj requested a review from natelust November 5, 2024 22:58
Copy link

codecov bot commented Feb 11, 2025

❌ 2 Tests Failed:

Tests completed Failed Passed Skipped
84 2 82 9
View the top 2 failed test(s) by shortest run time
tests/test_history.py::HistoryTest::testHistory
Stack Traces | 0.003s run time
self = <test_history.HistoryTest testMethod=testHistory>

        def testHistory(self):
            b = PexTestConfig()
            b.update(a=4.0)
            pexConfigHistory.Color.colorize(False)
            output = b.formatHistory("a", writeSourceLine=False)
    
            # The history differs depending on how the tests are executed and might
            # depend on pytest internals. We therefore test the output for the
            # presence of strings that we know should be there.
    
            # For reference, this is the output from running with unittest.main()
            """a
    1.0 unittest.main()
        self.runTests()
        self.result = testRunner.run(self.test)
        test(result)
        return self.run(*args, **kwds)
        test(result)
        return self.run(*args, **kwds)
        testMethod()
        b = PexTestConfig()
        a = pexConfig.Field('Parameter A', float, default=1.0)
    4.0 unittest.main()
        self.runTests()
        self.result = testRunner.run(self.test)
        test(result)
        return self.run(*args, **kwds)
        test(result)
        return self.run(*args, **kwds)
        testMethod()
        b.update(a=4.0)"""
    
            self.assertTrue(output.startswith("a\n1.0"))
            print(output)
>           self.assertIn(
                """
        b = PexTestConfig()
        a = pexConfig.Field("Parameter A", float, default=1.0)
    4.0""",
                output,
            )
E           AssertionError: '\n    b = PexTestConfig()\n    a = pexConfig.Field("Parameter A", float, default=1.0)\n4.0' not found in 'a\n1.0 \n4.0 '

tests/test_history.py:77: AssertionError
tests/test_configurableField.py::ConfigurableFieldTest::testBasics
Stack Traces | 0.01s run time
self = <test_configurableField.ConfigurableFieldTest testMethod=testBasics>

    def testBasics(self):
        c = Config2()
        self.assertEqual(c.c1.f, 5)
        self.assertEqual(c.c2.f, 3)
    
        self.assertEqual(type(c.c1.apply()), Target1)
        self.assertEqual(c.c1.apply().f, 5)
        self.assertEqual(c.c2.apply(), 3)
    
        c.c2.retarget(Target1)
        self.assertEqual(c.c2.f, 3)
        self.assertEqual(type(c.c2.apply()), Target1)
        self.assertEqual(c.c2.apply().f, 3)
    
        c.c1.f = 2
        self.assertEqual(c.c1.f, 2)
        self.assertRaises(pexConf.FieldValidationError, setattr, c.c1, "f", 0)
    
        c.c1 = Config1(f=10)
        self.assertEqual(c.c1.f, 10)
    
        c.c1 = Config1
        self.assertEqual(c.c1.f, 5)
    
>       f = Config2(**dict(c.items()))

tests/test_configurableField.py:120: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
.../hostedtoolcache/Python/3.12.8.............../x64/lib/python3.12.../pex/config/config.py:1111: in __new__
    instance.update(__at=at, **kw)
.../hostedtoolcache/Python/3.12.8.............../x64/lib/python3.12.../pex/config/config.py:1207: in update
    field.__set__(self, value, at=at, label=label)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <lsst.pex.config.configurableField.ConfigurableField object at 0x7f1ccd455640>
instance = test_configurableField.Config2(c1={'f': 5.0}, c2={'f': 3.0})
value = {'f': 5.0}
at = [StackFrame(<string>, 1, <module>), StackFrame(<string>, 8, <module>), StackFrame(.../hostedtoolcache/Python/3.12.8/x....../hostedtoolcache/Python/3.12.8.............../x64/lib/python3.12.../site-packages/execnet/gateway_base.py, 411, _perform_spawn), ...]
label = 'update'

    def __set__(self, instance, value, at=None, label="assignment"):
        if instance._frozen:
            raise FieldValidationError(self, instance, "Cannot modify a frozen Config")
        if at is None:
            at = getCallStack()
        oldValue = self.__getOrMake(instance, at=at)
    
        if isinstance(value, ConfigurableInstance):
            oldValue.retarget(value.target, value.ConfigClass, at, label)
            oldValue.update(__at=at, __label=label, **value._storage)
        elif type(value) is oldValue._ConfigClass:
            oldValue.update(__at=at, __label=label, **value._storage)
        elif value == oldValue.ConfigClass:
            value = oldValue.ConfigClass()
            oldValue.update(__at=at, __label=label, **value._storage)
        else:
            msg = (
                f"Value {value} is of incorrect type {_typeStr(value)}. "
                f"Expected {_typeStr(oldValue.ConfigClass)}"
            )
>           raise FieldValidationError(self, instance, msg)
E           lsst.pex.config.config.FieldValidationError: ConfigurableField 'c1' (c1) failed validation: Value {'f': 5.0} is of incorrect type dict. Expected test_configurableField.Config1
E           For more information see the Field definition at:
E             File .../hostedtoolcache/Python/3.12.8.............../x64/lib/python3.12.../pex/config/configurableField.py:448 (__deepcopy__) and the Config definition at:
E             File .../pex_config/tests/test_configurableField.py:55 (<module>)

.../hostedtoolcache/Python/3.12.8.............../x64/lib/python3.12.../pex/config/configurableField.py:396: FieldValidationError

To view more test analytics, go to the Test Analytics Dashboard
📋 Got 3 mins? Take this short survey to help us improve Test Analytics.

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