tree: 792dc3c91c480099da92a60a2a6fcff101c6d709 [path history] [tgz]
  1. README.md
  2. analyze_test.py
  3. autoroll_test.py
  4. bundle_test.py
  5. checker_test.py
  6. commit_list_test.py
  7. config_test.py
  8. doc_test.py
  9. errors_test.py
  10. fake_recipe_deps.py
  11. fakegit/
  12. fetch_test.py
  13. gitattr_checker_test.py
  14. manual_roll_test.py
  15. mock_recipe_deps.py
  16. override_test.py
  17. post_process_test.py
  18. properties_test.py
  19. proto_test.py
  20. run_test.py
  21. simulation_test.py
  22. stdlib_test.py
  23. step_runner_test.py
  24. stream_test.py
  25. test_env.py
  26. test_test.py
  27. util_test.py
unittests/README.md

Recipe Engine Unit Tests

This directory contains all the ‘unit’ tests for the recipe engine. In reality this folder contains a mix of unit and integration tests. All of the tests in here use the test_env module (in this directory). This module provides a base unittest.TestCase class with some helpers.

The main helpers are FakeRecipeDeps and MockRecipeDeps.

test_env.RecipeEngineUnitTest

This is the base unittest class for all tests in this directory. It has some nice common functionality:

  • maxDiff is always set to None (meaning that large test failures will always show the full diff).
  • If you pass ‘-v’ on the command line, it will enable verbose logging.
  • If you pass ‘--leak’ on the command line, it will leak all temporary files and directories from tests which fail. This can be useful for debugging the state of a test.
  • tempfile and tempdir functions for easy auto-cleaned temporary stuff.
  • assertDictEqual and assertListEqual have been updated to strip out all the unicode objects from their arguments (replacing them with str), which means that the diffs from test failures are actually helpful.

MockRecipeDeps

This is a lightweight ‘mocked’ version of recipe_deps.RecipeDeps. It contains only in-memory constructs which imitate the APIs exposed by the real RecipeDeps.

Currently this is pretty bare-bones and only covers the needs of e.g. the tests for the analyze command (and friends). If you're writing new unit tests, please opt to extend this mocked version and use it directly.

FakeRecipeDeps

This is a very heavyweight ‘fake’ framework for writing recipe integration tests. It manipulates the state of real git repos on disk with the following layout:

 tmpdir/
   main/           # the main 'entrypoint' repo for the FakeRecipeDeps.
     recipes.py    # you'll usually call this with the recipes_py function
     .recipe_deps/ # contains (local) clones of all of main's dependencies
       depname/
     infra/config/recipes.cfg
     ....
   sources/
     depname/   # the "upstream repo" location

You may notice that there are two copies of depname. The one in sources is analogous to the ‘remote repository’ (i.e. the one on googlesource.com), whereas the one in main/.recipe_deps is the ‘local clone’ of a real recipe repo.

Of course, all of these repos are local and very small. This testing setup allows testing even relatively complex features like autoroll, which require fetching the ‘remote’ changes into the ‘local’ .recipe_deps.