Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d651b08

Browse files
committed
9_15 let's get back on track
1 parent 0e73a0d commit d651b08

File tree

15 files changed

+106
-13
lines changed

15 files changed

+106
-13
lines changed

01_hello/_testhello.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/usr/bin/env python3
2+
# Purpose: Say hello
3+
4+
import argparse
5+
6+
parser = argparse.ArgumentParser(description="Say Hello")
7+
parser.add_argument("-n", "--name", metavar="namee", default="World", help="Name to greet")
8+
args = parser.parse_args()
9+
print("Hello, " + args.name + "!")

01_hello/hello.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/env python3
2+
# Purpose: Say hello
3+
4+
import argparse
5+
6+
7+
def get_args():
8+
parser = argparse.ArgumentParser(description="Say Hello")
9+
parser.add_argument("-n", "--name", metavar="name", default="World", help="Name to greet")
10+
return parser.parse_args()
11+
12+
13+
def main():
14+
args = get_args()
15+
print("Hello, " + args.name + "!")
16+
17+
18+
if __name__ == "__main__":
19+
main()

01_hello/hello_test.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/usr/bin/env python3
2+
"""tests for hello.py"""
3+
4+
import os
5+
from subprocess import getoutput, getstatusoutput
6+
7+
prg = "./hello.py"
8+
9+
10+
# --------------------------------------------------
11+
def test_exists():
12+
"""exists"""
13+
14+
assert os.path.isfile(prg)
15+
16+
17+
# --------------------------------------------------
18+
def test_runnable():
19+
"""Runs using python3"""
20+
21+
out = getoutput(f"python3 {prg}")
22+
assert out.strip() == "Hello, World!"
23+
24+
25+
# --------------------------------------------------
26+
def test_executable():
27+
"""Says 'Hello, World!' by default"""
28+
29+
out = getoutput(prg)
30+
assert out.strip() == "Hello, World!"
31+
32+
33+
# --------------------------------------------------
34+
def test_usage():
35+
"""usage"""
36+
37+
for flag in ["-h", "--help"]:
38+
rv, out = getstatusoutput(f"{prg} {flag}")
39+
assert rv == 0
40+
assert out.lower().startswith("usage")
41+
42+
43+
# --------------------------------------------------
44+
def test_input():
45+
"""test for input"""
46+
47+
for val in ["Universe", "Multiverse"]:
48+
for option in ["-n", "--name"]:
49+
rv, out = getstatusoutput(f"{prg} {option} {val}")
50+
assert rv == 0
51+
assert out.strip() == f"Hello, {val}!"

01_hello/test.py

100755100644
Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
#!/usr/bin/env python3
1+
#!/Users/noeltanner/.pyenv/shims/python
22
"""tests for hello.py"""
33

44
import os
5-
from subprocess import getstatusoutput, getoutput
5+
from subprocess import getoutput, getstatusoutput
66

7-
prg = './hello.py'
7+
prg = "./hello.py"
88

99

1010
# --------------------------------------------------
@@ -18,34 +18,34 @@ def test_exists():
1818
def test_runnable():
1919
"""Runs using python3"""
2020

21-
out = getoutput(f'python3 {prg}')
22-
assert out.strip() == 'Hello, World!'
21+
out = getoutput(f"python3 {prg}")
22+
assert out.strip() == "Hello, World!"
2323

2424

2525
# --------------------------------------------------
2626
def test_executable():
2727
"""Says 'Hello, World!' by default"""
2828

2929
out = getoutput(prg)
30-
assert out.strip() == 'Hello, World!'
30+
assert out.strip() == "Hello, World!"
3131

3232

3333
# --------------------------------------------------
3434
def test_usage():
3535
"""usage"""
3636

37-
for flag in ['-h', '--help']:
38-
rv, out = getstatusoutput(f'{prg} {flag}')
37+
for flag in ["-h", "--help"]:
38+
rv, out = getstatusoutput(f"{prg} {flag}")
3939
assert rv == 0
40-
assert out.lower().startswith('usage')
40+
assert out.lower().startswith("usage")
4141

4242

4343
# --------------------------------------------------
4444
def test_input():
4545
"""test for input"""
4646

47-
for val in ['Universe', 'Multiverse']:
48-
for option in ['-n', '--name']:
49-
rv, out = getstatusoutput(f'{prg} {option} {val}')
47+
for val in ["Universe", "Multiverse"]:
48+
for option in ["-n", "--name"]:
49+
rv, out = getstatusoutput(f"{prg} {option} {val}")
5050
assert rv == 0
51-
assert out.strip() == f'Hello, {val}!'
51+
assert out.strip() == f"Hello, {val}!"

appendix/SETUP_WINDOWS.pdf

-128 KB
Binary file not shown.

extra/02_dna/README.pdf

-51.9 KB
Binary file not shown.

extra/02_spanish/README.pdf

-39.6 KB
Binary file not shown.

extra/02_strings/README.pdf

-40.8 KB
Binary file not shown.

extra/03_lister/README.pdf

-42.5 KB
Binary file not shown.

extra/04_days/README.pdf

-47.1 KB
Binary file not shown.

extra/07_proteins/README.pdf

-64.4 KB
Binary file not shown.

extra/08_rna/README.pdf

-70.9 KB
Binary file not shown.

extra/09_moog/README.pdf

-120 KB
Binary file not shown.

extra/10_whitmans/README.pdf

-71.2 KB
Binary file not shown.

notes.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
## Chap 1
2+
3+
4+
### Ch 1 Pt9:
5+
https://www.youtube.com/watch?v=aBZhN7ZxezU&list=PLhOuww6rJJNP7UvTeF6_tQ1xcubAs9hvO&index=9&ab_channel=KenYouens-Clark
6+
7+
Running a test
8+
- the "make test" command just runs pytest -xv test.py
9+
- Same for vsc testing icon it's just a gui version of pytest -xv test.py
10+
11+
```python
12+
if __name__ == '__main__':
13+
main()
14+
```

0 commit comments

Comments
 (0)