cs107-lecture-examples

Example codes used during Harvard CS107 lectures
git clone https://git.0xfab.ch/cs107-lecture-examples.git
Log | Files | Refs | README | LICENSE

run_tests.sh (1165B)


      1 #!/usr/bin/env bash
      2 # File       : run_tests.sh
      3 # Description: Test suite driver script
      4 # Copyright 2022 Harvard University. All Rights Reserved.
      5 set -e
      6 
      7 # list of test cases you want to run
      8 tests=(
      9     # test_other_things_on_root_level.py
     10     subpkg_1/test_module_1.py
     11     subpkg_1/test_module_2.py
     12     # subpkg_2/test_module_3.py
     13     # subpkg_2/test_module_4.py
     14 )
     15 
     16 # Must add the module source path because we use `import cs107_package` in
     17 # our test suite.  This is necessary if you want to test in your local
     18 # development environment without properly installing the package.
     19 export PYTHONPATH="$(pwd -P)/../src":${PYTHONPATH}
     20 
     21 # decide what driver to use (depending on arguments given)
     22 if [[ $# -gt 0 && ${1} == 'coverage' ]]; then
     23     driver="${@} -m unittest"
     24 elif [[ $# -gt 0 && ${1} == 'pytest' ]]; then
     25     driver="${@}"
     26 elif [[ $# -gt 0 && ${1} == 'CI' ]]; then
     27     # Assumes the package has been installed and dependencies resolved.  This
     28     # would be the situation for a customer.  Uses `pytest` for testing.
     29     shift
     30     unset PYTHONPATH
     31     driver="pytest ${@}"
     32 else
     33     driver="python3 ${@} -m unittest"
     34 fi
     35 
     36 # run the tests
     37 ${driver} ${tests[@]}