Skip to content

Commit

Permalink
[misc] Fix flake8 warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
slarse committed Sep 12, 2019
1 parent e1564a2 commit 51ea718
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 21 deletions.
2 changes: 2 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[flake8]
ignore = W503,E203
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[tool.black]
line-length = 79
target-version = ['py34']
4 changes: 1 addition & 3 deletions repobee_feedback/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@


from .__version import __version__
from .__version import __version__ # noqa: F401
24 changes: 15 additions & 9 deletions repobee_feedback/feedback.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
student repos and opens them as issues on the issue tracker.
.. module:: feedback
:synopsis: A RepoBee plugin that finds issue files in student repos and opens them on their issue trackers
:synopsis: A RepoBee plugin that finds issue files in student repos and
opens them on their issue trackers
.. moduleauthor:: Simon Larsén
"""
import pathlib
import os
import re
import sys
import argparse
from typing import Union, Iterable, Tuple, List
from typing import Iterable, Tuple, List

import daiquiri
import repobee_plug as plug
Expand All @@ -24,7 +24,9 @@


def callback(args: argparse.Namespace, api: plug.API) -> None:
repo_names = plug.generate_repo_names(args.students, args.master_repo_names)
repo_names = plug.generate_repo_names(
args.students, args.master_repo_names
)
if "multi_issues_file" in args:
issues_file = pathlib.Path(args.multi_issues_file).resolve()
issues = _parse_multi_issues_file(issues_file)
Expand Down Expand Up @@ -108,7 +110,9 @@ def _ask_for_open(issue: plug.Issue, repo_name: str) -> bool:
)
)
return (
input('Open issue "{}" in repo {}? (y/n) '.format(issue.title, repo_name))
input(
'Open issue "{}" in repo {}? (y/n) '.format(issue.title, repo_name)
)
== "y"
)

Expand All @@ -125,7 +129,6 @@ def _collect_issues(
repo_names: Iterable[str], issues_dir: pathlib.Path
) -> Iterable[Tuple[str, plug.Issue]]:
issues = []
md_files = list(issues_dir.glob("*.md"))
for repo_name in repo_names:
expected_file = issues_dir / "{}.md".format(repo_name)
if expected_file.is_file():
Expand All @@ -142,12 +145,15 @@ def _read_issue(issue_path: pathlib.Path) -> plug.Issue:
def _parse_multi_issues_file(
issues_file: pathlib.Path
) -> Iterable[Tuple[str, plug.Issue]]:
repos_and_issues = []
with open(str(issues_file), mode="r", encoding=sys.getdefaultencoding()) as file:
with open(
str(issues_file), mode="r", encoding=sys.getdefaultencoding()
) as file:
lines = list(file.readlines())

if not lines or not re.match(BEGIN_ISSUE_PATTERN, lines[0], re.IGNORECASE):
raise plug.PlugError("first line of multi issues file not #ISSUE# line")
raise plug.PlugError(
"first line of multi issues file not #ISSUE# line"
)

issue_blocks = _extract_issue_blocks(lines)
return list(_extract_issues(issue_blocks, lines))
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
setup(
name="repobee-feedback",
version=__version__,
description="A RepoBee plugin that finds issue files in student repos and opens them on their issue trackers",
description="A plugin that adds the issue-feedback command to RepoBee",
long_description=readme,
long_description_content_type="text/markdown",
author="Simon Larsén",
Expand Down
Binary file removed tests/__pycache__/test_feedback.cpython-37-PYTEST.pyc
Binary file not shown.
21 changes: 13 additions & 8 deletions tests/test_feedback.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import sys
import pathlib
import random
import builtins
from unittest import mock

import pytest
Expand All @@ -24,7 +23,9 @@
KOMP_ISSUE = plug.Issue(
title="Komplettering", body="Not perfect, you need to fix this."
)
FAIL_ISSUE = plug.Issue(title="Fail", body="Unfortunately, there are severe errors.")
FAIL_ISSUE = plug.Issue(
title="Fail", body="Unfortunately, there are severe errors."
)
ISSUES = (PASS_ISSUE, KOMP_ISSUE, FAIL_ISSUE)

random.seed(512)
Expand Down Expand Up @@ -82,7 +83,9 @@ def with_issues(tmp_path):
"""Create issue files in a temporary directory and return a list of (team,
issue) tuples.
"""
repo_names = plug.generate_repo_names(STUDENT_TEAM_NAMES, MASTER_REPO_NAMES)
repo_names = plug.generate_repo_names(
STUDENT_TEAM_NAMES, MASTER_REPO_NAMES
)
existing_issues = []
for repo_name in repo_names:
issue_file = tmp_path / "{}.md".format(repo_name)
Expand All @@ -95,8 +98,12 @@ def with_issues(tmp_path):
@pytest.fixture
def with_multi_issues_file(tmp_path):
"""Create the multi issues file."""
repo_names = plug.generate_repo_names(STUDENT_TEAM_NAMES, MASTER_REPO_NAMES)
repos_and_issues = [(repo_name, random.choice(ISSUES)) for repo_name in repo_names]
repo_names = plug.generate_repo_names(
STUDENT_TEAM_NAMES, MASTER_REPO_NAMES
)
repos_and_issues = [
(repo_name, random.choice(ISSUES)) for repo_name in repo_names
]
issues_file = tmp_path / "issues.md"
_write_multi_issues_file(repos_and_issues, issues_file)
return issues_file, repos_and_issues
Expand Down Expand Up @@ -164,9 +171,7 @@ def test_opens_nothing_if_open_prompt_returns_false(
args_dict["batch_mode"] = False
parsed_args_interactive = argparse.Namespace(**args_dict)

with mock.patch(
"builtins.input", return_value="n", autospec=True
) as input_mock:
with mock.patch("builtins.input", return_value="n", autospec=True):
feedback.callback(args=parsed_args_interactive, api=api_mock)

assert not api_mock.open_issue.called
Expand Down

0 comments on commit 51ea718

Please sign in to comment.