-
Notifications
You must be signed in to change notification settings - Fork 270
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
refactor/scoped session fix #151
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Glad to have the tests! Let's just comment code significantly more? Even with self-descriptive function names, much easier to onboard folks when the "why" behind blocks if code is spelled out explicitly, particularly since most of team only writes code part-time.
src/cs50/_logger.py
Outdated
|
||
def _setup_logger(): | ||
# Configure default logging handler and formatter | ||
# Prevent flask, werkzeug, etc from adding default handler |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be docstring, no?
except IndexError: | ||
pass | ||
|
||
_logger = logging.getLogger("cs50") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's not have uncommented blocks of code.
return paramstyle, placeholders | ||
|
||
|
||
def _default_paramstyle(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Docstring
|
||
|
||
def _bind_numeric(self, placeholders, tokens): | ||
unused_arg_indices = set(range(len(self._args))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
comment
src/cs50/_statement.py
Outdated
return token.ttype == sqlparse.tokens.Literal.String.Symbol | ||
|
||
|
||
class _Paramstyle(enum.Enum): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's this do?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just an enum of the different paramstyle types that are supported so we don't have to hardcode "qmark"
, "numeric"
, etc and if we add or change types, their names are checked for (e.g., for misspellings).
if user_input is None: | ||
return None | ||
|
||
if re.search(r"^[+-]?\d+$", user_input): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
comment
@patch("cs50.cs50.get_string", return_value=None) | ||
def test_get_int_eof(self, mock_get_string): | ||
"""Returns None on EOF""" | ||
self.assertIs(_get_int("Answer: "), None) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How does this know to send EOF?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we're just testing get_int
here, we can assume that get_string
is working correctly. In this particular test, we're assuming that get_string
returns None
on EOF, which we know should be the case. And so the patch
decorator here replaces get_string
with a mock implementation that just returns None
. And the test is just making sure that get_int
also returns None
in this case.
the IDE proxy now handles forcing https
This reverts commit 006657e.
Executing a SQL statement in
SQL
's constructor creates a db session that may not be cleanly removed in some Flask threads (e.g., when the Flask reloader is enabled). This causes aProgrammingError
exception to be raised when the Flask reloader kills the server process to reload the app:Instead of relying on
flask.current_app
which is only set when an app context is pushed, theSQL
class now exposesinit_app
, which can be passed a Flask app instance to set up anteardown_appcontext
listener to remove the session.This PR also includes some refactoring to improve the readability, maintainability, and testability of the library and adds tests for the
get_*
functions. More tests to come.