Skip to content

Commit

Permalink
ruff format
Browse files Browse the repository at this point in the history
  • Loading branch information
s-t-e-v-e-n-k committed Nov 2, 2024
1 parent f9ea4aa commit 3ca940b
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 49 deletions.
4 changes: 2 additions & 2 deletions jellyash/bundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ def __getitem__(self, key) -> Item:
items = range(
key.start or 0,
key.stop or len(self.value["Items"]),
key.step or 1)
key.step or 1,
)
return [Item(self.value["Items"][k]) for k in items]
return Item(self.value["Items"][key])

Expand All @@ -59,4 +60,3 @@ def _get(self, handler, params=None):
if set(("Items", "TotalRecordCount")) <= set(resp.keys()):
return ApiResponse(resp)
return resp

3 changes: 2 additions & 1 deletion jellyash/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
def argparse_parser():
parser = argparse.ArgumentParser()
parser.add_argument(
"--version", action="version", version=f"jellyash {__version__}")
"--version", action="version", version=f"jellyash {__version__}"
)
return parser
8 changes: 5 additions & 3 deletions jellyash/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@ def authed_client():
try:
auth_with_token(client)
except (
PermissionError, ValueError, JSONDecodeError, ConnectionError
) as e:
PermissionError,
ValueError,
JSONDecodeError,
ConnectionError,
) as e:
print(f"{sys.argv[0]}: {e}")
sys.exit(1)
return client

1 change: 0 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,3 @@ class ClientTest(unittest.TestCase):
@pytest.fixture(autouse=True)
def _client(self):
self.test_client = test_client(self.__class__)

16 changes: 8 additions & 8 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ def setUp(self):

def test_create_client(self):
data = self.client.config.data
self.assertEqual(data['app.name'], "jellyash")
self.assertEqual(data['app.device_name'], platform.node())
self.assertEqual(data['app.version'], __version__)
self.assertTrue(data['auth.ssl'])
self.assertEqual(data["app.name"], "jellyash")
self.assertEqual(data["app.device_name"], platform.node())
self.assertEqual(data["app.version"], __version__)
self.assertTrue(data["auth.ssl"])

@pytest.mark.vcr
def test_auth_with_password(self):
Expand Down Expand Up @@ -73,7 +73,7 @@ def test_auth_with_nonexistant_file(self):

def test_auth_with_state_zero(self):
with tempfile.NamedTemporaryFile() as tmpfile:
tmpfile.file.write(b"{\"User\": \"foo\"}\n")
tmpfile.file.write(b'{"User": "foo"}\n')
tmpfile.file.flush()
ptf = pathlib.Path(tmpfile.name)
with patch("jellyash.client.CREDENTIALS_FILE", ptf):
Expand All @@ -93,7 +93,7 @@ def capsys(self, capsys):
def test_authed_client(self):
with tempfile.NamedTemporaryFile() as tmpfile:
credentials = self.test_client.auth.credentials.get_credentials()
with open(tmpfile.name, 'w') as f:
with open(tmpfile.name, "w") as f:
json.dump(credentials["Servers"][0], f)
ptf = pathlib.Path(tmpfile.name)
with patch("jellyash.client.CREDENTIALS_FILE", ptf):
Expand All @@ -104,7 +104,7 @@ def test_authed_client(self):
def test_authed_client_offline(self):
with tempfile.NamedTemporaryFile() as tmpfile:
credentials = self.test_client.auth.credentials.get_credentials()
with open(tmpfile.name, 'w') as f:
with open(tmpfile.name, "w") as f:
json.dump(credentials["Servers"][0], f)
ptf = pathlib.Path(tmpfile.name)
with patch("jellyash.client.CREDENTIALS_FILE", ptf):
Expand All @@ -114,7 +114,7 @@ def test_authed_client_offline(self):
captured = self.capsys.readouterr()
self.assertEqual(
captured.out, "test_offline: Failed to establish connection\n"
)
)
self.assertEqual(captured.err, "")

def test_authed_client_non_existant_file(self):
Expand Down
6 changes: 3 additions & 3 deletions tests/test_duration.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ def test_integration(self):
with patch("jellyash.duration.authed_client") as client_mock:
with patch(
"argparse.ArgumentParser.parse_args",
return_value=argparse.Namespace(show=["Foo", "Bar"])
return_value=argparse.Namespace(show=["Foo", "Bar"]),
):
with patch(
"jellyash.duration.calculate_duration") as avg_mock:
"jellyash.duration.calculate_duration"
) as avg_mock:
average_duration()
client_mock.assert_called_once()
avg_mock.assert_called_once_with(
client_mock(), "Foo Bar"
)

15 changes: 7 additions & 8 deletions tests/test_nextup.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,22 @@ def capsys(self, capsys):

@pytest.mark.block_network
def test_nextup(self):
client_type = namedtuple('client', ['jellyfin'])
client_type = namedtuple("client", ["jellyfin"])
client = client_type(Mock())
episode_dict = {
'Name': 'Bar',
'ParentIndexNumber': '4',
'IndexNumber': '20',
'SeriesName': 'Foo',
}
"Name": "Bar",
"ParentIndexNumber": "4",
"IndexNumber": "20",
"SeriesName": "Foo",
}
client.jellyfin.get_next.return_value = [Item(episode_dict)]
with patch("jellyash.nextup.authed_client", return_value=client):
with patch(
"argparse.ArgumentParser.parse_args",
return_value=argparse.Namespace(limit=10)
return_value=argparse.Namespace(limit=10),
):
nextup()
client.jellyfin.get_next.assert_called_once_with(limit=10)
captured = self.capsys.readouterr()
self.assertEqual(captured.out, "Foo [4x20] Bar\n")
self.assertEqual(captured.err, "")

9 changes: 4 additions & 5 deletions tests/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ class TestSearch(unittest.TestCase):
def setUp(self):
with open(self.cassette_name(self.id().split(".")[-1])) as f:
result = json.load(f)
client_type = namedtuple('client', ['jellyfin'])
client_type = namedtuple("client", ["jellyfin"])
self.client = client_type(Mock())
self.client.jellyfin.search_media_items.return_value = ApiResponse(
result
)
)

def test_term_not_found(self):
with self.assertRaises(ValueError):
Expand Down Expand Up @@ -49,15 +49,14 @@ def _rerecord_mock_results(self):
"test_multiple_terms_not_exact": "NCIS: ",
"test_multiple_terms_exact": "Maid",
"test_multiple_terms_exact_with_space": "The Blacklist",
}
}
for test in test_cassettes:
result = client.jellyfin.search_media_items(
term=test_cassettes[test], media="Series"
)
)
with open(self.cassette_name(test), "w") as f:
json.dump(result._raw_value(), f)


if __name__ == "__main__":
TestSearch()._rerecord_mock_results()

3 changes: 1 addition & 2 deletions tests/test_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def test_create_token(self):
server_url = "https://demo.jellyfin.org/stable"
with patch(
"argparse.ArgumentParser.parse_args",
return_value=argparse.Namespace(server=server_url, user="demo")
return_value=argparse.Namespace(server=server_url, user="demo"),
):
with tempfile.NamedTemporaryFile() as tmpfile:
ptf = pathlib.Path(tmpfile.name)
Expand All @@ -38,4 +38,3 @@ def test_create_token(self):
self.assertIn("AccessToken", credentials)
self.assertIn("UserId", credentials)
self.assertEqual(credentials["Name"], "Stable Demo")

30 changes: 14 additions & 16 deletions tests/test_unwatched.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,22 +84,19 @@ def test_specific_unwatched_unknown_special_season(self):
@pytest.mark.block_network
def test_specific_unwatched_special_season(self):
# Pioneer One does not have a special season, so we need to mock it.
client_type = namedtuple('client', ['jellyfin'])
client_type = namedtuple("client", ["jellyfin"])
client = client_type(Mock())
show_dict = {
"Id": 4,
"Name": "Foo Bar"
}
show_dict = {"Id": 4, "Name": "Foo Bar"}
special_dict = {
"IndexNumber": 0,
"ChildCount": 1,
"UserData": {"UnplayedItemCount": 0}
}
"UserData": {"UnplayedItemCount": 0},
}
client.jellyfin.get_seasons.return_value = [Item(special_dict)]
with patch(
"jellyash.unwatched.search_single_show",
return_value=Item(show_dict)
):
return_value=Item(show_dict),
):
specific_unwatched(client, "Foo Bar", 0)
captured = self.capsys.readouterr()
name = "Foo Bar, Specials"
Expand All @@ -118,17 +115,17 @@ def test_specific_unwatched_not_found(self):
@pytest.mark.block_network
def test_unwatched_season_without_show(self):
with patch("jellyash.unwatched.authed_client"):
with patch("argparse.ArgumentParser.parse_args",
return_value=argparse.Namespace(show=[], season=3)
with patch(
"argparse.ArgumentParser.parse_args",
return_value=argparse.Namespace(show=[], season=3),
):
# Sigh, parser.error will always exit.
with self.assertRaises(SystemExit):
unwatched()
captured = self.capsys.readouterr()
self.assertEqual(captured.out, "")
self.assertIn(
"Need to specify a show when specifiying a season",
captured.err
"Need to specify a show when specifiying a season", captured.err
)


Expand All @@ -139,7 +136,7 @@ def test_unwatched_all(self):
with patch("jellyash.unwatched.all_unwatched") as all_mock:
with patch(
"argparse.ArgumentParser.parse_args",
return_value=argparse.Namespace(show=[], season=None)
return_value=argparse.Namespace(show=[], season=None),
):
unwatched()
all_mock.assert_called_once_with(client_mock())
Expand All @@ -149,10 +146,11 @@ def test_unwatched_specific(self):
namespace = argparse.Namespace(show=["Foo", "Bar"], season=None)
with patch("jellyash.unwatched.authed_client") as client_mock:
with patch(
"jellyash.unwatched.specific_unwatched") as specific_mock:
"jellyash.unwatched.specific_unwatched"
) as specific_mock:
with patch(
"argparse.ArgumentParser.parse_args",
return_value=namespace
return_value=namespace,
):
unwatched()
specific_mock.assert_called_once_with(
Expand Down

0 comments on commit 3ca940b

Please sign in to comment.