From a59617ddf0775a52319d1d130a71d95519e73718 Mon Sep 17 00:00:00 2001 From: Kent Riggins Date: Mon, 20 Dec 2021 21:03:01 -0500 Subject: [PATCH 1/5] All done --- 01_hello/hello.py | 28 ++++++++++++++++++++++++++++ 01_hello/hello08_formatted.py | 4 ++-- 01_hello/{test.py => hello_test.py} | 8 ++++---- 3 files changed, 34 insertions(+), 6 deletions(-) create mode 100644 01_hello/hello.py rename 01_hello/{test.py => hello_test.py} (86%) mode change 100755 => 100644 diff --git a/01_hello/hello.py b/01_hello/hello.py new file mode 100644 index 000000000..9ca282202 --- /dev/null +++ b/01_hello/hello.py @@ -0,0 +1,28 @@ +#!/usr/bin/env python3 +""" +Purpose: Say hello +Author: kent +""" +import argparse + + +def get_args(): + """ Get the command line arguments """ + parser = argparse.ArgumentParser(description='Say hello') + parser.add_argument('-n', + '--name', + metavar="name", + default='World', + help="Name to greet") + return parser.parse_args() + + +def main(): + """main""" + args = get_args() + name = args.name + print('Hello, ' + name + '!') # comment + + +if __name__ == '__main__': + main() diff --git a/01_hello/hello08_formatted.py b/01_hello/hello08_formatted.py index e35e5d3b5..987a0848d 100755 --- a/01_hello/hello08_formatted.py +++ b/01_hello/hello08_formatted.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python3 +#!python3 """ Author: Ken Youens-Clark Purpose: Say hello @@ -12,7 +12,7 @@ def get_args(): """Get the command-line arguments""" parser = argparse.ArgumentParser(description='Say hello') - parser.add_argument('-n', '--name', default='World', help='Name to greet') + parser.add_argument('-n', '--name', default='Worlds', help='Name to greet') return parser.parse_args() diff --git a/01_hello/test.py b/01_hello/hello_test.py old mode 100755 new mode 100644 similarity index 86% rename from 01_hello/test.py rename to 01_hello/hello_test.py index d0cedd1c2..dd6e9ef41 --- a/01_hello/test.py +++ b/01_hello/hello_test.py @@ -1,10 +1,10 @@ -#!/usr/bin/env python3 +#! python3 """tests for hello.py""" import os from subprocess import getstatusoutput, getoutput -prg = './hello.py' +prg = '.\hello.py' # -------------------------------------------------- @@ -35,7 +35,7 @@ def test_usage(): """usage""" for flag in ['-h', '--help']: - rv, out = getstatusoutput(f'{prg} {flag}') + rv, out = getstatusoutput(f'python3 {prg} {flag}') assert rv == 0 assert out.lower().startswith('usage') @@ -46,6 +46,6 @@ def test_input(): for val in ['Universe', 'Multiverse']: for option in ['-n', '--name']: - rv, out = getstatusoutput(f'{prg} {option} {val}') + rv, out = getstatusoutput(f'python3 {prg} {option} {val}') assert rv == 0 assert out.strip() == f'Hello, {val}!' From fe122a04cca552a9e7f11e805f61217dad150d99 Mon Sep 17 00:00:00 2001 From: Kent Riggins Date: Mon, 20 Dec 2021 21:12:35 -0500 Subject: [PATCH 2/5] start --- 02_crowsnest/{test.py => crowsnest_test.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename 02_crowsnest/{test.py => crowsnest_test.py} (100%) mode change 100755 => 100644 diff --git a/02_crowsnest/test.py b/02_crowsnest/crowsnest_test.py old mode 100755 new mode 100644 similarity index 100% rename from 02_crowsnest/test.py rename to 02_crowsnest/crowsnest_test.py From 14b0551f71aeb52e014c1d297434a7195371385e Mon Sep 17 00:00:00 2001 From: Kent Riggins Date: Mon, 27 Dec 2021 21:03:42 -0500 Subject: [PATCH 3/5] code modified to work --- 01_hello/hello_test.py | 8 ++++---- 02_crowsnest/crowsnest_test.py | 14 +++++++------- 03_picnic/{test.py => picnic_test.py} | 12 ++++++------ 04_jump_the_five/{test.py => jump_test.py} | 0 4 files changed, 17 insertions(+), 17 deletions(-) rename 03_picnic/{test.py => picnic_test.py} (83%) mode change 100755 => 100644 rename 04_jump_the_five/{test.py => jump_test.py} (100%) mode change 100755 => 100644 diff --git a/01_hello/hello_test.py b/01_hello/hello_test.py index dd6e9ef41..36e529d95 100644 --- a/01_hello/hello_test.py +++ b/01_hello/hello_test.py @@ -1,4 +1,4 @@ -#! python3 +#! python """tests for hello.py""" import os @@ -18,7 +18,7 @@ def test_exists(): def test_runnable(): """Runs using python3""" - out = getoutput(f'python3 {prg}') + out = getoutput(f'python {prg}') assert out.strip() == 'Hello, World!' @@ -35,7 +35,7 @@ def test_usage(): """usage""" for flag in ['-h', '--help']: - rv, out = getstatusoutput(f'python3 {prg} {flag}') + rv, out = getstatusoutput(f'python {prg} {flag}') assert rv == 0 assert out.lower().startswith('usage') @@ -46,6 +46,6 @@ def test_input(): for val in ['Universe', 'Multiverse']: for option in ['-n', '--name']: - rv, out = getstatusoutput(f'python3 {prg} {option} {val}') + rv, out = getstatusoutput(f'python {prg} {option} {val}') assert rv == 0 assert out.strip() == f'Hello, {val}!' diff --git a/02_crowsnest/crowsnest_test.py b/02_crowsnest/crowsnest_test.py index d4e25c6c7..a242c8d75 100644 --- a/02_crowsnest/crowsnest_test.py +++ b/02_crowsnest/crowsnest_test.py @@ -1,10 +1,10 @@ -#!/usr/bin/env python3 +#!python """tests for crowsnest.py""" import os from subprocess import getstatusoutput, getoutput -prg = './crowsnest.py' +prg = '.\crowsnest.py' consonant_words = [ 'brigantine', 'clipper', 'dreadnought', 'frigate', 'galleon', 'haddock', 'junk', 'ketch', 'longboat', 'mullet', 'narwhal', 'porpoise', 'quay', @@ -27,7 +27,7 @@ def test_usage(): """usage""" for flag in ['-h', '--help']: - rv, out = getstatusoutput(f'{prg} {flag}') + rv, out = getstatusoutput(f'python {prg} {flag}') assert rv == 0 assert out.lower().startswith('usage') @@ -37,7 +37,7 @@ def test_consonant(): """brigantine -> a brigantine""" for word in consonant_words: - out = getoutput(f'{prg} {word}') + out = getoutput(f'python {prg} {word}') assert out.strip() == template.format('a', word) @@ -46,7 +46,7 @@ def test_consonant_upper(): """brigantine -> a Brigatine""" for word in consonant_words: - out = getoutput(f'{prg} {word.title()}') + out = getoutput(f'python {prg} {word.title()}') assert out.strip() == template.format('a', word.title()) @@ -55,7 +55,7 @@ def test_vowel(): """octopus -> an octopus""" for word in vowel_words: - out = getoutput(f'{prg} {word}') + out = getoutput(f'python {prg} {word}') assert out.strip() == template.format('an', word) @@ -64,5 +64,5 @@ def test_vowel_upper(): """octopus -> an Octopus""" for word in vowel_words: - out = getoutput(f'{prg} {word.upper()}') + out = getoutput(f'python {prg} {word.upper()}') assert out.strip() == template.format('an', word.upper()) diff --git a/03_picnic/test.py b/03_picnic/picnic_test.py old mode 100755 new mode 100644 similarity index 83% rename from 03_picnic/test.py rename to 03_picnic/picnic_test.py index 281fab552..3d9b991ed --- a/03_picnic/test.py +++ b/03_picnic/picnic_test.py @@ -19,7 +19,7 @@ def test_usage(): """usage""" for flag in ['', '-h', '--help']: - out = getoutput(f'{prg} {flag}') + out = getoutput(f'python {prg} {flag}') assert out.lower().startswith('usage') @@ -27,7 +27,7 @@ def test_usage(): def test_one(): """one item""" - out = getoutput(f'{prg} chips') + out = getoutput(f'python {prg} chips') assert out.strip() == 'You are bringing chips.' @@ -35,7 +35,7 @@ def test_one(): def test_two(): """two items""" - out = getoutput(f'{prg} soda "french fries"') + out = getoutput(f'python {prg} soda "french fries"') assert out.strip() == 'You are bringing soda and french fries.' @@ -44,7 +44,7 @@ def test_more_than_two(): """more than two items""" arg = '"potato chips" coleslaw cupcakes "French silk pie"' - out = getoutput(f'{prg} {arg}') + out = getoutput(f'python {prg} {arg}') expected = ('You are bringing potato chips, coleslaw, ' 'cupcakes, and French silk pie.') assert out.strip() == expected @@ -54,7 +54,7 @@ def test_more_than_two(): def test_two_sorted(): """two items sorted output""" - out = getoutput(f'{prg} -s soda candy') + out = getoutput(f'python {prg} -s soda candy') assert out.strip() == 'You are bringing candy and soda.' @@ -63,6 +63,6 @@ def test_more_than_two_sorted(): """more than two items sorted output""" arg = 'bananas apples dates cherries' - out = getoutput(f'{prg} {arg} --sorted') + out = getoutput(f'python {prg} {arg} --sorted') expected = ('You are bringing apples, bananas, cherries, and dates.') assert out.strip() == expected diff --git a/04_jump_the_five/test.py b/04_jump_the_five/jump_test.py old mode 100755 new mode 100644 similarity index 100% rename from 04_jump_the_five/test.py rename to 04_jump_the_five/jump_test.py From 12eac892e1a0401a47a077c6b91a412f0fdf94a1 Mon Sep 17 00:00:00 2001 From: Kent Riggins Date: Thu, 24 Mar 2022 20:07:18 -0400 Subject: [PATCH 4/5] updateing for pytest --- 04_jump_the_five/jump_test.py | 6 +++--- 05_howler/{test.py => howler_test.py} | 8 ++++---- 05_howler/test.txt | 1 + 06_wc/{test.py => wc_test.py} | 16 ++++++++-------- 07_gashlycrumb/gashlycrumb_interactive.py | 1 + 07_gashlycrumb/{test.py => gashlycrumb_test.py} | 14 +++++++------- .../{test.py => apples_test.py} | 14 +++++++------- 7 files changed, 31 insertions(+), 29 deletions(-) rename 05_howler/{test.py => howler_test.py} (89%) mode change 100755 => 100644 create mode 100644 05_howler/test.txt rename 06_wc/{test.py => wc_test.py} (83%) mode change 100755 => 100644 rename 07_gashlycrumb/{test.py => gashlycrumb_test.py} (85%) mode change 100755 => 100644 rename 08_apples_and_bananas/{test.py => apples_test.py} (80%) mode change 100755 => 100644 diff --git a/04_jump_the_five/jump_test.py b/04_jump_the_five/jump_test.py index 5dc89e311..42a17c0ed 100644 --- a/04_jump_the_five/jump_test.py +++ b/04_jump_the_five/jump_test.py @@ -19,7 +19,7 @@ def test_usage(): """usage""" for flag in ['-h', '--help']: - rv, out = getstatusoutput(f'{prg} {flag}') + rv, out = getstatusoutput(f'python {prg} {flag}') assert rv == 0 assert out.lower().startswith('usage') @@ -28,7 +28,7 @@ def test_usage(): def test_01(): """test""" - rv, out = getstatusoutput(f'{prg} 123-456-7890') + rv, out = getstatusoutput(f'python {prg} 123-456-7890') assert rv == 0 assert out == '987-604-3215' @@ -37,6 +37,6 @@ def test_01(): def test_02(): """test""" - rv, out = getstatusoutput(f'{prg} "That number to call is 098-765-4321."') + rv, out = getstatusoutput(f'python {prg} "That number to call is 098-765-4321."') assert rv == 0 assert out.rstrip() == 'That number to call is 512-340-6789.' diff --git a/05_howler/test.py b/05_howler/howler_test.py old mode 100755 new mode 100644 similarity index 89% rename from 05_howler/test.py rename to 05_howler/howler_test.py index 1c04934c8..57211371f --- a/05_howler/test.py +++ b/05_howler/howler_test.py @@ -37,7 +37,7 @@ def test_usage(): """usage""" for flag in ['-h', '--help']: - rv, out = getstatusoutput(f'{prg} {flag}') + rv, out = getstatusoutput(f'python {prg} {flag}') assert rv == 0 assert re.match("usage", out, re.IGNORECASE) @@ -46,7 +46,7 @@ def test_usage(): def test_text_stdout(): """Test STDIN/STDOUT""" - out = getoutput(f'{prg} "foo bar baz"') + out = getoutput(f'python {prg} "foo bar baz"') assert out.strip() == 'FOO BAR BAZ' @@ -59,7 +59,7 @@ def test_text_outfile(): os.remove(out_file) try: - out = getoutput(f'{prg} {out_flag()} {out_file} "foo bar baz"') + out = getoutput(f'python {prg} {out_flag()} {out_file} "foo bar baz"') assert out.strip() == '' assert os.path.isfile(out_file) text = open(out_file).read().rstrip() @@ -81,7 +81,7 @@ def test_file(): basename = os.path.basename(expected_file) in_file = os.path.join('../inputs', basename) - out = getoutput(f'{prg} {out_flag()} {out_file} {in_file}') + out = getoutput(f'python {prg} {out_flag()} {out_file} {in_file}') assert out.strip() == '' produced = open(out_file).read().rstrip() expected = open(os.path.join('test-outs', diff --git a/05_howler/test.txt b/05_howler/test.txt new file mode 100644 index 000000000..fa96e1af2 --- /dev/null +++ b/05_howler/test.txt @@ -0,0 +1 @@ +THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG. diff --git a/06_wc/test.py b/06_wc/wc_test.py old mode 100755 new mode 100644 similarity index 83% rename from 06_wc/test.py rename to 06_wc/wc_test.py index f9ebc9dea..e3859f3db --- a/06_wc/test.py +++ b/06_wc/wc_test.py @@ -27,7 +27,7 @@ def test_usage(): """usage""" for flag in ['-h', '--help']: - rv, out = getstatusoutput(f'{prg} {flag}') + rv, out = getstatusoutput(f' python {prg} {flag}') assert rv == 0 assert re.match("usage", out, re.IGNORECASE) @@ -45,7 +45,7 @@ def test_bad_file(): """bad_file""" bad = random_string() - rv, out = getstatusoutput(f'{prg} {bad}') + rv, out = getstatusoutput(f'python {prg} {bad}') assert rv != 0 assert re.search(f"No such file or directory: '{bad}'", out) @@ -54,7 +54,7 @@ def test_bad_file(): def test_empty(): """Test on empty""" - rv, out = getstatusoutput(f'{prg} {empty}') + rv, out = getstatusoutput(f'python {prg} {empty}') assert rv == 0 assert out.rstrip() == ' 0 0 0 ./inputs/empty.txt' @@ -63,7 +63,7 @@ def test_empty(): def test_one(): """Test on one""" - rv, out = getstatusoutput(f'{prg} {one_line}') + rv, out = getstatusoutput(f'python {prg} {one_line}') assert rv == 0 assert out.rstrip() == ' 1 1 2 ./inputs/one.txt' @@ -72,7 +72,7 @@ def test_one(): def test_two(): """Test on two""" - rv, out = getstatusoutput(f'{prg} {two_lines}') + rv, out = getstatusoutput(f'python {prg} {two_lines}') assert rv == 0 assert out.rstrip() == ' 2 2 4 ./inputs/two.txt' @@ -81,7 +81,7 @@ def test_two(): def test_fox(): """Test on fox""" - rv, out = getstatusoutput(f'{prg} {fox}') + rv, out = getstatusoutput(f'python {prg} {fox}') assert rv == 0 assert out.rstrip() == ' 1 9 45 ../inputs/fox.txt' @@ -90,7 +90,7 @@ def test_fox(): def test_more(): """Test on more than one file""" - rv, out = getstatusoutput(f'{prg} {fox} {sonnet}') + rv, out = getstatusoutput(f'python {prg} {fox} {sonnet}') expected = (' 1 9 45 ../inputs/fox.txt\n' ' 17 118 661 ../inputs/sonnet-29.txt\n' ' 18 127 706 total') @@ -102,6 +102,6 @@ def test_more(): def test_stdin(): """Test on stdin""" - rv, out = getstatusoutput(f'{prg} < {fox}') + rv, out = getstatusoutput(f'python {prg} < {fox}') assert rv == 0 assert out.rstrip() == ' 1 9 45 ' diff --git a/07_gashlycrumb/gashlycrumb_interactive.py b/07_gashlycrumb/gashlycrumb_interactive.py index 6ed82c5ef..9dbfaf393 100755 --- a/07_gashlycrumb/gashlycrumb_interactive.py +++ b/07_gashlycrumb/gashlycrumb_interactive.py @@ -2,6 +2,7 @@ """Interactive Gashlycrumb""" import argparse +from pprint import pprint as pp # -------------------------------------------------- diff --git a/07_gashlycrumb/test.py b/07_gashlycrumb/gashlycrumb_test.py old mode 100755 new mode 100644 similarity index 85% rename from 07_gashlycrumb/test.py rename to 07_gashlycrumb/gashlycrumb_test.py index b7bd700eb..cc3e3be12 --- a/07_gashlycrumb/test.py +++ b/07_gashlycrumb/gashlycrumb_test.py @@ -29,7 +29,7 @@ def test_usage(): """usage""" for flag in ['-h', '--help']: - rv, out = getstatusoutput(f'{prg} {flag}') + rv, out = getstatusoutput(f'python {prg} {flag}') assert rv == 0 assert re.match("usage", out, re.IGNORECASE) @@ -40,7 +40,7 @@ def test_bad_file(): bad = random_string() letter = random.choice(string.ascii_lowercase) - rv, out = getstatusoutput(f'{prg} {letter} -f {bad}') + rv, out = getstatusoutput(f'python {prg} {letter} -f {bad}') assert rv != 0 expected = f"No such file or directory: '{bad}'" assert re.search(expected, out) @@ -50,7 +50,7 @@ def test_bad_file(): def test_a(): """Test for 'a'""" - rv, out = getstatusoutput(f'{prg} a') + rv, out = getstatusoutput(f'python {prg} a') assert rv == 0 expected = 'A is for Amy who fell down the stairs.' assert out.strip() == expected @@ -60,7 +60,7 @@ def test_a(): def test_b_c(): """Test for 'b c'""" - rv, out = getstatusoutput(f'{prg} b c') + rv, out = getstatusoutput(f'python {prg} b c') assert rv == 0 expected = ('B is for Basil assaulted by bears.\n' 'C is for Clara who wasted away.') @@ -71,7 +71,7 @@ def test_b_c(): def test_y(): """Test for 'y'""" - rv, out = getstatusoutput(f'{prg} Y') + rv, out = getstatusoutput(f'python {prg} Y') assert rv == 0 expected = 'Y is for Yorick whose head was bashed in.' assert out.strip() == expected @@ -81,7 +81,7 @@ def test_y(): def test_o_alternate(): """ Test for 'o' from 'alternate.txt' """ - rv, out = getstatusoutput(f'{prg} o P q -f alternate.txt') + rv, out = getstatusoutput(f'python {prg} o P q -f alternate.txt') assert rv == 0 expected = ('O is for Orville, who fell in a canyon.\n' 'P is for Paul, strangled by his banyan.\n' @@ -93,7 +93,7 @@ def test_o_alternate(): def test_bad_letter(): """Test for bad input""" - rv, out = getstatusoutput(f'{prg} 5 CH') + rv, out = getstatusoutput(f'python {prg} 5 CH') assert rv == 0 expected = ('I do not know "5".\n' 'I do not know "CH".') assert out.strip() == expected diff --git a/08_apples_and_bananas/test.py b/08_apples_and_bananas/apples_test.py old mode 100755 new mode 100644 similarity index 80% rename from 08_apples_and_bananas/test.py rename to 08_apples_and_bananas/apples_test.py index e82161f9b..9c56b79a4 --- a/08_apples_and_bananas/test.py +++ b/08_apples_and_bananas/apples_test.py @@ -21,7 +21,7 @@ def test_usage(): """usage""" for flag in ['-h', '--help']: - rv, out = getstatusoutput(f'{prg} {flag}') + rv, out = getstatusoutput(f'python {prg} {flag}') assert rv == 0 assert re.match("usage", out, re.IGNORECASE) @@ -30,7 +30,7 @@ def test_usage(): def test_bad_vowel(): """Should fail on a bad vowel""" - rv, out = getstatusoutput(f'{prg} -v x foo') + rv, out = getstatusoutput(f'python {prg} -v x foo') assert rv != 0 assert re.match("usage", out, re.IGNORECASE) @@ -39,7 +39,7 @@ def test_bad_vowel(): def test_command_line(): """ foo -> faa """ - out = getoutput(f'{prg} foo') + out = getoutput(f'python {prg} foo') assert out.strip() == 'faa' @@ -47,7 +47,7 @@ def test_command_line(): def test_command_line_with_vowel(): """ foo -> fii """ - out = getoutput(f'{prg} -v i foo') + out = getoutput(f'python {prg} -v i foo') assert out.strip() == 'fii' @@ -55,7 +55,7 @@ def test_command_line_with_vowel(): def test_command_line_with_vowel_preserve_case(): """ foo -> fii """ - out = getoutput(f'{prg} "APPLES AND BANANAS" --vowel i') + out = getoutput(f'python {prg} "APPLES AND BANANAS" --vowel i') assert out.strip() == 'IPPLIS IND BININIS' @@ -63,7 +63,7 @@ def test_command_line_with_vowel_preserve_case(): def test_file(): """ fox.txt """ - out = getoutput(f'{prg} {fox}') + out = getoutput(f'python {prg} {fox}') assert out.strip() == 'Tha qaack brawn fax jamps avar tha lazy dag.' @@ -71,5 +71,5 @@ def test_file(): def test_file_with_vowel(): """ fox.txt """ - out = getoutput(f'{prg} --vowel o {fox}') + out = getoutput(f'python {prg} --vowel o {fox}') assert out.strip() == 'Tho qoock brown fox jomps ovor tho lozy dog.' From cd4223e0cb92984d10cb99bf6a473144ccca8d3c Mon Sep 17 00:00:00 2001 From: Kent Riggins Date: Tue, 5 Apr 2022 21:32:27 -0400 Subject: [PATCH 5/5] this is a test of the git change tracking --- 01_hello/hello_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/01_hello/hello_test.py b/01_hello/hello_test.py index 36e529d95..b5971504b 100644 --- a/01_hello/hello_test.py +++ b/01_hello/hello_test.py @@ -4,7 +4,7 @@ import os from subprocess import getstatusoutput, getoutput -prg = '.\hello.py' +prg = '.\\hello.py' # --------------------------------------------------