8000 Code files added · e1teck/Clean-Code-in-Python@5e18464 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5e18464

Browse files
committed
Code files added
1 parent 2de6e84 commit 5e18464

File tree

199 files changed

+7740
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

199 files changed

+7740
-0
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
__pycache__
2+
*.sw[op]
3+
.mypy_cache/
4+
*.tar.gz
5+
.pytest_cache/

Chapter01/Makefile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
typehint:
2+
mypy --ignore-missing-imports src/
3+
4+
test:
5+
pytest tests/
6+
7+
lint:
8+
pylint src/
9+
10+
checklist: lint typehint test
11+
12+
black:
13+
black -l 79 *.py
14+
15+
setup:
16+
$(VIRTUAL_ENV)/bin/pip install -r requirements.txt
17+
18+
.PHONY: typehint test lint checklist black

Chapter01/README.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Chapter 01 - Introduction, Tools, and Formatting
2+
================================================
3+
4+
Install dependencies::
5+
6+
make setup
7+
8+
Run the tests::
9+
10+
make test

Chapter01/before_black.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
"""Clean Code in Python - Chapter 1: Introduction, Tools, and Formatting
2+
3+
> Black:
4+
A code that is compliant with PEP-8, but that still can be modified by back
5+
6+
7+
Run::
8+
black -l 79 before_black.py
9+
10+
To see the difference
11+
"""
12+
13+
14+
def my_function(name):
15+
"""
16+
>>> my_function('black')
17+
'received Black'
18+
"""
19+
return 'received {0}'.format(name.title())

Chapter01/requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-r ../requirements.txt
2+
pytest==3.7.1

Chapter01/src/__init__.py

Whitespace-only changes.

Chapter01/src/annotations.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
"""Clean Code in Python - Chapter 1: Introduction, Tools, and Formatting
2+
3+
> Annotations
4+
"""
5+
6+
7+
class Point: # pylint: disable=R0903
8+
"""Example to be used as return type of locate"""
9+
def __init__(self, lat, long):
10+
self.lat = lat
11+
self.long = long
12+
13+
14+
def locate(latitude: float, longitude: float) -> Point:
15+
"""Find an object in the map by its coordinates"""
16+
return Point(latitude, longitude)
17+
18+
19+
class NewPoint: # pylint: disable=R0903
20+
"""Example to display its __annotations__ attribute."""
21+
lat: float
22+
long: float

Chapter01/src/test_annotations.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
"""Clean Code in Python - Chapter 01: Introcution, Tools, and Formatting
2+
3+
Tests for annotations examples
4+
5+
"""
6+
import pytest
7+
8+
from src.annotations import NewPoint, Point, locate
9+
10+
11+
@pytest.mark.parametrize(
12+
"element,expected",
13+
(
14+
(locate, {"latitude": float, "longitude": float, "return": Point}),
15+
(NewPoint, {"lat": float, "long": float}),
16+
),
17+
)
18+
def test_annotations(element, expected):
19+
"""test the class/functions againts its expected annotations"""
20+
assert getattr(element, "__annotations__") == expected

Chapter01/tests

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
src

Chapter02/Makefile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
PYTHON:=$(VIRTUAL_ENV)/bin/python
2+
3+
test:
4+
@$(PYTHON) -m doctest *.py
5+
@$(PYTHON) -m unittest *.py
6+
7+
.PHONY: test

0 commit comments

Comments
 (0)
0