Skip to content

Commit

Permalink
Black changed, reformatting to match
Browse files Browse the repository at this point in the history
Signed-off-by: LilSpazJoekp <15524072+LilSpazJoekp@users.noreply.github.com>
  • Loading branch information
LilSpazJoekp committed Aug 28, 2020
1 parent b0ed590 commit 905e5c9
Show file tree
Hide file tree
Showing 21 changed files with 104 additions and 40 deletions.
4 changes: 3 additions & 1 deletion asyncpraw/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ def parse_exception_list(exceptions: List[Union[RedditErrorItem, List[str]]]):
exception
if isinstance(exception, RedditErrorItem)
else RedditErrorItem(
exception[0], exception[1], exception[2] if bool(exception[2]) else "",
exception[0],
exception[1],
exception[2] if bool(exception[2]) else "",
)
for exception in exceptions
]
Expand Down
5 changes: 4 additions & 1 deletion asyncpraw/models/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,10 @@ def url(
raise MissingRequiredAttributeException("redirect_uri must be provided")
if isinstance(authenticator, UntrustedAuthenticator):
return authenticator.authorize_url(
"temporary" if implicit else duration, scopes, state, implicit=implicit,
"temporary" if implicit else duration,
scopes,
state,
implicit=implicit,
)
if implicit:
raise InvalidImplicitAuth
Expand Down
4 changes: 3 additions & 1 deletion asyncpraw/models/comment_forest.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ async def __aiter__(self) -> AsyncIterator["Comment"]:
yield comment

def __init__(
self, submission: "Submission", comments: Optional[List["Comment"]] = None,
self,
submission: "Submission",
comments: Optional[List["Comment"]] = None,
):
"""Initialize a CommentForest instance.
Expand Down
3 changes: 2 additions & 1 deletion asyncpraw/models/reddit/collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,8 @@ async def delete(self):
"""
await self._reddit.post(
API_PATH["collection_delete"], data={"collection_id": self.collection_id},
API_PATH["collection_delete"],
data={"collection_id": self.collection_id},
)

async def remove_post(self, submission: Submission):
Expand Down
4 changes: 3 additions & 1 deletion asyncpraw/models/reddit/live.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ def _handle_permissions(permissions):
permissions = set(permissions)
return ",".join(f"+{x}" for x in permissions)

def __call__(self,) -> AsyncGenerator: # noqa: D202
def __call__(
self,
) -> AsyncGenerator: # noqa: D202
"""Return a :class:`.RedditorList` for live threads' contributors.
Usage:
Expand Down
9 changes: 7 additions & 2 deletions asyncpraw/models/reddit/modmail.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,10 @@ def _convert_user_summary(data, reddit):

@classmethod
def parse( # pylint: disable=arguments-differ
cls, data: Dict[str, Any], reddit: "Reddit", convert_objects: bool = True,
cls,
data: Dict[str, Any],
reddit: "Reddit",
convert_objects: bool = True,
):
"""Return an instance of ModmailConversation from ``data``.
Expand Down Expand Up @@ -205,7 +208,9 @@ async def mute(self, num_days=3):
.. code-block:: python
reddit.subreddit("redditdev").modmail("2gmz").mute(7)
subreddit = await reddit.subreddit("redditdev")
conversation = await subreddit.modmail("2gmz")
await conversation.mute(7)
"""
Expand Down
3 changes: 2 additions & 1 deletion asyncpraw/models/reddit/redditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,8 @@ async def gild(self, months: int = 1):
if months < 1 or months > 36:
raise TypeError("months must be between 1 and 36")
await self._reddit.post(
API_PATH["gild_user"].format(username=self), data={"months": months},
API_PATH["gild_user"].format(username=self),
data={"months": months},
)

async def moderated(self) -> List["Subreddit"]:
Expand Down
6 changes: 4 additions & 2 deletions asyncpraw/models/reddit/submission.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ async def contest_mode(self, state: bool = True):
"""
await self.thing._reddit.post(
API_PATH["contest_mode"], data={"id": self.thing.fullname, "state": state},
API_PATH["contest_mode"],
data={"id": self.thing.fullname, "state": state},
)

async def flair(
Expand Down Expand Up @@ -297,7 +298,8 @@ async def suggested_sort(self, sort: str = "blank"):
"""
await self.thing._reddit.post(
API_PATH["suggested_sort"], data={"id": self.thing.fullname, "sort": sort},
API_PATH["suggested_sort"],
data={"id": self.thing.fullname, "sort": sort},
)

async def unset_original_content(self):
Expand Down
32 changes: 23 additions & 9 deletions asyncpraw/models/reddit/subreddit.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,7 @@ def _validate_gallery(images):
image_path = image.get("image_path", "")
if image_path:
if not isfile(image_path):
raise TypeError(
"{!r} is not a valid image path.".format(image_path)
)
raise TypeError(f"{image_path!r} is not a valid image path.")
else:
raise TypeError("'image_path' is required.")
if not len(image.get("caption", "")) <= 180:
Expand Down Expand Up @@ -642,7 +640,11 @@ async def _submit_media(self, data, timeout, without_websockets):
response["json"]["data"]["websocket_url"], timeout=timeout
) as websocket:
ws_update = await websocket.receive_json()
except (WebSocketError, socket.error, BlockingIOError,) as ws_exception:
except (
WebSocketError,
socket.error,
BlockingIOError,
) as ws_exception:
raise WebSocketException(
"Websocket error. Check your media file. "
"Your post may still have been created. "
Expand Down Expand Up @@ -1028,7 +1030,9 @@ async def submit_gallery(
"caption": image.get("caption", ""),
"outbound_url": image.get("outbound_url", ""),
"media_id": await self._upload_media(
image["image_path"], expected_mime_prefix="image", gallery=True,
image["image_path"],
expected_mime_prefix="image",
gallery=True,
),
}
)
Expand Down Expand Up @@ -1136,7 +1140,8 @@ async def submit_image(
data[key] = value
url = await self._upload_media(image_path, expected_mime_prefix="image")
data.update(
kind="image", url=url,
kind="image",
url=url,
)
return await self._submit_media(
data, timeout, without_websockets=without_websockets
Expand Down Expand Up @@ -1470,7 +1475,9 @@ async def add(self, subreddit):
"""
user = await self.subreddit._reddit.user.me()
url = API_PATH["subreddit_filter"].format(
special=self.subreddit, user=user, subreddit=subreddit,
special=self.subreddit,
user=user,
subreddit=subreddit,
)
await self.subreddit._reddit.put(
url, data={"model": dumps({"name": str(subreddit)})}
Expand All @@ -1487,7 +1494,9 @@ async def remove(self, subreddit):
"""
user = await self.subreddit._reddit.user.me()
url = API_PATH["subreddit_filter"].format(
special=self.subreddit, user=user, subreddit=subreddit,
special=self.subreddit,
user=user,
subreddit=subreddit,
)
await self.subreddit._reddit.delete(url)

Expand Down Expand Up @@ -3087,7 +3096,12 @@ async def bulk_read(self, other_subreddits=None, state=None):
]

async def conversations(
self, after=None, limit=None, other_subreddits=None, sort=None, state=None,
self,
after=None,
limit=None,
other_subreddits=None,
sort=None,
state=None,
): # noqa: D207, D301
"""Generate :class:`.ModmailConversation` objects for subreddit(s).
Expand Down
3 changes: 2 additions & 1 deletion asyncpraw/models/reddit/wikipage.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,8 @@ async def edit(
"""
other_settings.update({"content": content, "page": self.name, "reason": reason})
await self._reddit.post(
API_PATH["wiki_edit"].format(subreddit=self.subreddit), data=other_settings,
API_PATH["wiki_edit"].format(subreddit=self.subreddit),
data=other_settings,
)

async def revision(self, revision: str):
Expand Down
10 changes: 8 additions & 2 deletions asyncpraw/reddit.py
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,9 @@ async def get(
return await self._objectify_request(method="GET", params=params, path=path)

def info(
self, fullnames: Optional[Iterable[str]] = None, url: Optional[str] = None,
self,
fullnames: Optional[Iterable[str]] = None,
url: Optional[str] = None,
) -> AsyncGenerator[Union[Subreddit, Comment, Submission], None]:
"""Fetch information about each item in ``fullnames`` or from ``url``.
Expand Down Expand Up @@ -687,7 +689,11 @@ async def post(
logger.debug(f"Rate limit hit, sleeping for {seconds:.2f} seconds")
await asyncio.sleep(seconds)
return await self._objectify_request(
data=data, files=files, method="POST", params=params, path=path,
data=data,
files=files,
method="POST",
params=params,
path=path,
)
raise

Expand Down
3 changes: 2 additions & 1 deletion docs/examples/obtain_refresh_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ async def main():

if state != params["state"]:
send_message(
client, f"State mismatch. Expected: {state} Received: {params['state']}",
client,
f"State mismatch. Expected: {state} Received: {params['state']}",
)
return 1
elif "error" in params:
Expand Down
7 changes: 5 additions & 2 deletions tests/integration/models/reddit/test_emoji.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ async def test_update(self, _):
subreddit = await self.reddit.subreddit(pytest.placeholders.test_subreddit)
emoji = await subreddit.emoji.get_emoji("test_png")
await emoji.update(
mod_flair_only=False, post_flair_allowed=True, user_flair_allowed=True,
mod_flair_only=False,
post_flair_allowed=True,
user_flair_allowed=True,
)

@mock.patch("asyncio.sleep", return_value=None)
Expand Down Expand Up @@ -78,7 +80,8 @@ async def test_add(self, _):
subreddit = await self.reddit.subreddit(pytest.placeholders.test_subreddit)
for extension in ["jpg", "png"]:
emoji = await subreddit.emoji.add(
f"test_{extension}", f"tests/integration/files/test.{extension}",
f"test_{extension}",
f"tests/integration/files/test.{extension}",
)
assert isinstance(emoji, Emoji)

Expand Down
4 changes: 3 additions & 1 deletion tests/integration/models/reddit/test_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,9 @@ async def test_update_rule(self, _):
rule_list = await self.async_list(subreddit.rules)
rule = rule_list[0]
rule2 = await rule.mod.update(
description="Updated rule", kind="link", violation_reason="PUpdate",
description="Updated rule",
kind="link",
violation_reason="PUpdate",
)
assert rule.description != rule2.description
assert rule2.description == "Updated rule"
Expand Down
12 changes: 8 additions & 4 deletions tests/integration/models/reddit/test_subreddit.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,10 @@ async def test_submit_poll(self, _):
with self.use_cassette():
subreddit = await self.reddit.subreddit(pytest.placeholders.test_subreddit)
submission = await subreddit.submit_poll(
"Test Poll", selftext="Test poll text.", options=options, duration=6,
"Test Poll",
selftext="Test poll text.",
options=options,
duration=6,
)
await submission.load()
assert submission.author == pytest.placeholders.username
Expand Down Expand Up @@ -2111,9 +2114,10 @@ async def test_upload__others_too_large(self):
"upload_mobile_icon",
]:
with pytest.raises(TooLarge):
await getattr(subreddit.stylesheet, method,)(
image_path("too_large.jpg")
)
await getattr(
subreddit.stylesheet,
method,
)(image_path("too_large.jpg"))


class TestSubredditWiki(IntegrationTest):
Expand Down
12 changes: 9 additions & 3 deletions tests/integration/models/reddit/test_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,10 @@ async def test_create_and_update_and_delete(self, _):
},
]
widget = await widgets.mod.add_button_widget(
"Things to click", "Click some of these *cool* links!", buttons, styles,
"Things to click",
"Click some of these *cool* links!",
buttons,
styles,
)

assert isinstance(widget, ButtonWidget)
Expand Down Expand Up @@ -284,7 +287,8 @@ async def test_create_and_update_and_delete(self, _):
assert "redditdev" in widget

widget = await widget.mod.update(
shortName="My least fav subs :(", data=["redesign"],
shortName="My least fav subs :(",
data=["redesign"],
)

assert isinstance(widget, CommunityList)
Expand Down Expand Up @@ -720,7 +724,9 @@ async def test_update(self, _):
assert rules.styles != new_styles

rules = await rules.mod.update(
display="compact", shortName="Our regulations", styles=new_styles,
display="compact",
shortName="Our regulations",
styles=new_styles,
)

assert rules.display == "compact"
Expand Down
3 changes: 2 additions & 1 deletion tests/integration/models/test_subreddits.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ async def test_recommended__with_multiple(
): # FIXME: always seems to return []; same with praw
with self.use_cassette():
subreddits = await self.reddit.subreddits.recommended(
["cityporn", "earthporn"], omit_subreddits=["skyporn", "winterporn"],
["cityporn", "earthporn"],
omit_subreddits=["skyporn", "winterporn"],
)
assert (
len(subreddits) == 0
Expand Down
5 changes: 4 additions & 1 deletion tests/unit/models/reddit/test_redditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ def test_construct_failure(self):

with pytest.raises(TypeError) as excinfo:
Redditor(
self.reddit, name="dummy", fullname="t2_dummy", _data={"id": "dummy"},
self.reddit,
name="dummy",
fullname="t2_dummy",
_data={"id": "dummy"},
)
assert str(excinfo.value) == message

Expand Down
6 changes: 3 additions & 3 deletions tests/unit/models/reddit/test_subreddit.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ def test_hash(self):
assert hash(subreddit1) != hash(subreddit3)

@mock.patch(
"asyncpraw.Reddit.post", return_value={"json": {"data": {"websocket_url": ""}}},
"asyncpraw.Reddit.post",
return_value={"json": {"data": {"websocket_url": ""}}},
)
@mock.patch("asyncpraw.models.Subreddit._upload_media", return_value="")
@mock.patch("aiohttp.client.ClientSession.ws_connect")
Expand Down Expand Up @@ -135,8 +136,7 @@ async def test_submit_gallery__invalid_path(self):
async def test_submit_gallery__too_long_caption(self):
message = "Caption must be 180 characters or less."
subreddit = Subreddit(self.reddit, display_name="name")
caption = \
"wayyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy too long caption"
caption = "wayyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy too long caption"
with pytest.raises(TypeError) as excinfo:
await subreddit.submit_gallery(
"Cool title", images=[{"image_path": __file__, "caption": caption}]
Expand Down
4 changes: 3 additions & 1 deletion tests/unit/models/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ def test_url__web_app__implicit(self):

def test_url__web_app_without_redirect_uri(self):
reddit = Reddit(
client_id="dummy client", client_secret="dummy secret", user_agent="dummy",
client_id="dummy client",
client_secret="dummy secret",
user_agent="dummy",
)
with pytest.raises(ClientException):
reddit.auth.url(["dummy scope"], "dummy state")
5 changes: 4 additions & 1 deletion tests/unit/test_reddit.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,10 @@ async def test_request__json_and_body(self):
reddit = Reddit(client_id="dummy", client_secret="dummy", user_agent="dummy")
with pytest.raises(ClientException) as excinfo:
await reddit.request(
method="POST", path="/", data={"key": "value"}, json={"key": "value"},
method="POST",
path="/",
data={"key": "value"},
json={"key": "value"},
)
assert str(excinfo.value).startswith(
"At most one of `data` and `json` is supported."
Expand Down

0 comments on commit 905e5c9

Please sign in to comment.