Skip to content

Commit feaebef

Browse files
committed
code review
1 parent 0db7665 commit feaebef

File tree

7 files changed

+114
-70
lines changed

7 files changed

+114
-70
lines changed

students/briggsm/Term2_project/baselinter/baselinter/baselinter.py

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,27 @@
1-
'''BaseLinter'''
1+
'''BaseLinter version 0.1
2+
Base Linter is a command-line interface app checks for sets of words in a text by order.
3+
Each time the app encounters a word belonging to a set, it prompts you to choose which
4+
of the words in the set. The app will replace the word in that position in the word
5+
order in the text you are checking. When you are done, the app saved the updated text
6+
as a file with the date in the filename.
7+
8+
Matt Briggs 2018-02-24
9+
10+
'''
211

312
import json
413
import datetime
514
import os
15+
import baselinter as BS
16+
17+
# Global Variables
618

7-
LOCATION = "D:\\UW\\Intro-to-Python\\IntroPython-2017\\students\\briggsm\\Term2_project\\baselinter\\baselinter\\" # os.path.dirname(os.path.realpath('__file__'))
819
THISDATE = str(datetime.date.today()) # e:\MB\Better-Butter\Projects\BaseLinter
920
LIST_of_SETS = []
1021
LINTER_NAME = ""
1122

23+
# Functions
24+
1225

1326
def open_set_json(filename):
1427
'''Opens a JSON file and returns the a list of sets.'''
@@ -79,20 +92,27 @@ def select_update(choices, wordlist, wordloc):
7992
Select ----------------------------\n
8093
{}\n
8194
-----------------------------------\n
95+
N ) next I ) ignore\n
8296
{}
8397
-----------------------------------
8498
""".format(display_string, display_choices))
85-
choiceindex = input("Select an option. > ")
86-
wordupdate = these_choices[int(choiceindex)-1]
87-
wordlist[wordloc] = wordupdate
88-
return wordlist
99+
choosing = True
100+
while (choosing == True):
101+
choiceindex = input("Select an option. > ")
102+
try:
103+
wordupdate = these_choices[int(choiceindex)-1]
104+
wordlist[wordloc] = wordupdate
105+
return wordlist
106+
choosing = False
107+
except ValueError:
108+
print ("Please type a valid option. \n")
109+
choosing = True
89110

90111

91112
def load_linter():
92113
'''Load linters'''
93114
global LIST_of_SETS
94115
global LINTER_NAME
95-
global LOCATION
96116

97117
linters = { "American Homophone" : "\\data\\guide-amhomo.json",
98118
"MS Docs Voice Guide" : "\\data\\guide-msdocs.json",
@@ -106,7 +126,7 @@ def load_linter():
106126
lint_choice = input("Select an option. > ")
107127
lint_choice = int(lint_choice) - 1
108128
LINTER_NAME = lint_list[lint_choice]
109-
LIST_of_SETS = open_set_json(LOCATION + "\\" + linters[LINTER_NAME])
129+
LIST_of_SETS = open_set_json(os.path.dirname(BS.__file__) + linters[LINTER_NAME])
110130

111131
return True
112132

@@ -116,6 +136,7 @@ def exit_app():
116136
print("Goodbye.")
117137
return False
118138

139+
119140
def check_file():
120141
''' '''
121142
try:
@@ -135,9 +156,6 @@ def check_file():
135156
f.write(outtext)
136157
return True
137158

138-
139-
140-
141159
chooser = {
142160
"1": ("Check file.", check_file),
143161
"2": ("Load new linter.", load_linter),
@@ -151,7 +169,8 @@ def main():
151169
global LIST_of_SETS
152170

153171
LINTER_NAME = "American Homophone"
154-
LIST_of_SETS = open_set_json(LOCATION + "\\data\\guide-amhomo.json")
172+
173+
LIST_of_SETS = open_set_json(os.path.dirname(BS.__file__) + "\\data\\guide-amhomo.json")
155174

156175
run = True
157176
while run == True:
Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,44 @@
11
{
2-
"7a548216-9301-43d1-af5b-77cc976a0eed" : ["actionable","**edit item :: actionable"],
3-
"9bd390f6-2258-4240-a07d-cb3c6a216d32" : ["agreeance","**edit item :: agreeance"],
4-
"3ce7f957-470a-4b08-a182-9522ab8858c1" : ["bandwidth","**edit item :: bandwidth"],
5-
"c54911a5-b4c6-4414-a7c8-0868e897f966" : ["client-centered","**edit item :: client-centered"],
6-
"164d20ed-6fc7-4010-bef2-09ade126b620" : ["CYA","**edit item :: CYA"],
7-
"3dd40bc4-1e0f-46e9-9089-39a359686199" : ["going forward","**edit item :: going forward"],
8-
"e0784322-bed2-425b-97df-f5fd48b01e63" : ["go rogue","**edit item :: go rogue"],
9-
"e7001580-e2b9-4c48-b351-e62a723c26a9" : ["guesstimate","**edit item :: guesstimate"],
10-
"b0bf2b70-d2df-4a4a-8880-db1dc6d7ed9e" : ["impact","**edit item :: impact"],
11-
"ec515601-5aa9-4b4a-80ab-6345fb1eb73b" : ["incent","**edit item :: incent"],
12-
"ecf801a1-7115-4dc6-ba7f-18aea6c2a3bc" : ["incentivize","**edit item :: incentivize"],
13-
"317c9986-0817-4863-b2eb-389c8e2db71b" : ["impactful","**edit item :: impactful"],
14-
"7193d135-7f14-4541-8e8b-04d64d1c36ad" : ["leverage","**edit item :: leverage"],
15-
"086040a3-8240-4a9b-bc8c-55562fe77aa1" : ["liaise","**edit item :: liaise"],
16-
"97873513-46d1-4352-85fd-24bd24bd9773" : ["mission-critical","**edit item :: mission-critical"],
17-
"dd188923-2d91-48ca-bae0-b081e0b159d4" : ["monetize","**edit item :: monetize"],
18-
"2bf760c2-b4d7-44eb-b248-27a213d35ce8" : ["net-net","**edit item :: net-net"],
19-
"61dadc35-bd21-4ecf-b2b3-c984d09a1f64" : ["operationalize","**edit item :: operationalize"],
20-
"caca5a35-5206-4088-8ac3-7675ee83018d" : ["optimize","**edit item :: optimize"],
21-
"e5b977e6-9e47-4e0c-aee1-2109062f1bf3" : ["paradigm","**edit item :: paradigm"],
22-
"0f44c71e-592a-498d-a402-31a8e479164f" : ["parameters","**edit item :: parameters"],
23-
"d2a1fe8f-b3fe-4d41-8eb3-97999665cce5" : ["planfu","**edit item :: planfu"],
24-
"a4871fd0-630e-4739-8d5f-222381ffc94f" : ["pursuant","**edit item :: pursuant"],
25-
"b03dae0a-02ce-4185-bc79-103d775c0b37" : ["recontextualize","**edit item :: recontextualize"],
26-
"1ce02721-02d3-4236-a73e-51da03aacbc1" : ["repurpose","**edit item :: repurpose"],
27-
"f83176fe-3c88-4fe5-a1ed-77dcf3773f81" : ["rightsized","**edit item :: rightsized"],
28-
"49ce5f29-0be3-4c63-92dc-6cebf4acb545" : ["sacred cow","**edit item :: sacred cow"],
29-
"164abeb6-2ac7-4e0a-ac43-1745e44f39f3" : ["scalable","**edit item :: scalable"],
30-
"89ecc5d0-da96-44a8-887d-71b5d8bbeb91" : ["seamless","**edit item :: seamless"],
31-
"c2999f2f-3e45-4b00-8db3-019918b60d4e" : ["seismic","**edit item :: seismic"],
32-
"f8b1dedf-b1a4-42c3-be88-7edf4cfa380d" : ["smartsized","**edit item :: smartsized"],
33-
"fd511c6c-eb16-4ee8-905c-914b4cd26c96" : ["strategic","**edit item :: strategic"],
34-
"81a5da6e-502c-4f30-a696-34c9d23eba16" : ["alliance","**edit item :: alliance"],
35-
"19281354-320d-43ef-841e-0498035cbfd0" : ["dynamism","**edit item :: dynamism"],
36-
"b4ad18fc-3a3d-44b2-8ed7-cfb5ab9cbe37" : ["synergize","**edit item :: synergize"],
37-
"2796c91e-8734-4e3e-afeb-ac440ae26f07" : ["synergy","**edit item :: synergy"],
38-
"cde15d85-15fa-4303-ac63-041c73497bcf" : ["turnkey","**edit item :: turnkey"],
39-
"1dfb8b9c-3376-4afa-bd7f-6707456f2b34" : ["utilization","**edit item :: utilization"],
2+
"7a548216-9301-43d1-af5b-77cc976a0eed" : ["actionable","**edit item :: actionable **"],
3+
"9bd390f6-2258-4240-a07d-cb3c6a216d32" : ["agreeance","**edit item :: agreeance **"],
4+
"3ce7f957-470a-4b08-a182-9522ab8858c1" : ["bandwidth","**edit item :: bandwidth **"],
5+
"c54911a5-b4c6-4414-a7c8-0868e897f966" : ["client-centered","**edit item :: client-centered **"],
6+
"164d20ed-6fc7-4010-bef2-09ade126b620" : ["CYA","**edit item :: CYA **"],
7+
"3dd40bc4-1e0f-46e9-9089-39a359686199" : ["going forward","**edit item :: going forward **"],
8+
"e0784322-bed2-425b-97df-f5fd48b01e63" : ["go rogue","**edit item :: go rogue **"],
9+
"e7001580-e2b9-4c48-b351-e62a723c26a9" : ["guesstimate","**edit item :: guesstimate **"],
10+
"b0bf2b70-d2df-4a4a-8880-db1dc6d7ed9e" : ["impact","**edit item :: impact **"],
11+
"ec515601-5aa9-4b4a-80ab-6345fb1eb73b" : ["incent","**edit item :: incent **"],
12+
"ecf801a1-7115-4dc6-ba7f-18aea6c2a3bc" : ["incentivize","**edit item :: incentivize **"],
13+
"317c9986-0817-4863-b2eb-389c8e2db71b" : ["impactful","**edit item :: impactful **"],
14+
"7193d135-7f14-4541-8e8b-04d64d1c36ad" : ["leverage","**edit item :: leverage **"],
15+
"086040a3-8240-4a9b-bc8c-55562fe77aa1" : ["liaise","**edit item :: liaise **"],
16+
"97873513-46d1-4352-85fd-24bd24bd9773" : ["mission-critical","**edit item :: mission-critical **"],
17+
"dd188923-2d91-48ca-bae0-b081e0b159d4" : ["monetize","**edit item :: monetize **"],
18+
"2bf760c2-b4d7-44eb-b248-27a213d35ce8" : ["net-net","**edit item :: net-net **"],
19+
"61dadc35-bd21-4ecf-b2b3-c984d09a1f64" : ["operationalize","**edit item :: operationalize **"],
20+
"caca5a35-5206-4088-8ac3-7675ee83018d" : ["optimize","**edit item :: optimize **"],
21+
"e5b977e6-9e47-4e0c-aee1-2109062f1bf3" : ["paradigm","**edit item :: paradigm **"],
22+
"0f44c71e-592a-498d-a402-31a8e479164f" : ["parameters","**edit item :: parameters **"],
23+
"d2a1fe8f-b3fe-4d41-8eb3-97999665cce5" : ["planfu","**edit item :: planfu **"],
24+
"a4871fd0-630e-4739-8d5f-222381ffc94f" : ["pursuant","**edit item :: pursuant **"],
25+
"b03dae0a-02ce-4185-bc79-103d775c0b37" : ["recontextualize","**edit item :: recontextualize **"],
26+
"1ce02721-02d3-4236-a73e-51da03aacbc1" : ["repurpose","**edit item :: repurpose **"],
27+
"f83176fe-3c88-4fe5-a1ed-77dcf3773f81" : ["rightsized","**edit item :: rightsized **"],
28+
"49ce5f29-0be3-4c63-92dc-6cebf4acb545" : ["sacred cow","**edit item :: sacred cow **"],
29+
"164abeb6-2ac7-4e0a-ac43-1745e44f39f3" : ["scalable","**edit item :: scalable **"],
30+
"89ecc5d0-da96-44a8-887d-71b5d8bbeb91" : ["seamless","**edit item :: seamless **"],
31+
"c2999f2f-3e45-4b00-8db3-019918b60d4e" : ["seismic","**edit item :: seismic **"],
32+
"f8b1dedf-b1a4-42c3-be88-7edf4cfa380d" : ["smartsized","**edit item :: smartsized **"],
33+
"fd511c6c-eb16-4ee8-905c-914b4cd26c96" : ["strategic","**edit item :: strategic **"],
34+
"81a5da6e-502c-4f30-a696-34c9d23eba16" : ["alliance","**edit item :: alliance **"],
35+
"19281354-320d-43ef-841e-0498035cbfd0" : ["dynamism","**edit item :: dynamism "],
36+
"b4ad18fc-3a3d-44b2-8ed7-cfb5ab9cbe37" : ["synergize","**edit item :: synergize **"],
37+
"2796c91e-8734-4e3e-afeb-ac440ae26f07" : ["synergy","**edit item :: synergy **"],
38+
"cde15d85-15fa-4303-ac63-041c73497bcf" : ["turnkey","**edit item :: turnkey **"],
39+
"1dfb8b9c-3376-4afa-bd7f-6707456f2b34" : ["utilization","**edit item :: utilization **"],
4040
"04e2f429-b5fc-4c2f-8d1e-6b71cc01ea28" : ["utilize","**edit item :: utilize"],
41-
"ea4323d3-6b15-4632-bde4-25bc93fc7fa7" : ["value-added","**edit item :: value-added"],
42-
"598d65fa-354e-4526-bdb5-df6f740ab2c4" : ["verbage","**edit item :: verbage"],
43-
"7ac142b6-1669-4b2c-983b-fa3b75935df5" : ["win-win","**edit item :: win-win"]
41+
"ea4323d3-6b15-4632-bde4-25bc93fc7fa7" : ["value-added","**edit item :: value-added **"],
42+
"598d65fa-354e-4526-bdb5-df6f740ab2c4" : ["verbage","**edit item :: verbage **"],
43+
"7ac142b6-1669-4b2c-983b-fa3b75935df5" : ["win-win","**edit item :: win-win **"]
4444
}

students/briggsm/Term2_project/baselinter/baselinter/dummy-txt-2018-02-20.txt

Whitespace-only changes.

students/briggsm/Term2_project/baselinter/baselinter/loco.py

Lines changed: 0 additions & 8 deletions
This file was deleted.

students/briggsm/Term2_project/baselinter/baselinter/test/baselinter_.py renamed to students/briggsm/Term2_project/baselinter/baselinter/test/baselinter_test.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
11
'''Test for BaseLinter'''
22

33
import json
4+
import os
45
import datetime
56
import mock
6-
import baselinter as BL
7+
import baselinter.baselinter as BS
78

89
def test_open_set_json():
910
'''Function returns a list of sets from a json file.'''
10-
list_of_sets = BL.open_set_json("dummy-data.json")
11+
list_of_sets = BS.open_set_json(os.path.dirname(BS.__file__) + "\\test\\dummy-data.json")
1112

12-
assert type(list_of_sets) == list
13-
assert type(list_of_sets[0]) == set
14-
assert list_of_sets[1] == {"mole", "vole"}
13+
assert {"mole","vole"} == list_of_sets[0]
1514

1615
def test_text_to_list():
1716
'''Function returns from a filename a list of words in order.'''
18-
wordlist = BL.text_to_list("dummy-text.txt")
17+
wordlist = BS.text_to_list(os.path.dirname(BS.__file__) + "\\test\\dummy-text.txt")
1918

2019
assert len(wordlist) == 413
2120
assert wordlist[0] == "We"
@@ -24,7 +23,7 @@ def test_text_to_list():
2423
def test_wordlist_to_text():
2524
'''Function returns from a list of words in order a single string.'''
2625
test_list = ['We', 'got', 'up', 'at', 'four', 'in', 'the', 'morning,', 'that', 'first', 'day', 'in', 'the', 'east.']
27-
out_text = BL.wordlist_to_text(test_list)
26+
out_text = BS.wordlist_to_text(test_list)
2827

2928
assert out_text == "We got up at four in the morning, that first day in the east."
3029

@@ -33,8 +32,8 @@ def test_return_members():
3332
'''Function returns the set of an item if a member of the set, otherwise returns None.'''
3433
test_set = [{"that1", "that2", "that3"},{"mole", "vole"}]
3534

36-
assert BL.return_members(test_set, "mole") == {"mole", "vole"}
37-
assert BL.return_members(test_set, "fig") == None
35+
assert BS.return_members(test_set, "mole") == {"mole", "vole"}
36+
assert BS.return_members(test_set, "fig") == None
3837

3938
def test_select_update():
4039
'''Function returns an updated list'''
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
{ "1A8C5C98-3306-4068-8CA8-302F3EF49A62": ["mole","vole"],
2+
"61CA4EB1-E9C7-4913-8484-C6A26A594E61": ["marmot","lemming"] }
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
We got up at four in the morning, that first day in the east. On the
2+
evening before we had climbed off a freight train at the edge of town,
3+
and with the true instinct of Kentucky boys had found our way across
4+
town and to the race track and the stables at once. Then we knew we
5+
were all right. Hanley Turner right away found a nigger we knew. It was
6+
Bildad Johnson who in the winter works at Ed Becker's livery barn in
7+
our home town, Beckersville. Bildad is a good cook as almost all our
8+
niggers are and of course he, like everyone in our part of Kentucky who
9+
is anyone at all, likes the horses. In the spring Bildad begins to
10+
scratch around. A nigger from our country can flatter and wheedle
11+
anyone into letting him do most anything he wants. Bildad wheedles the
12+
stable men and the trainers from the horse farms in our country around
13+
Lexington. The trainers come into town in the evening to stand around
14+
and talk and maybe get into a poker game. Bildad gets in with them. He
15+
is always doing little favors and telling about things to eat, chicken
16+
browned in a pan, and how is the best way to cook sweet potatoes and
17+
corn bread. It makes your mouth water to hear him.
18+
19+
When the racing season comes on and the horses go to the races and
20+
there is all the talk on the streets in the evenings about the new
21+
colts, and everyone says when they are going over to Lexington or to
22+
the spring meeting at Churchhill Downs or to Latonia, and the horsemen
23+
that have been down to New Orleans or maybe at the winter meeting at
24+
Havana in Cuba come home to spend a week before they start out again,
25+
at such a time when everything talked about in Beckersville is just
26+
horses and nothing else and the outfits start out and horse racing is
27+
in every breath of air you breathe, Bildad shows up with a job as cook
28+
for some outfit. Often when I think about it, his always going all
29+
season to the races and working in the livery barn in the winter where
30+
horses are and where men like to come and talk about horses, I wish I
31+
was a nigger. It's a foolish thing to say, but that's the way I am
32+
about being around horses, just crazy. I can't help it.

0 commit comments

Comments
 (0)