Closed ingrinder closed 4 years ago
Nice! I like that solution, it's very clean.
While having a look through I've noticed that our Configuration._config
's sub-dictionaries are mutable when we get them with .get()
or using dict()
on the instance (ie with your new __iter__
method)...:
Not ideal, since entries could unintentionally modify it, right? I might have a play about in a new branch changing our behaviour so that only Configuration
itself can modify any configuration using its own internal methods.
Anyway, this PR looks good now, I'll go ahead and squash-rebase 👍
Edit: Oh, okay, GH only does squash + merge. That works too 😆
As has been discussed previously, the
Configuration
singleton can cause some problems in our tests. Additionally, I've noticed that our tests aren't very... unit-test-y -- they're closer to integration tests than unit tests. Hopefully, these changes mean:Configuration
in tests.Description
archey.constants
entries
subfolder.__init__.py
to define the entry-test-specific helpers in.entry_mock
-- This creates a mock which we can pretend is an instance of an entry, so we can test instance methods by passing it in asself
. This makes it a lot easier to unit-test the instance methods without worrying about having to run an entry's__init__
to get an instance to use them.patch_clean_configuration
-- This method should be used as a decorator on entry test definitions, similar tounittest.mock.patch
, and it simply means that if we have to instantiate an entry (e.g. like the current tests, and if we need to test__init__
), its configuration is automatically mocked out with a mock specced toConfiguration
with the default Archey configuration in it.configuration
, which is a dict that is applied to the default configuration dict using theupdate_recursive
method (akin to the wayConfiguration
loads config files). This allows for way, wayyyy easier configuration setting in tests.Disk
entry test's setup has been rewritten to useentry_mock
, since I was thinking about this back then and those tests were rewritten specifically to make this a lot easier -- so that one's pretty much my vision for where we can go from here.Reason and / or context
In addition to the stuff described above, this is also a direct step to #57 where I have an implementation going that could be rebased onto this branch, which would help significantly with the number of broken tests it caused...
How has this been tested ?
There are some quite nice tests for the
entry_mock
helper method in its__init__.py
. As for the decorator, I've yet to figure out exactly how to test that... Either way, all the other tests pass, of course. (The ones currently failing are ones I've added, none of the existing tests are broken).Types of changes :
This is a bit hard to answer, these are really meta-changes being entirely about the tests.
Checklist :