Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
- name: 🏗 Install dependencies
run: poetry install --no-interaction
- name: 🚀 Run pytest
run: poetry run pytest --cov vehicle tests
run: poetry run pytest --cov youtubeaio tests
- name: ⬆️ Upload coverage artifact
uses: actions/[email protected]
with:
Expand Down
2,148 changes: 1,131 additions & 1,017 deletions poetry.lock

Large diffs are not rendered by default.

63 changes: 62 additions & 1 deletion tests/__snapshots__/test_video.ambr
Original file line number Diff line number Diff line change
@@ -1,4 +1,65 @@
# serializer version: 1
# name: test_fetch_video
YouTubeVideo(video_id='Ks-_Mh1QhMc', nullable_snippet=YouTubeVideoSnippet(published_at=datetime.datetime(2012, 10, 1, 15, 27, 35, tzinfo=TzInfo(UTC)), channel_id='UCAuUUnT6oDeKwE6v1NGQxug', title='Your body language may shape who you are | Amy Cuddy', description='Body language affects how others see us, but it may also change how we see ourselves. Social psychologist Amy Cuddy argues that "power posing" -- standing in a posture of confidence, even when we don\'t feel confident -- can boost feelings of confidence, and might have an impact on our chances for success. (Note: Some of the findings presented in this talk have been referenced in an ongoing debate among social scientists about robustness and reproducibility. Read Amy Cuddy\'s response here: http://ideas.ted.com/inside-the-debate-about-power-posing-a-q-a-with-amy-cuddy/)\n\nGet TED Talks recommended just for you! Learn more at https://www.ted.com/signup.\n\nThe TED Talks channel features the best talks and performances from the TED Conference, where the world\'s leading thinkers and doers give the talk of their lives in 18 minutes (or less). Look for talks on Technology, Entertainment and Design -- plus science, business, global issues, the arts and more.\n\nFollow TED on Twitter: http://www.twitter.com/TEDTalks\nLike TED on Facebook: https://www.facebook.com/TED\n\nSubscribe to our channel: https://www.youtube.com/TED', thumbnails=YouTubeVideoThumbnails(default=YouTubeThumbnail(url='https://i.ytimg.com/vi/Ks-_Mh1QhMc/default.jpg', width=120, height=90), medium=YouTubeThumbnail(url='https://i.ytimg.com/vi/Ks-_Mh1QhMc/mqdefault.jpg', width=320, height=180), high=YouTubeThumbnail(url='https://i.ytimg.com/vi/Ks-_Mh1QhMc/hqdefault.jpg', width=480, height=360), standard=YouTubeThumbnail(url='https://i.ytimg.com/vi/Ks-_Mh1QhMc/sddefault.jpg', width=640, height=480), maxres=YouTubeThumbnail(url='https://i.ytimg.com/vi/Ks-_Mh1QhMc/maxresdefault.jpg', width=1280, height=720)), channel_title='TED', tags=['Amy Cuddy', 'TED', 'TEDTalk', 'TEDTalks', 'TED Talk', 'TED Talks', 'TEDGlobal', 'brain', 'business', 'psychology', 'self', 'success'], live_broadcast_content=<LiveBroadcastContent.NONE: 'none'>, default_language='en', default_audio_language='en'), nullable_content_details=YouTubeVideoContentDetails(raw_duration='PT21M3S', dimension=<VideoDimension.D2: '2d'>, definition=<VideoDefinition.HD: 'hd'>, raw_caption='true', licensed_content=True, projection=<VideoProjection.RECTANGULAR: 'rectangular'>))
dict({
'nullable_content_details': dict({
'definition': <VideoDefinition.HD: 'hd'>,
'dimension': <VideoDimension.D2: '2d'>,
'licensed_content': True,
'projection': <VideoProjection.RECTANGULAR: 'rectangular'>,
'raw_caption': 'true',
'raw_duration': 'PT21M3S',
}),
'nullable_snippet': dict({
'channel_id': 'UCAuUUnT6oDeKwE6v1NGQxug',
'channel_title': 'TED',
'default_audio_language': 'en',
'default_language': 'en',
'description': 'Body language affects how others see us, but it may also change how we see ourselves. Social psychologist Amy Cuddy argues that "power posing" -- standing in a posture of confidence, even when we don\'t feel confident -- can boost feelings of confidence, and might have an impact on our chances for success. (Note: Some of the findings presented in this talk have been referenced in an ongoing debate among social scientists about robustness and reproducibility. Read Amy Cuddy\'s response here: http://ideas.ted.com/inside-the-debate-about-power-posing-a-q-a-with-amy-cuddy/)Get TED Talks recommended just for you! Learn more at https://www.ted.com/signup.The TED Talks channel features the best talks and performances from the TED Conference, where the world\'s leading thinkers and doers give the talk of their lives in 18 minutes (or less). Look for talks on Technology, Entertainment and Design -- plus science, business, global issues, the arts and more.Follow TED on Twitter: http://www.twitter.com/TEDTalksLike TED on Facebook: https://www.facebook.com/TEDSubscribe to our channel: https://www.youtube.com/TED',
'live_broadcast_content': <LiveBroadcastContent.NONE: 'none'>,
'published_at': datetime.datetime(2012, 10, 1, 15, 27, 35, tzinfo=TzInfo(0)),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There seems to be something off with the CI configuration. This should probably be

Suggested change
'published_at': datetime.datetime(2012, 10, 1, 15, 27, 35, tzinfo=TzInfo(0)),
'published_at': datetime.datetime(2012, 10, 1, 15, 27, 35, tzinfo=TzInfo(UTC)),

'tags': list([
'Amy Cuddy',
'TED',
'TEDTalk',
'TEDTalks',
'TED Talk',
'TED Talks',
'TEDGlobal',
'brain',
'business',
'psychology',
'self',
'success',
]),
'thumbnails': dict({
'default': dict({
'height': 90,
'url': 'https://i.ytimg.com/vi/Ks-_Mh1QhMc/default.jpg',
'width': 120,
}),
'high': dict({
'height': 360,
'url': 'https://i.ytimg.com/vi/Ks-_Mh1QhMc/hqdefault.jpg',
'width': 480,
}),
'maxres': dict({
'height': 720,
'url': 'https://i.ytimg.com/vi/Ks-_Mh1QhMc/maxresdefault.jpg',
'width': 1280,
}),
'medium': dict({
'height': 180,
'url': 'https://i.ytimg.com/vi/Ks-_Mh1QhMc/mqdefault.jpg',
'width': 320,
}),
'standard': dict({
'height': 480,
'url': 'https://i.ytimg.com/vi/Ks-_Mh1QhMc/sddefault.jpg',
'width': 640,
}),
}),
'title': 'Your body language may shape who you are | Amy Cuddy',
}),
'video_id': 'Ks-_Mh1QhMc',
})
# ---
12 changes: 12 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
"""Pytest configuration for Syrupy snapshot testing with Youtube extension."""

import pytest

from syrupy import SnapshotAssertion
from tests.syrupy import YoutubeSnapshotExtension


@pytest.fixture(name="snapshot")
def snapshot_assertion(snapshot: SnapshotAssertion) -> SnapshotAssertion:
"""Return snapshot assertion fixture with the Youtube extension."""
return snapshot.use_extension(YoutubeSnapshotExtension)
4 changes: 2 additions & 2 deletions tests/fixtures/video/1/snippet.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"publishedAt": "2012-10-01T15:27:35Z",
"channelId": "UCAuUUnT6oDeKwE6v1NGQxug",
"title": "Your body language may shape who you are | Amy Cuddy",
"description": "Body language affects how others see us, but it may also change how we see ourselves. Social psychologist Amy Cuddy argues that \"power posing\" -- standing in a posture of confidence, even when we don't feel confident -- can boost feelings of confidence, and might have an impact on our chances for success. (Note: Some of the findings presented in this talk have been referenced in an ongoing debate among social scientists about robustness and reproducibility. Read Amy Cuddy's response here: http://ideas.ted.com/inside-the-debate-about-power-posing-a-q-a-with-amy-cuddy/)\n\nGet TED Talks recommended just for you! Learn more at https://www.ted.com/signup.\n\nThe TED Talks channel features the best talks and performances from the TED Conference, where the world's leading thinkers and doers give the talk of their lives in 18 minutes (or less). Look for talks on Technology, Entertainment and Design -- plus science, business, global issues, the arts and more.\n\nFollow TED on Twitter: http://www.twitter.com/TEDTalks\nLike TED on Facebook: https://www.facebook.com/TED\n\nSubscribe to our channel: https://www.youtube.com/TED",
"description": "Body language affects how others see us, but it may also change how we see ourselves. Social psychologist Amy Cuddy argues that \"power posing\" -- standing in a posture of confidence, even when we don't feel confident -- can boost feelings of confidence, and might have an impact on our chances for success. (Note: Some of the findings presented in this talk have been referenced in an ongoing debate among social scientists about robustness and reproducibility. Read Amy Cuddy's response here: http://ideas.ted.com/inside-the-debate-about-power-posing-a-q-a-with-amy-cuddy/)Get TED Talks recommended just for you! Learn more at https://www.ted.com/signup.The TED Talks channel features the best talks and performances from the TED Conference, where the world's leading thinkers and doers give the talk of their lives in 18 minutes (or less). Look for talks on Technology, Entertainment and Design -- plus science, business, global issues, the arts and more.Follow TED on Twitter: http://www.twitter.com/TEDTalksLike TED on Facebook: https://www.facebook.com/TEDSubscribe to our channel: https://www.youtube.com/TED",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/Ks-_Mh1QhMc/default.jpg",
Expand Down Expand Up @@ -50,7 +50,7 @@
"defaultLanguage": "en",
"localized": {
"title": "Your body language may shape who you are | Amy Cuddy",
"description": "Body language affects how others see us, but it may also change how we see ourselves. Social psychologist Amy Cuddy argues that \"power posing\" -- standing in a posture of confidence, even when we don't feel confident -- can boost feelings of confidence, and might have an impact on our chances for success. (Note: Some of the findings presented in this talk have been referenced in an ongoing debate among social scientists about robustness and reproducibility. Read Amy Cuddy's response here: http://ideas.ted.com/inside-the-debate-about-power-posing-a-q-a-with-amy-cuddy/)\n\nGet TED Talks recommended just for you! Learn more at https://www.ted.com/signup.\n\nThe TED Talks channel features the best talks and performances from the TED Conference, where the world's leading thinkers and doers give the talk of their lives in 18 minutes (or less). Look for talks on Technology, Entertainment and Design -- plus science, business, global issues, the arts and more.\n\nFollow TED on Twitter: http://www.twitter.com/TEDTalks\nLike TED on Facebook: https://www.facebook.com/TED\n\nSubscribe to our channel: https://www.youtube.com/TED"
"description": "Body language affects how others see us, but it may also change how we see ourselves. Social psychologist Amy Cuddy argues that \"power posing\" -- standing in a posture of confidence, even when we don't feel confident -- can boost feelings of confidence, and might have an impact on our chances for success. (Note: Some of the findings presented in this talk have been referenced in an ongoing debate among social scientists about robustness and reproducibility. Read Amy Cuddy's response here: http://ideas.ted.com/inside-the-debate-about-power-posing-a-q-a-with-amy-cuddy/)Get TED Talks recommended just for you! Learn more at https://www.ted.com/signup.The TED Talks channel features the best talks and performances from the TED Conference, where the world's leading thinkers and doers give the talk of their lives in 18 minutes (or less). Look for talks on Technology, Entertainment and Design -- plus science, business, global issues, the arts and more.Follow TED on Twitter: http://www.twitter.com/TEDTalksLike TED on Facebook: https://www.facebook.com/TEDSubscribe to our channel: https://www.youtube.com/TED"
},
"defaultAudioLanguage": "en"
}
67 changes: 67 additions & 0 deletions tests/syrupy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
"""Tests for the YouTube client."""

from __future__ import annotations

from typing import TYPE_CHECKING, Any

from pydantic import BaseModel
from syrupy.extensions import AmberSnapshotExtension
from syrupy.extensions.amber import AmberDataSerializer

if TYPE_CHECKING:
from syrupy.types import (
PropertyFilter,
PropertyMatcher,
PropertyPath,
SerializableData,
)


class YoutubeSnapshotSerializer(AmberDataSerializer):
"""Youtube snapshot serializer for Syrupy.

Handles special cases for Youtube data structures.
"""

@classmethod
def _serialize( # pylint: disable=too-many-arguments
cls,
data: SerializableData,
*,
depth: int = 0,
exclude: PropertyFilter | None = None,
include: PropertyFilter | None = None,
matcher: PropertyMatcher | None = None,
path: PropertyPath = (),
visited: set[Any] | None = None,
) -> str:
"""Pre-process data before serializing.

This allows us to handle specific cases for
Youtube data structures.
"""
serializable_data = data
if isinstance(data, BaseModel):
serializable_data = data.model_dump()

return super()._serialize(
serializable_data,
depth=depth,
exclude=exclude,
include=include,
matcher=matcher,
path=path,
visited=visited,
)


class YoutubeSnapshotExtension(AmberSnapshotExtension):
"""Youtube extension for Syrupy."""

VERSION = "1"
"""Current version of serialization format.

Need to be bumped when we change the YoutubeSnapshotSerializer.
"""

serializer_class: type[AmberDataSerializer] = YoutubeSnapshotSerializer
2 changes: 1 addition & 1 deletion tests/test_video.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import pytest
from aiohttp.web_request import BaseRequest
from aresponses import Response, ResponsesMockServer
from syrupy import SnapshotAssertion

from syrupy import SnapshotAssertion
from youtubeaio.helper import first
from youtubeaio.models import YouTubeVideoThumbnails
from youtubeaio.types import PartMissingError
Expand Down
Loading