ruff: Fix N806 Variable in function should be lowercase.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg 2023-10-30 10:34:57 -07:00
parent 5e708e3661
commit 87e7d31403
17 changed files with 92 additions and 90 deletions

View file

@ -284,11 +284,11 @@ def run_mirror() -> None:
since = default_since()
try:
sleepInterval = 1
sleep_interval = 1
while True:
events = make_api_call("activity")
if events is not None:
sleepInterval = 1
sleep_interval = 1
for event in events[::-1]:
timestamp = event.get("event", {}).get("timestamp", "")
event_date = dateutil.parser.parse(timestamp)
@ -297,9 +297,9 @@ def run_mirror() -> None:
since = event_date
else:
# back off a bit
if sleepInterval < 22:
sleepInterval += 4
time.sleep(sleepInterval)
if sleep_interval < 22:
sleep_interval += 4
time.sleep(sleep_interval)
except KeyboardInterrupt:
open(config.RESUME_FILE, "w").write(since.strftime("%s"))

View file

@ -166,9 +166,9 @@ def unwrap_text(body: str) -> str:
def elide_subject(subject: str) -> str:
MAX_TOPIC_LENGTH = 60
if len(subject) > MAX_TOPIC_LENGTH:
subject = subject[: MAX_TOPIC_LENGTH - 3].rstrip() + "..."
max_topic_length = 60
if len(subject) > max_topic_length:
subject = subject[: max_topic_length - 3].rstrip() + "..."
return subject

View file

@ -52,7 +52,7 @@ class ConnectFourBotHandler(GameAdapter):
)
move_regex = "(move ([1-7])$)|(([1-7])$)"
model = ConnectFourModel
gameMessageHandler = ConnectFourMessageHandler
game_message_handler = ConnectFourMessageHandler
rules = """Try to get four pieces in row, Diagonals count too!"""
super().__init__(
@ -61,7 +61,7 @@ class ConnectFourBotHandler(GameAdapter):
move_help_message,
move_regex,
model,
gameMessageHandler,
game_message_handler,
rules,
max_players=2,
)

View file

@ -130,13 +130,13 @@ The first player to get 4 in a row wins!\n Good Luck!",
def confirm_available_moves(
good_moves: List[int], bad_moves: List[int], board: List[List[int]]
) -> None:
connectFourModel.update_board(board)
connect_four_model.update_board(board)
for move in good_moves:
self.assertTrue(connectFourModel.validate_move(move))
self.assertTrue(connect_four_model.validate_move(move))
for move in bad_moves:
self.assertFalse(connectFourModel.validate_move(move))
self.assertFalse(connect_four_model.validate_move(move))
def confirm_move(
column_number: int,
@ -144,14 +144,14 @@ The first player to get 4 in a row wins!\n Good Luck!",
initial_board: List[List[int]],
final_board: List[List[int]],
) -> None:
connectFourModel.update_board(initial_board)
test_board = connectFourModel.make_move("move " + str(column_number), token_number)
connect_four_model.update_board(initial_board)
test_board = connect_four_model.make_move("move " + str(column_number), token_number)
self.assertEqual(test_board, final_board)
def confirm_game_over(board: List[List[int]], result: str) -> None:
connectFourModel.update_board(board)
game_over = connectFourModel.determine_game_over(["first_player", "second_player"])
connect_four_model.update_board(board)
game_over = connect_four_model.determine_game_over(["first_player", "second_player"])
self.assertEqual(game_over, result)
@ -162,7 +162,7 @@ The first player to get 4 in a row wins!\n Good Luck!",
for board in array[1]:
confirm_game_over(board, "second_player")
connectFourModel = ConnectFourModel()
connect_four_model = ConnectFourModel()
# Basic Board setups
blank_board = [
@ -433,14 +433,14 @@ The first player to get 4 in a row wins!\n Good Luck!",
confirm_available_moves([0, 1, 2, 3, 4, 5], [6], diagonal_board)
# Test Available Move Logic
connectFourModel.update_board(blank_board)
self.assertEqual(connectFourModel.available_moves(), [0, 1, 2, 3, 4, 5, 6])
connect_four_model.update_board(blank_board)
self.assertEqual(connect_four_model.available_moves(), [0, 1, 2, 3, 4, 5, 6])
connectFourModel.update_board(single_column_board)
self.assertEqual(connectFourModel.available_moves(), [3])
connect_four_model.update_board(single_column_board)
self.assertEqual(connect_four_model.available_moves(), [3])
connectFourModel.update_board(full_board)
self.assertEqual(connectFourModel.available_moves(), [])
connect_four_model.update_board(full_board)
self.assertEqual(connect_four_model.available_moves(), [])
# Test Move Logic
confirm_move(

View file

@ -14,7 +14,7 @@ class FileUploaderHandler:
)
def handle_message(self, message: Dict[str, str], bot_handler: BotHandler) -> None:
HELP_STR = (
help_str = (
"Use this bot with any of the following commands:"
"\n* `@uploader <local_file_path>` : Upload a file, where `<local_file_path>` is the path to the file"
"\n* `@uploader help` : Display help message"
@ -22,7 +22,7 @@ class FileUploaderHandler:
content = message["content"].strip()
if content == "help":
bot_handler.send_reply(message, HELP_STR)
bot_handler.send_reply(message, help_str)
return
path = Path(os.path.expanduser(content))

View file

@ -50,7 +50,7 @@ class GameHandlerBotHandler(GameAdapter):
move_help_message = "* To make your move during a game, type\n```move <column-number>```"
move_regex = r"move (\d)$"
model = MockModel
gameMessageHandler = GameHandlerBotMessageHandler
game_message_handler = GameHandlerBotMessageHandler
rules = ""
super().__init__(
@ -59,7 +59,7 @@ class GameHandlerBotHandler(GameAdapter):
move_help_message,
move_regex,
model,
gameMessageHandler,
game_message_handler,
rules,
max_players=2,
supports_computer=True,

View file

@ -130,7 +130,7 @@ class GameOfFifteenBotHandler(GameAdapter):
)
move_regex = r"move [\d{1}\s]+$"
model = GameOfFifteenModel
gameMessageHandler = GameOfFifteenMessageHandler
game_message_handler = GameOfFifteenMessageHandler
rules = """Arrange the boards tiles from smallest to largest, left to right,
top to bottom, and tiles adjacent to :grey_question: can only be moved.
Final configuration will have :grey_question: in top left."""
@ -141,7 +141,7 @@ class GameOfFifteenBotHandler(GameAdapter):
move_help_message,
move_regex,
model,
gameMessageHandler,
game_message_handler,
rules,
min_players=1,
max_players=1,

View file

@ -59,7 +59,9 @@ class TestGameOfFifteenBot(BotTestCase, DefaultTests):
board = "\n\n:grey_question::one::two:\n\n:three::four::five:\n\n:six::seven::eight:"
bot, bot_handler = self._get_handlers()
self.assertEqual(bot.game_message_handler.parse_board(self.winning_board), board)
self.assertEqual(bot.game_message_handler.alert_move_message("foo", "move 1"), "foo moved 1")
self.assertEqual(
bot.game_message_handler.alert_move_message("foo", "move 1"), "foo moved 1"
)
self.assertEqual(
bot.game_message_handler.game_start_message(),
"Welcome to Game of Fifteen!"
@ -72,12 +74,12 @@ class TestGameOfFifteenBot(BotTestCase, DefaultTests):
def confirm_available_moves(
good_moves: List[int], bad_moves: List[int], board: List[List[int]]
) -> None:
gameOfFifteenModel.update_board(board)
game_of_fifteen_model.update_board(board)
for move in good_moves:
self.assertTrue(gameOfFifteenModel.validate_move(move))
self.assertTrue(game_of_fifteen_model.validate_move(move))
for move in bad_moves:
self.assertFalse(gameOfFifteenModel.validate_move(move))
self.assertFalse(game_of_fifteen_model.validate_move(move))
def confirm_move(
tile: str,
@ -85,23 +87,23 @@ class TestGameOfFifteenBot(BotTestCase, DefaultTests):
initial_board: List[List[int]],
final_board: List[List[int]],
) -> None:
gameOfFifteenModel.update_board(initial_board)
test_board = gameOfFifteenModel.make_move("move " + tile, token_number)
game_of_fifteen_model.update_board(initial_board)
test_board = game_of_fifteen_model.make_move("move " + tile, token_number)
self.assertEqual(test_board, final_board)
def confirm_game_over(board: List[List[int]], result: str) -> None:
gameOfFifteenModel.update_board(board)
game_over = gameOfFifteenModel.determine_game_over(["first_player"])
game_of_fifteen_model.update_board(board)
game_over = game_of_fifteen_model.determine_game_over(["first_player"])
self.assertEqual(game_over, result)
def confirm_coordinates(board: List[List[int]], result: Dict[int, Tuple[int, int]]) -> None:
gameOfFifteenModel.update_board(board)
coordinates = gameOfFifteenModel.get_coordinates(board)
game_of_fifteen_model.update_board(board)
coordinates = game_of_fifteen_model.get_coordinates(board)
self.assertEqual(coordinates, result)
gameOfFifteenModel = GameOfFifteenModel()
game_of_fifteen_model = GameOfFifteenModel()
# Basic Board setups
initial_board = [[8, 7, 6], [5, 4, 3], [2, 1, 0]]

View file

@ -115,20 +115,20 @@ def entries_list(team_name: str) -> str:
def create_entry(message: str) -> str:
SINGLE_WORD_REGEX = re.compile("--team=([a-zA-Z0-9_]*)")
MULTIWORD_REGEX = re.compile('"--team=([^"]*)"')
single_word_regex = re.compile("--team=([a-zA-Z0-9_]*)")
multiword_regex = re.compile('"--team=([^"]*)"')
team = ""
new_message = ""
single_word_match = SINGLE_WORD_REGEX.search(message)
multiword_match = MULTIWORD_REGEX.search(message)
single_word_match = single_word_regex.search(message)
multiword_match = multiword_regex.search(message)
if multiword_match is not None:
team = multiword_match.group(1)
new_message = MULTIWORD_REGEX.sub("", message).strip()
new_message = multiword_regex.sub("", message).strip()
elif single_word_match is not None:
team = single_word_match.group(1)
new_message = SINGLE_WORD_REGEX.sub("", message).strip()
new_message = single_word_regex.sub("", message).strip()
elif default_team:
team = default_team
new_message = message

View file

@ -74,14 +74,14 @@ class TestIDoneThisBot(BotTestCase, DefaultTests):
{"api_key": "12345678", "default_team": "testing team 1"}
), self.mock_http_conversation("test_show_team"), patch(
"zulip_bots.bots.idonethis.idonethis.get_team_hash", return_value="31415926535"
) as get_team_hashFunction:
) as get_team_hash_function:
self.verify_reply(
"team info testing team 1",
"Team Name: testing team 1\n"
"ID: `31415926535`\n"
"Created at: 2017-12-28T19:12:55.121+11:00",
)
get_team_hashFunction.assert_called_with("testing team 1")
get_team_hash_function.assert_called_with("testing team 1")
def test_entries_list(self) -> None:
with self.mock_config_info(

View file

@ -180,7 +180,7 @@ class JiraHandler:
self.display_url = self.domain_with_protocol
def jql_search(self, jql_query: str) -> str:
UNKNOWN_VAL = "*unknown*"
unknown_val = "*unknown*"
jira_response = requests.get(
self.domain_with_protocol
+ f"/rest/api/2/search?jql={jql_query}&fields=key,summary,status",
@ -197,8 +197,8 @@ class JiraHandler:
response = f"*Found {results} results*\n\n"
for issue in jira_response.get("issues", []):
fields = issue.get("fields", {})
summary = fields.get("summary", UNKNOWN_VAL)
status_name = fields.get("status", {}).get("name", UNKNOWN_VAL)
summary = fields.get("summary", unknown_val)
status_name = fields.get("status", {}).get("name", unknown_val)
response += "\n - {}: [{}]({}) **[{}]**".format(
issue["key"], summary, url + issue["key"], status_name
)
@ -217,7 +217,7 @@ class JiraHandler:
help_match = HELP_REGEX.match(content)
if get_match:
UNKNOWN_VAL = "*unknown*"
unknown_val = "*unknown*"
key = get_match.group("issue_key")
@ -230,13 +230,13 @@ class JiraHandler:
errors = jira_response.get("errorMessages", [])
fields = jira_response.get("fields", {})
creator_name = fields.get("creator", {}).get("name", UNKNOWN_VAL)
description = fields.get("description", UNKNOWN_VAL)
priority_name = fields.get("priority", {}).get("name", UNKNOWN_VAL)
project_name = fields.get("project", {}).get("name", UNKNOWN_VAL)
type_name = fields.get("issuetype", {}).get("name", UNKNOWN_VAL)
status_name = fields.get("status", {}).get("name", UNKNOWN_VAL)
summary = fields.get("summary", UNKNOWN_VAL)
creator_name = fields.get("creator", {}).get("name", unknown_val)
description = fields.get("description", unknown_val)
priority_name = fields.get("priority", {}).get("name", unknown_val)
project_name = fields.get("project", {}).get("name", unknown_val)
type_name = fields.get("issuetype", {}).get("name", unknown_val)
status_name = fields.get("status", {}).get("name", unknown_val)
summary = fields.get("summary", unknown_val)
if errors:
response = "Oh no! Jira raised an error:\n > " + ", ".join(errors)

View file

@ -39,7 +39,7 @@ class LinkShortenerHandler:
)
def handle_message(self, message: Dict[str, str], bot_handler: BotHandler) -> None:
REGEX_STR = (
regex_str = (
r"("
r"(?:http|https):\/\/" # This allows for the HTTP or HTTPS
# protocol.
@ -48,7 +48,7 @@ class LinkShortenerHandler:
r")"
)
HELP_STR = (
help_str = (
"Mention the link shortener bot in a conversation and "
"then enter any URLs you want to shorten in the body of "
"the message."
@ -57,10 +57,10 @@ class LinkShortenerHandler:
content = message["content"]
if content.strip() == "help":
bot_handler.send_reply(message, HELP_STR)
bot_handler.send_reply(message, help_str)
return
link_matches = re.findall(REGEX_STR, content)
link_matches = re.findall(regex_str, content)
shortened_links = [self.shorten_link(link) for link in link_matches]
link_pairs = [
@ -71,7 +71,7 @@ class LinkShortenerHandler:
final_response = "\n".join(link_pairs)
if final_response == "":
bot_handler.send_reply(message, "No links found. " + HELP_STR)
bot_handler.send_reply(message, "No links found. " + help_str)
return
bot_handler.send_reply(message, final_response)

View file

@ -88,14 +88,14 @@ class MerelsHandler(GameAdapter):
move_regex = ".*"
model = MerelsModel
rules = game.get_info()
gameMessageHandler = MerelsMessageHandler
game_message_handler = MerelsMessageHandler
super().__init__(
game_name,
bot_name,
move_help_message,
move_regex,
model,
gameMessageHandler,
game_message_handler,
rules,
max_players=2,
min_players=2,

View file

@ -62,25 +62,25 @@ class CheckIntegrity(unittest.TestCase):
[6, 6],
)
AM = grid_layout
am = grid_layout
relative_hills = (
[AM[0], AM[1], AM[2]],
[AM[3], AM[4], AM[5]],
[AM[6], AM[7], AM[8]],
[AM[9], AM[10], AM[11]],
[AM[12], AM[13], AM[14]],
[AM[15], AM[16], AM[17]],
[AM[18], AM[19], AM[20]],
[AM[21], AM[22], AM[23]],
[AM[0], AM[9], AM[21]],
[AM[3], AM[10], AM[18]],
[AM[6], AM[11], AM[15]],
[AM[1], AM[4], AM[7]],
[AM[16], AM[19], AM[22]],
[AM[8], AM[12], AM[17]],
[AM[5], AM[13], AM[20]],
[AM[2], AM[14], AM[23]],
[am[0], am[1], am[2]],
[am[3], am[4], am[5]],
[am[6], am[7], am[8]],
[am[9], am[10], am[11]],
[am[12], am[13], am[14]],
[am[15], am[16], am[17]],
[am[18], am[19], am[20]],
[am[21], am[22], am[23]],
[am[0], am[9], am[21]],
[am[3], am[10], am[18]],
[am[6], am[11], am[15]],
[am[1], am[4], am[7]],
[am[16], am[19], am[22]],
[am[8], am[12], am[17]],
[am[5], am[13], am[20]],
[am[2], am[14], am[23]],
)
self.assertEqual(constants.HILLS, relative_hills, "Incorrect relative hills arrangement")

View file

@ -25,8 +25,8 @@ class DatabaseTest(BotTestCase, DefaultTests):
self.merels.update_game("topic1", "X", 0, 0, "NNNNNNNNNNNNNNNNNNNNNNNN", "", 0)
self.merels.update_game("topic2", "O", 5, 4, "XXXXOOOOONNNNNNNNNNNNNNN", "", 0)
self.assertTrue(self.storage.contains("topic1"), self.storage.contains("topic2"))
topic2Board = game_data.GameData(self.merels.get_game_data("topic2"))
self.assertEqual(topic2Board.board, "XXXXOOOOONNNNNNNNNNNNNNN")
topic2_board = game_data.GameData(self.merels.get_game_data("topic2"))
self.assertEqual(topic2_board.board, "XXXXOOOOONNNNNNNNNNNNNNN")
def test_remove_game(self):
self.merels.update_game("topic1", "X", 0, 0, "NNNNNNNNNNNNNNNNNNNNNNNN", "", 0)

View file

@ -47,8 +47,8 @@ class TestMerelsBot(BotTestCase, DefaultTests):
def test_parse_board(self) -> None:
board = EMPTY_BOARD
expectResponse = EMPTY_BOARD
self._test_parse_board(board, expectResponse)
expect_response = EMPTY_BOARD
self._test_parse_board(board, expect_response)
def test_add_user_to_cache(self):
self.add_user_to_cache("Name")

View file

@ -280,7 +280,7 @@ class TicTacToeHandler(GameAdapter):
move_help_message = "* To move during a game, type\n`move <number>` or `<number>`"
move_regex = r"(move (\d)$)|((\d)$)"
model = TicTacToeModel
gameMessageHandler = TicTacToeMessageHandler
game_message_handler = TicTacToeMessageHandler
rules = """Try to get three in horizontal or vertical or diagonal row to win the game."""
super().__init__(
game_name,
@ -288,7 +288,7 @@ class TicTacToeHandler(GameAdapter):
move_help_message,
move_regex,
model,
gameMessageHandler,
game_message_handler,
rules,
supports_computer=True,
)