Skip to content

Latest commit

 

History

History
78 lines (60 loc) · 1.67 KB

python.md

File metadata and controls

78 lines (60 loc) · 1.67 KB

Testing

# Basic Modules
import unittest

# Pip Modules

# Project modules

class StageTest(unittest.TestCase):
    def setUp(self):
        self.template_thing = "hello world"
    def tearDown(self):
        del self.template_thing

    def test_my_method(self):
        # Define
        my_input = self.template_thing

        # Process
        result = my_method(my_input)

        # Assert
        self.assertEqual(result, "hello-world")

    def test_multiple(self):
        # Define
        allowed_error = 0.001
        subtests = [
            # infow temp F, expected result
            (50, 253.5),
            (100, 503.5),
            (150, 753.5),
            (200, 1003.5),
        ]

        # Process
        calculated_value = {}
        for temp_f, _ in subtests:
            calculated_value[temp_f] = calculate_result(temp_f)

        # Assert
        for temp_f, expected_value in subtests:
            with self.subTest(temp_f = temp_inflow_f):
                self.assertAlmostEqual(calculated_value[temp_f], expected_value, delta = allowed_error)

Typing

# Dictionary
from typing import Dict
data:Dict[datetime, Device.StageData] = {}

# Method input/return
def greeting(name: str) -> str:
    return 'Hello ' + name

# Complex input
from typing import Union
def add_data(self, date_time:Union[datetime,int], speed_rpm:float):
    pass

Random - Choice

import random
cities = ["Atlanta", "New York", "Miami", "Chicago"]
source = random.choice(cities)
destination = random.choice([c for c in cities if c != source])

References

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy