Skip to content

IPP-DEV-01-001: Install Python and Clone the Repos #40

@labbenchstudios

Description

@labbenchstudios

Description

  • Set up your IPP dev environment using the ipp-exercise-components repository or your related GitHub Classroom repository.
    • NOTE: If you're a student of Intro to Programming in Python, during our first class meeting of the semester we'll discuss whether to clone the repo directly or use GitHub Classroom.

Review the README

  • Please see README.md for further information on, and use of, this content.
  • License for embedded documentation and source codes: IPP-DOC-LIC

Estimated effort may vary greatly

  • The estimated level of effort for this exercise shown in the 'Estimate' section below is a very rough approximation. The actual level of effort may vary greatly depending on your development and test environment, experience with the requisite technologies, and many other factors.

Actions

Step 1: Make Sure Your System is Setup for Python and This Course

Step 2: REMINDER: Make Sure PYTHONPATH is Set Correctly

Whether running Python tests within your IDE or from the command line, you must set the PYTHONPATH environment variable in every execution environment (e.g., every terminal you launch) when attempting to run any of your scripts and their tests or the IPP test app from the command line. The IPP source and test paths will be as follows:

  • {your IPP source code path}
  • {your IPP source code path}/tests

NOTE: As a reminder, your IPP source code path (where you cloned the ipp-exercise-components source tree) will be referred to as IPP_HOME. Your IPP documentation code path (where you cloned the ipp-exercise-docs repository) will be referred to as IPP_DOCS.

PYTHONPATH EXAMPLE: If you're using WSL on Windows 11, and you've cloned the IPP source repo to your 'C' drive using path /mnt/c/ipp/ipp-exercise-components, you can set your PYTHONPATH in the terminal using the following command:

export PYTHONPATH=/mnt/c/ipp/ipp-exercise-components:/mnt/c/ipp/ipp-exercise-components/tests

VIRTUAL ENV EXAMPLE: If you're using WSL on Windows 11, and you've created a virtual environment in the path /mnt/c/ipp/ipp-exercise-components/ipp-venv, you can start your virtual environment using the following:

source /mnt/c/ipp/ipp-exercise-components/ipp-venv/bin/activate

Step 3: Test Your Environment

Run the test IPP application (ipp/app/IppTestApp.py):

  • Start your virtualenv
  • Change your working directory to IPP_HOME (in the example below, IPP_HOME is /mnt/c/ipp/ipp-exercise-components)
  • Make sure your PYTHONPATH is set as indicated above
  • Run the test app
    • NOTE: BE SURE TO USE THE CORRECT PATH FOR YOUR ENVIRONMENT!
source /mnt/c/ipp/ipp-exercise-components/ipp-venv/bin/activate
cd /mnt/c/ipp/ipp-exercise-components
export PYTHONPATH=/mnt/c/ipp/ipp-exercise-components:/mnt/c/ipp/ipp-exercise-components/tests
python ipp/app/TestApp.py

Alternatively, you may want to save a step and simply add the export PYTHONPATH={path] to the end of the activate script within your virtual environment. This way it always gets set when you run the virtual environment.

  • Caveat: If you have other Python environments that require a different virtualenv and PYTHONPATH, you'll need to ensure the proper environment var is set for those when working on those projects.

If you just want to run a single unit test module from the command line, you can use the following pattern (in this example, the tests to run are contained in the module ConfigUtilDefaultTest, which is in the file test_ConfigUtilDefault.py).

  • Start your virtualenv
  • Change your working directory to IPP_HOME/tests
  • Make sure your PYTHONPATH is set as indicated above
  • Run the test module
    • NOTE: BE SURE TO USE THE CORRECT PATH FOR YOUR ENVIRONMENT!
python -m unittest unit/common/test_ConfigUtilDefault.py
python -m unittest unit/common/test_ConfigUtilCustom.py

Instructions

  • Read through the appropriate lab module presentation content and reference items from the class discussion.
  • Verify all sample code, unit / integration tests, and folder structure is the same as the online repo at https://github.com/programming-in-python/ipp-exercise-components.git.
  • Run all tests in the next section and ensure they work correctly. Add new tests as appropriate.
  • Review / verify any code updates within the repo.
  • Commit the local changes, then push the merged work to your remote.

Estimate

  • Small

Tests

IMPORTANT NOTE on Using VS Code

  • If you're using VS Code:
    • When setup properly, you can run the IPP exercises and all unit tests from within VS Code. Integration tests should run fine within VS Code; however, they often have external dependencies that will require their own configuration. See the integration test for details.
    • For details on configuring your environment with VS Code, see IPP VS Code Setup

IMPORTANT NOTE on TESTING

  • Unit tests and integration tests that do NOT involve running the test app:

    • In general, the easiest way to run unit tests (and some integration tests) is to use the unittest module from the command line, within the same directory path as the unit test.
      • E.g., python -m unittest ConfigUtilTest.py
      • Be sure your PYTHONPATH is setup properly to include BOTH the IPP_HOME and IPP_HOME/tests paths! It can be helpful, although is not necessarily required, to use a virtual environment to ensure your Python dependencies for development can be separated from other Python environments on your system.
  • Application tests (running the test app):

    • In general, the easiest way to run the test app instance is to run it directly from the command line as a Python app, within the same directory path as the app module, after setting up your operating environment according to the integration test instructions.
      • E.g., python IppTestApp.py
      • Be sure your PYTHONPATH is setup properly to include BOTH the IPP_HOME and IPP_HOME/tests paths!

TESTS

  • Unit tests (in IPP_HOME/tests/common)
    • Run tests for test_ConfigUtilDefault.py and test_ConfigUtilCustom.py. All unit tests should pass.
    • NOTE: In VS Code, you may need to configure unittest and then reload VS Code (restart, or simply refresh the test module) to see the tests appear.
  • Integration test
    • Run the IppTestApp.py directly in your console.
      • In VS Code, you can simply right click on IppTestApp.py and select Run Python file in Terminal.
      • NOTE: This will only work if your PYTHONPATH is configured properly!
    • It should run for slightly over 1 minute (about 65 seconds), load the default configuration file, and then exit without any error. Console output should look similar to the following:
(venv) :/mnt/d/ipp/ipp-exercise-components$ /mnt/d/ipp/ipp-exercise-components/venv/bin/python /mnt/d/ipp/ipp-exercise-components/ipp/app/IppTestApp.py
2025-08-31 18:31:18,164:::129026752753664:root.IppTestApp.main()[114]:INFO:Parsed configuration file arg: None
2025-08-31 18:31:18,164:::129026752753664:root.ConfigUtil.__init__()[60]:INFO:Creating instance of ConfigUtil: None
2025-08-31 18:31:18,164:::129026752753664:root.ConfigUtil._loadConfig()[228]:INFO:Attempting to locate IppConfig.props.
2025-08-31 18:31:18,164:::129026752753664:root.ConfigUtil._locateAndInitDefaultConfigFileName()[271]:INFO:Searching path /mnt/d/ipp/ipp-exercise-components/ipp/config/IppConfig.props for config file.
2025-08-31 18:31:18,164:::129026752753664:root.ConfigUtil._locateAndInitDefaultConfigFileName()[271]:INFO:Searching path /mnt/d/ipp/ipp-exercise-components/config/IppConfig.props for config file.
2025-08-31 18:31:18,166:::129026752753664:root.ConfigUtil._locateAndInitDefaultConfigFileName()[274]:INFO:Found configuration file at /mnt/d/ipp/ipp-exercise-components/config/IppConfig.props
2025-08-31 18:31:18,167:::129026752753664:root.ConfigUtil._loadConfigFile()[239]:INFO:Attempting to load config file: /mnt/d/ipp/ipp-exercise-components/config/IppConfig.props
2025-08-31 18:31:18,168:::129026752753664:root.ConfigUtil._loadConfigFile()[248]:INFO:Successfully loaded configuration at /mnt/d/ipp/ipp-exercise-components/config/IppConfig.props.
2025-08-31 18:31:18,168:::129026752753664:root.ConfigUtil._loadConfigFile()[249]:DEBUG:Config: ['Mqtt.GatewayService', 'IppTestApp', 'Settings.Environmental', 'Settings.Camera']
2025-08-31 18:31:18,168:::129026752753664:root.IppTestApp.__init__()[51]:INFO:Initializing IPP Test App...
2025-08-31 18:31:18,169:::129026752753664:root.IppTestApp.startApp()[65]:INFO:Starting Ipp Test App...
2025-08-31 18:31:18,169:::129026752753664:root.IppTestApp.startApp()[77]:INFO:Ipp Test App started.
2025-08-31 18:32:23,175:::129026752753664:root.IppTestApp.stopApp()[87]:INFO:Ipp Test App stopping...
2025-08-31 18:32:23,175:::129026752753664:root.IppTestApp.stopApp()[91]:INFO:Ipp Test App stopped with exit code 0.
2025-08-31 18:32:23,176:::129026752753664:root.IppTestApp.main()[159]:INFO:Exiting Ipp Test App.```
(venv) :/mnt/d/ipp/ipp-exercise-components$ 

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    Lab Module 01 - Setup

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions