... | ... | @@ -673,7 +673,17 @@ class TestPlayer(unittest.TestCase): |
|
|
|
|
|
## Shapes Example
|
|
|
|
|
|
**Draft**
|
|
|
While this example focuses on polymorphism (e.g., abstract base classes), other
|
|
|
topics will be discussed, e.g.,
|
|
|
|
|
|
- Factory Pattern
|
|
|
- lambda functions
|
|
|
- `min` and `max` with lambdas as key functions
|
|
|
- unit tests [pyhamcrest](https://github.com/hamcrest/PyHamcrest) assertions
|
|
|
- Python project structure
|
|
|
|
|
|
|
|
|
### shape.py
|
|
|
|
|
|
```python
|
|
|
"""
|
... | ... | @@ -752,6 +762,9 @@ class Shape(metaclass=abc.ABCMeta): |
|
|
return STR_FMT.format("Name", self.name)
|
|
|
```
|
|
|
|
|
|
|
|
|
### square.py
|
|
|
|
|
|
```python
|
|
|
import copy
|
|
|
|
... | ... | @@ -817,6 +830,9 @@ class Square(Shape): |
|
|
+ FPT_FMT.format("Area", self.area()))
|
|
|
```
|
|
|
|
|
|
|
|
|
### shape_factory.py
|
|
|
|
|
|
```python
|
|
|
"""
|
|
|
This module provides factory utilities for creating shapes. This includes
|
... | ... | @@ -918,7 +934,7 @@ def number_known(): |
|
|
return len(_KNOWN_SHAPES)
|
|
|
```
|
|
|
|
|
|
### Shapes Driver
|
|
|
### run_shapes.py
|
|
|
|
|
|
```python
|
|
|
#! /usr/bin/env python3
|
... | ... | @@ -1036,27 +1052,15 @@ if __name__ == "__main__": |
|
|
print(err)
|
|
|
```
|
|
|
|
|
|
### Directory Structure
|
|
|
|
|
|
```
|
|
|
drwxrwxr-x htmlcov
|
|
|
-rw-rw-r-- inputShapes.txt
|
|
|
-rw-rw-r-- MANIFEST
|
|
|
-rw-rw-r-- runTests.sh
|
|
|
-rw-rw-r-- setup.py
|
|
|
drwxrwxr-x shapes
|
|
|
drwxrwxr-x tests
|
|
|
-rw-rw-r-- tox.ini
|
|
|
```
|
|
|
|
|
|
# Threads & Processes
|
|
|
|
|
|
This section will focus on a [single example](https://git-community.cs.odu.edu/tkennedy/python-workshop/-/blob/master/cs330-Python3-Toys/Example-3-parallel-coin-flip/coin_flip.py).
|
|
|
|
|
|
**Draft**
|
|
|
This section will focus on a [single
|
|
|
example](https://git-community.cs.odu.edu/tkennedy/python-workshop/-/blob/master/cs330-Python3-Toys/Example-3-parallel-coin-flip/coin_flip.py).
|
|
|
Topics will include:
|
|
|
|
|
|
- GIL
|
|
|
- Global Interpreter Lock (GIL)
|
|
|
- Threads vs Processes
|
|
|
- Futures
|
|
|
- `ProcessPoolExecutor`
|
|
|
- Simple timer with `datetime` |
|
|
- A simple timer with `datetime` |