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

WIP: DON'T MERGE: Ultimate test setup #1899

Closed
wants to merge 49 commits into from

Conversation

bpoldrack
Copy link
Member

@bpoldrack bpoldrack commented Oct 13, 2017

You may look, but don't touch!

  • Closes Strange testrepo setup #1826
  • find solution for Test must not use existing user configuration #1890
  • Implement TestRepo base class
  • Implement basic Item subclasses
  • Implement TestRepo's, ItemRepo's and ItemFile's assert_intact method (mostly done)
  • resemble all existing testrepos (basically done) by defining corresponding subclasses
  • Implement new with_testrepos
  • Implement transition helper to let tests use new repos without adapting them
  • Have an extensive check on definitions of subclasses of TestRepo with meaningful messages to ease doing so for everybody
  • Provide new test helpers to easily use new powers within tests (see "TODO: - use the power!" in testrepos.utils.py
  • Fully adapt at least some actual tests (probably GitRepo/AnnexRepo) to show off
  • delay implementation of probably required ItemCommands and some properties until they are actually required. Do this while adapting tests and creating additional TestRepos. It's important to make use of what's already available ASAP.
  • Lazy creation (currently we pre-create ALL of them although the test might need just a single one of them)

Provide new concept for running unit tests in different setups.

short overview of the goals
New TestRepo subclasses are capable of setting up pretty much everything you can think of, including untracked files, independent repos (or even an entire forrest of hierarchies at once), staged and unstaged modifications, ... everything. This used to be not possible, since we relied on them being cloneable repositories.
They are delivered by with_testrepos as an object that contains all information about the SHOULD-BE state of the entire setup. Tests now can base their assertions on properties of the TestRepo. Thereby it's easy to write tests that can actually run on anything being thrown at them. They don't need (hard-)coded assumptions about the tesrepos that were known to the developer when writing the test. And they also don't need to read properties from FS, which basically means to make the IS state the SHOULD-BE state.
They provide full automatic integrity testing. No need for a test developer to each time think about, what could possibly have changed and come up with a complete set of assertions to make sure nothing has changed.
This also means there's now the possibility to just define intended changes and automatically run a full set of assertions making sure that those changes and those changes ONLY actually happened. Again: No need by the developer to always come up with the necessary assertions to make that sure.
If used via new with_testreposdecorator it is ensured that testrepos can't be left messed up by tests and still being used by other tests, too. However, if the test requests a "read-only" instance of a TestRepo they will get a persistent one, that isn't always recreated and used by others, too. Those persistent ones will check themselves after such a test (and raise of course if check failed) and will be automatically recreated from scratch for the next test that wants to use them.
Finally, the definition of new test setups is pretty easy, I think. To help with that even further there are supposed to be extensive checks on the definitions, generating pretty precise messages, that are telling what's wrong with the definition.

Implicit feature: There is basically no need for additional unit tests on TestRepo and the subclasses of Item. They implicitly test themselves as soon as they are used in a subclass of TestRepo. This subclass just needs to be instantiated. The "object consistency" part of assert_intact (which is autmatically and recursively called for all item of a TestRepo) does that. Whatever unit test you can come up with that actually contains assertions that are not tested anyway, implies that either those assertions should be added in a general way in the appropriate assert_intact method or it's about a not yet tested setup, meaning you should simply define a new TestRepo instead. The latter will automatically test the code in testrepo module against that situation and furthermore this also leads to us testing DATALAD against that untested situation!

- Implement ItemCommand, ItemCommit
- Implement first test repos: BasicGit, BasicMixed
- several little fixes and changes
- add TODOs
- Fix addurl
- BasicMixed now works too and is the same as old BasicAnnexTestRepo
RF: introduce helper fucntions for command calls
…to ItemFile, let TestRepo check for independent repos
ENH: represent remotes and branches
ENH: Implement physical assertions for ItemRepo
TST: Test recursive execution of everything for TestRepo class and BasicGit respectively
Copy link
Member

@yarikoptic yarikoptic 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!



@auto_repr
class ItemInfoFile(ItemFile):
Copy link
Member

Choose a reason for hiding this comment

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

invaluable concern: use "Item" as a suffix (if at all) not as a prefix, to stay inline with other places (AnnexRepo, etc)

Copy link
Member

Choose a reason for hiding this comment

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

here is an example for attrs

>>> import attr
>>> @attr.s
... class C(object):
...     x = attr.ib(default=42)
...     y = attr.ib(default=attr.Factory(list))

so we could do just that from testrepos import items, and use items.File, or if really valuing our bytes, from testrepos import items as it; it.File


if self.branches:
assert self.commits
# TODO: Not necessarily vice versa? Could be just detached HEAD, I guess
Copy link
Member

Choose a reason for hiding this comment

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

make sure that it also asserts on the states of the branches

although git-annex branch might be tricky, since many git-annex operations just adjust the timestamp within the log of the git-annex although no content being dropped etc. E.g. 'annex fsck' would change git-annex branch.

@yarikoptic
Copy link
Member

the failing test in the env with lots of debugging etc

======================================================================

ERROR: datalad.tests.testrepos.tests.test_repos.test_BasicMixed_instantiation

----------------------------------------------------------------------

Traceback (most recent call last):

  File "/home/travis/virtualenv/python2.7.13/lib/python2.7/site-packages/nose/case.py", line 197, in runTest

    self.test(*self.arg)

  File "/home/travis/build/datalad/datalad/datalad/tests/utils.py", line 593, in newfunc

    return t(*(arg + (filename,)), **kw)

  File "/home/travis/build/datalad/datalad/datalad/tests/testrepos/tests/test_repos.py", line 108, in test_BasicMixed_instantiation

    tr = BasicMixed(path)

  File "/home/travis/build/datalad/datalad/datalad/tests/testrepos/repos.py", line 343, in __init__

    self.assert_intact()

  File "/home/travis/build/datalad/datalad/datalad/tests/testrepos/repos.py", line 396, in assert_intact

    [item.assert_intact() for item in self._roots]

  File "/home/travis/build/datalad/datalad/datalad/tests/testrepos/items.py", line 592, in assert_intact

    for line in out.splitlines()]

IndexError: list index out of range

…from the one used for instantiation

BF: Use OrderedDict for TestRepo's items
ENH: Allow for other TestRepos to be used within definitions like Items
ENH/TST: Add a rudimentary MixedSubmodules TestRepo to test enhancement - MixedSubmodules itself remains TODO!
@codecov-io
Copy link

codecov-io commented Oct 16, 2017

Codecov Report

Merging #1899 into master will increase coverage by 4.01%.
The diff coverage is 89.28%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1899      +/-   ##
==========================================
+ Coverage   85.72%   89.74%   +4.01%     
==========================================
  Files         265      287      +22     
  Lines       31598    32936    +1338     
==========================================
+ Hits        27088    29558    +2470     
+ Misses       4510     3378    -1132
Impacted Files Coverage Δ
datalad/tests/testrepos/items.py 83.2% <ø> (ø)
datalad/cmdline/main.py 78.98% <ø> (-2.31%) ⬇️
datalad/tests/testrepos/__init__.py 100% <100%> (ø)
datalad/tests/testrepos/tests/__init__.py 100% <100%> (ø)
datalad/tests/testrepos/tests/test_repos.py 100% <100%> (ø)
datalad/tests/testrepos/exc.py 62.5% <62.5%> (ø)
datalad/tests/testrepos/repos.py 85.06% <85.06%> (ø)
datalad/tests/testrepos/helpers.py 86.2% <86.2%> (ø)
datalad/tests/testrepos/tests/test_utils.py 98.46% <98.46%> (ø)
datalad/tests/testrepos/utils.py 98.48% <98.48%> (ø)
... and 98 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2708c1b...e07b31f. Read the comment docs.

…_class__ inplace instead.

TST: Use several BasicMixed in MixedSubmodules to test enahncement
BF: use relative paths for submodule-add
ENH: Have MixedSubmodules almost resemble old SubmoduleDataset
Add(and remove) some TODOs plus minor fixes
BF: Let ItemRepo know if datalad special remote was enabled
ENH: Lazily provide persistent TestRepos and files
ENH: Use cloning in MixedSubmodules to fully resemble old SubmoduleDataset
RF: Move code into a helper function
…n additional items that were instantiated during creation of that item
RF: Something to clone from needs to be an ItemRepo
ENH: Start accounting for non-initialized submodules
TST: Last 'old' TestRepo almost done
BF: When reading remotes from config, do the right thing if we are in a submodule with .git file
ENH: Get branch (and commit) information from cloning source
RF: Make annex-init a method of ItemRepo to be called by its create() as well as when initializing a submodule
ENH: Add command 'submodule update'
ENH: Finish 'old' TestRepo with nested submodules
BF: When calling super().__init__ for items, pass 'check_definition'
We need to reference persistent ones in other TestRepos using them. Therefore the laziness wasn't real, since the simple import of repos.py instantiated all of them, that were referenced this way. Now, the 'src' parameter of an ItemRepo isn't required to be an ItemRepo anymore, but is allowed to be a callable.

get_persistent_testrepo(cls, attr) now delivers a callable, that will create the instance if called and it wasn't created yet. In addition this function now allows to not only return the instance of 'cls', but its attribute 'attr' instead.
@bpoldrack bpoldrack mentioned this pull request Oct 24, 2017
…ble types in PY3 and we don'T actually need a set here
V6
BF: Clean up failed attempt to create a particular persistent TestRepo
instance
…pt decorators and tests accordingly.

This is needed, since we have TestRepos (MixedSubmodulesOld*), that are
invalid in V6 right from the beginning. So it's not about skipping the
actual tests, that are supposed to operate on several TestRepos. This
might be somewhat confusing - don't throw away this approach easily!
@bpoldrack
Copy link
Member Author

Don't see myself finishing this anytime soon. Thus closing.

@bpoldrack bpoldrack closed this Jul 16, 2019
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.

Strange testrepo setup
3 participants