Skip to content

Commit

Permalink
New tests
Browse files Browse the repository at this point in the history
  - Rename `format_*` arg `format` to `ext`
  • Loading branch information
davfsa committed Aug 21, 2020
1 parent 76af22a commit 8046fef
Show file tree
Hide file tree
Showing 11 changed files with 363 additions and 127 deletions.
24 changes: 12 additions & 12 deletions hikari/applications.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,13 +334,13 @@ def icon_url(self) -> typing.Optional[files.URL]:
return self.format_icon()

# noinspection PyShadowingBuiltins
def format_icon(self, *, format: str = "png", size: int = 4096) -> typing.Optional[files.URL]:
def format_icon(self, *, ext: str = "png", size: int = 4096) -> typing.Optional[files.URL]:
"""Generate the icon for this team if set.
Parameters
----------
format : builtins.str
The format to use for this URL, defaults to `png`.
ext : builtins.str
The extension to use for this URL, defaults to `png`.
Supports `png`, `jpeg`, `jpg` and `webp`.
size : builtins.int
The size to set for the URL, defaults to `4096`. Can be any power
Expand All @@ -361,7 +361,7 @@ def format_icon(self, *, format: str = "png", size: int = 4096) -> typing.Option
return None

return routes.CDN_TEAM_ICON.compile_to_file(
constants.CDN_URL, team_id=self.id, hash=self.icon_hash, size=size, file_format=format,
constants.CDN_URL, team_id=self.id, hash=self.icon_hash, size=size, file_format=ext,
)


Expand Down Expand Up @@ -455,13 +455,13 @@ def icon_url(self) -> typing.Optional[files.URL]:
return self.format_icon()

# noinspection PyShadowingBuiltins
def format_icon(self, *, format: str = "png", size: int = 4096) -> typing.Optional[files.URL]:
def format_icon(self, *, ext: str = "png", size: int = 4096) -> typing.Optional[files.URL]:
"""Generate the icon for this application.
Parameters
----------
format : builtins.str
The format to use for this URL, defaults to `png`.
ext : builtins.str
The extension to use for this URL, defaults to `png`.
Supports `png`, `jpeg`, `jpg` and `webp`.
size : builtins.int
The size to set for the URL, defaults to `4096`.
Expand All @@ -482,7 +482,7 @@ def format_icon(self, *, format: str = "png", size: int = 4096) -> typing.Option
return None

return routes.CDN_APPLICATION_ICON.compile_to_file(
constants.CDN_URL, application_id=self.id, hash=self.icon_hash, size=size, file_format=format,
constants.CDN_URL, application_id=self.id, hash=self.icon_hash, size=size, file_format=ext,
)

@property
Expand All @@ -497,13 +497,13 @@ def cover_image_url(self) -> typing.Optional[files.URL]:
return self.format_cover_image()

# noinspection PyShadowingBuiltins
def format_cover_image(self, *, format: str = "png", size: int = 4096) -> typing.Optional[files.URL]:
def format_cover_image(self, *, ext: str = "png", size: int = 4096) -> typing.Optional[files.URL]:
"""Generate the cover image used in the store, if set.
Parameters
----------
format : builtins.str
The format to use for this URL, defaults to `png`.
ext : builtins.str
The extension to use for this URL, defaults to `png`.
Supports `png`, `jpeg`, `jpg` and `webp`.
size : builtins.int
The size to set for the URL, defaults to `4096`.
Expand All @@ -524,5 +524,5 @@ def format_cover_image(self, *, format: str = "png", size: int = 4096) -> typing
return None

return routes.CDN_APPLICATION_COVER.compile_to_file(
constants.CDN_URL, application_id=self.id, hash=self.cover_image_hash, size=size, file_format=format,
constants.CDN_URL, application_id=self.id, hash=self.cover_image_hash, size=size, file_format=ext,
)
8 changes: 4 additions & 4 deletions hikari/channels.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,13 +456,13 @@ def icon_url(self) -> typing.Optional[files.URL]:
return self.format_icon()

# noinspection PyShadowingBuiltins
def format_icon(self, *, format: str = "png", size: int = 4096) -> typing.Optional[files.URL]:
def format_icon(self, *, ext: str = "png", size: int = 4096) -> typing.Optional[files.URL]:
"""Generate the icon for this DM, if set.
Parameters
----------
format : builtins.str
The format to use for this URL, defaults to `png`.
ext : builtins.str
The extension to use for this URL, defaults to `png`.
Supports `png`, `jpeg`, `jpg` and `webp`.
size : builtins.int
The size to set for the URL, defaults to `4096`.
Expand All @@ -482,7 +482,7 @@ def format_icon(self, *, format: str = "png", size: int = 4096) -> typing.Option
return None

return routes.CDN_CHANNEL_ICON.compile_to_file(
constants.CDN_URL, channel_id=self.id, hash=self.icon_hash, size=size, file_format=format,
constants.CDN_URL, channel_id=self.id, hash=self.icon_hash, size=size, file_format=ext,
)


Expand Down
72 changes: 36 additions & 36 deletions hikari/guilds.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,12 +365,12 @@ def flags(self) -> users.UserFlag:
return self.user.flags

@property
def avatar(self) -> files.URL:
return self.user.avatar
def avatar_url(self) -> files.URL:
return self.user.avatar_url

# noinspection PyShadowingBuiltins
def format_avatar(self, *, format: typing.Optional[str] = None, size: int = 4096) -> typing.Optional[files.URL]:
return self.user.format_avatar(format=format, size=size)
def format_avatar(self, *, ext: typing.Optional[str] = None, size: int = 4096) -> typing.Optional[files.URL]:
return self.user.format_avatar(ext=ext, size=size)

@property
def default_avatar(self) -> files.URL:
Expand Down Expand Up @@ -645,18 +645,18 @@ def icon_url(self) -> typing.Optional[files.URL]:
"""Icon for the guild, if set; otherwise `builtins.None`."""
return self.format_icon()

def format_icon(self, *, format_: typing.Optional[str] = None, size: int = 4096) -> typing.Optional[files.URL]:
def format_icon(self, *, ext: typing.Optional[str] = None, size: int = 4096) -> typing.Optional[files.URL]:
"""Generate the guild's icon, if set.
Parameters
----------
format_ : typing.Optional[builtins.str]
The format to use for this URL, defaults to `png` or `gif`.
ext : typing.Optional[builtins.str]
The extension to use for this URL, defaults to `png` or `gif`.
Supports `png`, `jpeg`, `jpg`, `webp` and `gif` (when
animated).
If `builtins.None`, then the correct default format is determined
based on whether the icon is animated or not.
If `builtins.None`, then the correct default extension is
determined based on whether the icon is animated or not.
size : builtins.int
The size to set for the URL, defaults to `4096`.
Can be any power of two between 16 and 4096.
Expand All @@ -674,14 +674,14 @@ def format_icon(self, *, format_: typing.Optional[str] = None, size: int = 4096)
if self.icon_hash is None:
return None

if format_ is None:
if ext is None:
if self.icon_hash.startswith("a_"):
format_ = "gif"
ext = "gif"
else:
format_ = "png"
ext = "png"

return routes.CDN_GUILD_ICON.compile_to_file(
constants.CDN_URL, guild_id=self.id, hash=self.icon_hash, size=size, file_format=format_,
constants.CDN_URL, guild_id=self.id, hash=self.icon_hash, size=size, file_format=ext,
)


Expand Down Expand Up @@ -712,13 +712,13 @@ def splash_url(self) -> typing.Optional[files.URL]:
"""Splash for the guild, if set."""
return self.format_splash()

def format_splash(self, *, format_: str = "png", size: int = 4096) -> typing.Optional[files.URL]:
def format_splash(self, *, ext: str = "png", size: int = 4096) -> typing.Optional[files.URL]:
"""Generate the guild's splash image, if set.
Parameters
----------
format_ : builtins.str
The format to use for this URL, defaults to `png`.
ext : builtins.str
The extension to use for this URL, defaults to `png`.
Supports `png`, `jpeg`, `jpg` and `webp`.
size : builtins.int
The size to set for the URL, defaults to `4096`.
Expand All @@ -738,21 +738,21 @@ def format_splash(self, *, format_: str = "png", size: int = 4096) -> typing.Opt
return None

return routes.CDN_GUILD_SPLASH.compile_to_file(
constants.CDN_URL, guild_id=self.id, hash=self.splash_hash, size=size, file_format=format_,
constants.CDN_URL, guild_id=self.id, hash=self.splash_hash, size=size, file_format=ext,
)

@property
def discovery_splash(self) -> typing.Optional[files.URL]:
def discovery_splash_url(self) -> typing.Optional[files.URL]:
"""Discovery splash for the guild, if set."""
return self.format_discovery_splash()

def format_discovery_splash(self, *, format_: str = "png", size: int = 4096) -> typing.Optional[files.URL]:
def format_discovery_splash(self, *, ext: str = "png", size: int = 4096) -> typing.Optional[files.URL]:
"""Generate the guild's discovery splash image, if set.
Parameters
----------
format_ : builtins.str
The format to use for this URL, defaults to `png`.
ext : builtins.str
The extension to use for this URL, defaults to `png`.
Supports `png`, `jpeg`, `jpg` and `webp`.
size : builtins.int
The size to set for the URL, defaults to `4096`.
Expand All @@ -772,7 +772,7 @@ def format_discovery_splash(self, *, format_: str = "png", size: int = 4096) ->
return None

return routes.CDN_GUILD_DISCOVERY_SPLASH.compile_to_file(
constants.CDN_URL, guild_id=self.id, hash=self.discovery_splash_hash, size=size, file_format=format_,
constants.CDN_URL, guild_id=self.id, hash=self.discovery_splash_hash, size=size, file_format=ext,
)


Expand Down Expand Up @@ -952,13 +952,13 @@ def splash_url(self) -> typing.Optional[files.URL]:
"""Splash for the guild, if set."""
return self.format_splash()

def format_splash(self, *, format_: str = "png", size: int = 4096) -> typing.Optional[files.URL]:
def format_splash(self, *, ext: str = "png", size: int = 4096) -> typing.Optional[files.URL]:
"""Generate the guild's splash image, if set.
Parameters
----------
format_ : builtins.str
The format to use for this URL, defaults to `png`.
ext : builtins.str
The extension to use for this URL, defaults to `png`.
Supports `png`, `jpeg`, `jpg` and `webp`.
size : builtins.int
The size to set for the URL, defaults to `4096`.
Expand All @@ -978,21 +978,21 @@ def format_splash(self, *, format_: str = "png", size: int = 4096) -> typing.Opt
return None

return routes.CDN_GUILD_SPLASH.compile_to_file(
constants.CDN_URL, guild_id=self.id, hash=self.splash_hash, size=size, file_format=format_,
constants.CDN_URL, guild_id=self.id, hash=self.splash_hash, size=size, file_format=ext,
)

@property
def discovery_splash(self) -> typing.Optional[files.URL]:
def discovery_splash_url(self) -> typing.Optional[files.URL]:
"""Discovery splash for the guild, if set."""
return self.format_discovery_splash()

def format_discovery_splash(self, *, format_: str = "png", size: int = 4096) -> typing.Optional[files.URL]:
def format_discovery_splash(self, *, ext: str = "png", size: int = 4096) -> typing.Optional[files.URL]:
"""Generate the guild's discovery splash image, if set.
Parameters
----------
format_ : builtins.str
The format to use for this URL, defaults to `png`.
ext : builtins.str
The extension to use for this URL, defaults to `png`.
Supports `png`, `jpeg`, `jpg` and `webp`.
size : builtins.int
The size to set for the URL, defaults to `4096`.
Expand All @@ -1012,21 +1012,21 @@ def format_discovery_splash(self, *, format_: str = "png", size: int = 4096) ->
return None

return routes.CDN_GUILD_DISCOVERY_SPLASH.compile_to_file(
constants.CDN_URL, guild_id=self.id, hash=self.discovery_splash_hash, size=size, file_format=format_,
constants.CDN_URL, guild_id=self.id, hash=self.discovery_splash_hash, size=size, file_format=ext,
)

@property
def banner(self) -> typing.Optional[files.URL]:
def banner_url(self) -> typing.Optional[files.URL]:
"""Banner for the guild, if set."""
return self.format_banner()

def format_banner(self, *, format_: str = "png", size: int = 4096) -> typing.Optional[files.URL]:
def format_banner(self, *, ext: str = "png", size: int = 4096) -> typing.Optional[files.URL]:
"""Generate the guild's banner image, if set.
Parameters
----------
format_ : builtins.str
The format to use for this URL, defaults to `png`.
ext : builtins.str
The extension to use for this URL, defaults to `png`.
Supports `png`, `jpeg`, `jpg` and `webp`.
size : builtins.int
The size to set for the URL, defaults to `4096`.
Expand All @@ -1046,7 +1046,7 @@ def format_banner(self, *, format_: str = "png", size: int = 4096) -> typing.Opt
return None

return routes.CDN_GUILD_BANNER.compile_to_file(
constants.CDN_URL, guild_id=self.id, hash=self.banner_hash, size=size, file_format=format_,
constants.CDN_URL, guild_id=self.id, hash=self.banner_hash, size=size, file_format=ext,
)


Expand Down
16 changes: 8 additions & 8 deletions hikari/invites.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,13 @@ def splash_url(self) -> typing.Optional[files.URL]:
"""Splash for the guild, if set."""
return self.format_splash()

def format_splash(self, *, format_: str = "png", size: int = 4096) -> typing.Optional[files.URL]:
def format_splash(self, *, ext: str = "png", size: int = 4096) -> typing.Optional[files.URL]:
"""Generate the guild's splash image, if set.
Parameters
----------
format_ : builtins.str
The format to use for this URL, defaults to `png`.
ext : builtins.str
The extension to use for this URL, defaults to `png`.
Supports `png`, `jpeg`, `jpg` and `webp`.
size : builtins.int
The size to set for the URL, defaults to `4096`.
Expand All @@ -162,21 +162,21 @@ def format_splash(self, *, format_: str = "png", size: int = 4096) -> typing.Opt
return None

return routes.CDN_GUILD_SPLASH.compile_to_file(
constants.CDN_URL, guild_id=self.id, hash=self.splash_hash, size=size, file_format=format_,
constants.CDN_URL, guild_id=self.id, hash=self.splash_hash, size=size, file_format=ext,
)

@property
def banner(self) -> typing.Optional[files.URL]:
"""Banner for the guild, if set."""
return self.format_banner()

def format_banner(self, *, format_: str = "png", size: int = 4096) -> typing.Optional[files.URL]:
def format_banner(self, *, ext: str = "png", size: int = 4096) -> typing.Optional[files.URL]:
"""Generate the guild's banner image, if set.
Parameters
----------
format_ : builtins.str
The format to use for this URL, defaults to `png`.
ext : builtins.str
The extension to use for this URL, defaults to `png`.
Supports `png`, `jpeg`, `jpg` and `webp`.
size : builtins.int
The size to set for the URL, defaults to `4096`.
Expand All @@ -196,7 +196,7 @@ def format_banner(self, *, format_: str = "png", size: int = 4096) -> typing.Opt
return None

return routes.CDN_GUILD_BANNER.compile_to_file(
constants.CDN_URL, guild_id=self.id, hash=self.banner_hash, size=size, file_format=format_,
constants.CDN_URL, guild_id=self.id, hash=self.banner_hash, size=size, file_format=ext,
)


Expand Down
Loading

0 comments on commit 8046fef

Please sign in to comment.