tree: e113e57fc61049025a753ede638b8218fa21306f [path history] [tgz]
  1. fakegit/
  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. config_types_test.py
  9. doc_test.py
  10. errors_test.py
  11. fake_recipe_deps.py
  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. python3.py
  21. README.md
  22. recipe_util_test.py
  23. run_test.py
  24. simulation_test.py
  25. stdlib_test.py
  26. step_runner_test.py
  27. stream_test.py
  28. test_env.py
  29. test_test.py
  30. util_test.py
  31. warn_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.

You should be able to run tests via ./unittests/foo_test.py.

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.