ParadigmHyperloop / hyperloop

High Performance Hyperloop Pod Control Software
https://paradigmhyperloop.com
Other
17 stars 4 forks source link

Abstract unittest test classes #67

Closed EdHurtig closed 6 years ago

EdHurtig commented 6 years ago

Each test in tests/integration will have the same redundant code in it as stands. This redundant code should be DRY'd up

Redundancy is in the setup and tear down

import os
import time
import unittest

from hyperloop import ControllerInstance

PATHS = [
    os.environ.get("CORE_LOCATION", None),
    "../../proj/BUILD/dst/usr/local/bin/core",
    "../../proj/core/core",
    "./BUILD/dst/usr/local/bin/core",
    "./proj/BUILD/dst/usr/local/bin/core",
    "./proj/core/core",
]

CONTROLLER_PATH = None

for path in PATHS:
    if path and os.path.exists(path):
        CONTROLLER_PATH = path
        break

class TestFlightProfiles(unittest.TestCase):

    def setUp(self):
        if CONTROLLER_PATH is None:
            self.fail("Could not find core: ".format(PATHS))

        self.controller = ControllerInstance(CONTROLLER_PATH, imu="-",
                                             POST=True)

        self.assertTrue(self.controller.start())

    def tearDown(self):
        self.controller.shutdown()

Notably, the PATHS list to discover the binary really needs to be in a single place as it will certainly change in the future