Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pylint code cleanup #26

Merged
merged 1 commit into from
Oct 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 4 additions & 41 deletions autostack/__tests__/test_main.py
Original file line number Diff line number Diff line change
@@ -1,53 +1,16 @@
'''
Authors: Elijah Sawyers, Benjamin Sanders
Emails: elijahsawyers@gmail.com, ben.sanders97@gmail.com
Date: 07/23/2019
Overview: Tests for the main functionality.
TODO:
'''

import os
from threading import Thread
from unittest import mock

import pytest

from autostack.main import main


# ======================================================================
# Mock input
# ======================================================================


# ======================================================================
# Tests for main
# ======================================================================

def test_main_input_y():
'''
Test to ensure that, when an error is detected, inputting
'Y' exits the post query loop.
'''

# 1. Given.

# 2. When.

# 3. Then.

pass


def test_main_input_n():
def test_placeholder():
'''
Test to ensure that, when an error is detected, inputting
'n' continues the post query loop.
TODO: Write docstring.
'''

# 1. Given.

# 2. When.

# 3. Then.

pass
assert True
20 changes: 13 additions & 7 deletions autostack/error/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,15 @@ def parse_output_for_error(output, pipe):
'''

try:
if output.split()[0][:-1] in SYNTAX_ERRORS: # Syntax errors - no traceback.
# Syntax errors - no traceback.
if output.split()[0][:-1] in SYNTAX_ERRORS:
error = output.split()[0]
handle_exception(error)
elif 'Traceback' in output.split(): # Runtime error - has traceback.
# Runtime error - has traceback.
elif 'Traceback' in output.split():
error = get_error_from_traceback(pipe)
handle_exception(error)
except:
except IndexError:
pass


Expand All @@ -63,7 +65,7 @@ def get_error_from_traceback(pipe):
output = pipe.readline()

while (
output.split()[0][-1] != ':'
output.split()[0][-1] != ':'
):
output = pipe.readline()

Expand Down Expand Up @@ -97,14 +99,18 @@ def error_solved():
print('Did this solve your error? (Y/n): ', end='')
is_error_solved = input()

if not is_error_solved in ('Y', 'n'):
print('{} is not valid input! Please try again.'.format(is_error_solved))
if is_error_solved not in ('Y', 'n'):
print(
'{} is not valid input! Please try again.'.format(
is_error_solved
)
)
else:
break

if is_error_solved == 'n':
return False

return True


Expand Down
16 changes: 16 additions & 0 deletions autostack/error/__tests__/test_error.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
'''
TODO: Write docstring.
'''


def test_placeholder():
'''
TODO: Write docstring.
'''

# 1. Given.

# 2. When.

# 3. Then.
assert True
3 changes: 2 additions & 1 deletion autostack/pipe/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import os


def create_pipe(path):
'''
TODO: Write docstring.
Expand All @@ -19,7 +20,7 @@ def create_pipe(path):

if not os.path.exists(leaf_dir_path):
os.makedirs(leaf_dir_path)

try:
os.mkfifo(path)
except FileExistsError:
Expand Down
16 changes: 16 additions & 0 deletions autostack/pipe/__tests__/test_pipe.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
'''
TODO: Write docstring.
'''


def test_placeholder():
''''
TODO: Write docstring.
'''

# 1. Given.

# 2. When.

# 3. Then.
assert True
41 changes: 20 additions & 21 deletions autostack/so_web_scraper/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ def accepted_posts(query):
TODO: Write docstring.
'''

for post_summary in get_post_summaries(query):
post = post_soup(post_summary)

if post:
yield post
for result_set in get_post_summaries(query):
for post_summary in result_set:
post = post_soup(post_summary)

if post:
yield post


def get_post_summaries(query):
Expand All @@ -51,7 +52,7 @@ def get_post_summaries(query):
if not post_summaries:
break

return post_summaries
yield post_summaries

page += 1

Expand Down Expand Up @@ -80,7 +81,7 @@ def query_stack_overflow(url):
try:
response = requests.get(url)
response.raise_for_status()
except:
except requests.exceptions.HTTPError:
return None

return BeautifulSoup(response.text, 'lxml')
Expand All @@ -96,13 +97,11 @@ def post_soup(post_summary):

try:
response = requests.get(BASE_URL + post_url)
except:
except requests.exceptions.HTTPError:
return None

post_soup = BeautifulSoup(response.text, 'lxml')

return post_soup
return BeautifulSoup(response.text, 'lxml')

return None


Expand Down Expand Up @@ -135,7 +134,7 @@ def get_post_url(post_summary):
},
href=True
)['href']
except:
except KeyError:
return None


Expand Down Expand Up @@ -229,12 +228,12 @@ def print_post_text(post_text):
print_code_block(element.find('code'))


def print_ul(ul):
def print_ul(ul_element):
'''
TODO: Write docstring.
'''

for item in ul.find_all('li'):
for item in ul_element.find_all('li'):
print(
colored(' - ' + item.text, 'green', attrs=['bold'])
)
Expand Down Expand Up @@ -289,6 +288,7 @@ def print_code_block(code_block):

print('')


def get_src_code(code_block):
'''
TODO: Write docstring.
Expand All @@ -303,14 +303,13 @@ def get_src_code(code_block):
code += token
except TypeError:
code += get_nested_src_code(token)

return code


def get_nested_src_code(token):
code = ''
'''
TODO: Write docstring.
'''

for nestedToken in token.contents:
code += nestedToken

return code
return ''.join(token.contents)
Loading