Skip to content

Commit

Permalink
Merge branch 'add_linting_rules' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
TabulateJarl8 authored Sep 15, 2024
2 parents be07f6c + 6b462fb commit e1f5758
Show file tree
Hide file tree
Showing 19 changed files with 420 additions and 179 deletions.
16 changes: 0 additions & 16 deletions fix_ruff_docstring_error.py

This file was deleted.

4 changes: 4 additions & 0 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

80 changes: 67 additions & 13 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ description = "TUI program to check the ProtonDB compatibility of all the games
authors = ["TabulateJarl8 <[email protected]>"]
license = "GPLv3"
readme = "README.md"
packages = [{include = "vapor"}]
packages = [{ include = "vapor" }]
homepage = "https://tabulate.tech/software/vapor"
repository = "https://github.com/TabulateJarl8/vapor"
keywords = ["steam", "protondb", "compatibility", "textual", "tui"]
Expand All @@ -22,11 +22,9 @@ classifiers = [
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Typing :: Typed"
]
include = [
{ path = "tests", format = "sdist" },
"Typing :: Typed",
]
include = [{ path = "tests", format = "sdist" }]

[tool.poetry.dependencies]
python = "^3.8.1"
Expand Down Expand Up @@ -81,21 +79,20 @@ exclude_also = [

]

omit = [
"*/__main__.py",
]
omit = ["*/__main__.py"]


[tool.ruff.lint]
preview = true
extend-select = [
# pycodestyle
"E",
"W293",
"W292",
"W605",
# Warnings
"W",
# Pyflakes
"F",
# pydocstyle
"D",
# pyupgrade
"UP",
# flake8-bugbear
Expand Down Expand Up @@ -128,9 +125,66 @@ extend-select = [
# eradicate
"ERA",
# perflint
"PERF"
"PERF",
# flake8-2020
"YTT",
# flake8-annotations
"ANN",
# flake8-async
"ASYNC",
# flake8-builtins
"A",
# flake8-commas
"COM",
# flake8-implicit-str-concat
"ISC",
# flake8-print
"T20",
# flake8-pytest-style
"PT",
# flake8-use-pathlib
"PTH",
# pylint
"PL",
# tryceratops
"TRY",
# refurb
"FURB",
# pydoclint
"DOC",
# ruff rules
"RUF",
]
ignore = ["E501", "E274", "S110", "FBT001", "FBT002", "PERF203", "S101"]

ignore = [
# complains about tab indentation
"W191",
"D206",
# adds a line break before a class docstring
"D203",
# puts the first line summary of a docstring on a different line than the """
"D213",
# tries to add a blank line after the last docstring section
"D413",
# yells at you if you use a bool typed function argument
"FBT001",
"FBT002",
# yells at you for using try-except in a for loop
"PERF203",
# allow for the use of Any
"ANN401",
# false positives for overriding methods (i think)
"PLR6301",
# disable too many branches check
"PLR0912",
]

[tool.ruff.lint.per-file-ignores]
"tests/*" = ["S101", "ANN001", "ANN002", "PLC2701", "ARG002", "PLR2004", "DOC"]
"vapor/main.py" = ["DOC402"]

[tool.ruff.lint.pydocstyle]
convention = "google"

[tool.ruff.format]
quote-style = "single"
Expand Down
1 change: 1 addition & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""__init__.py for the AUR."""
68 changes: 49 additions & 19 deletions tests/test_api_interface.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
"""Tests related to vapor's API interface."""

import json
from unittest.mock import patch

import pytest

from vapor.api_interface import (
Response,
_extract_game_is_native,
check_game_is_native,
parse_anti_cheat_data,
parse_steam_game_platform_info,
parse_steam_user_games,
)
from vapor.data_structures import AntiCheatStatus, Game
Expand All @@ -29,52 +31,69 @@
'games': [
{'appid': 123456, 'name': 'Test Game 1', 'playtime_forever': 100},
{'appid': 789012, 'name': 'Test Game 2', 'playtime_forever': 200},
]
}
],
},
}

STEAM_GAME_PLATFORM_DATA = {
'123': {
'success': True,
'data': {'platforms': {'windows': True, 'mac': False, 'linux': False}},
}
},
'456': {
'success': True,
'data': {'platforms': {'windows': False, 'mac': True, 'linux': True}},
},
}


class MockCache:
def __init__(self, has_game: bool):
"""Mock Cache object with a set Game data."""

def __init__(self, has_game: bool) -> None:
"""Construct a new MockCache object."""
self.has_game_cache = has_game

def get_game_data(self, app_id): # noqa: ARG002
def get_game_data(self, app_id: None) -> Game:
"""Return a set Game data for testing.
Args:
app_id (None): unused argument.
"""
return Game(
name='Euro Truck Simulator 2',
rating='native',
playtime=12933,
app_id='227300',
)

def update_cache(self, game_list):
pass
def update_cache(self, game_list: None) -> None:
"""Update cache with dummy function. Does nothing.
Args:
game_list (None): unused argument.
"""

@pytest.mark.asyncio
async def test_parse_steam_game_data():
assert await parse_steam_game_platform_info(STEAM_GAME_DATA, '123456')
assert not await parse_steam_game_platform_info(STEAM_GAME_DATA, '789012')
assert not await parse_steam_game_platform_info(STEAM_GAME_DATA, '123')

def test_parse_steam_game_data() -> None:
"""Test that Steam data is correctly parsed."""
assert _extract_game_is_native(STEAM_GAME_DATA, '123456')
assert not _extract_game_is_native(STEAM_GAME_DATA, '789012')
assert not _extract_game_is_native(STEAM_GAME_DATA, '123')

@pytest.mark.asyncio
async def test_parse_anti_cheat_data():
result = await parse_anti_cheat_data(ANTI_CHEAT_DATA)

def test_parse_anti_cheat_data() -> None:
"""Test that anti-cheat data is parsed correctly."""
result = parse_anti_cheat_data(ANTI_CHEAT_DATA)
assert len(result) == 2
assert result[0].app_id == '123456'
assert result[0].status == AntiCheatStatus.DENIED
assert result[1].status == AntiCheatStatus.SUPPORTED


@pytest.mark.asyncio
async def test_parse_steam_user_games():
async def test_parse_steam_user_games() -> None:
"""Test that Steam games are parsed correctly."""
with patch(
'vapor.api_interface.get_game_average_rating',
return_value='gold',
Expand All @@ -86,16 +105,27 @@ async def test_parse_steam_user_games():


@pytest.mark.asyncio
async def test_parse_steam_user_priv_acct():
async def test_parse_steam_user_priv_acct() -> None:
"""Test that Steam private accounts are handled correctly."""
cache = MockCache(has_game=True)
with pytest.raises(PrivateAccountError):
await parse_steam_user_games({'response': {}}, cache) # type: ignore


@pytest.mark.asyncio
async def test_check_game_is_native():
async def test_check_game_is_native() -> None:
"""Test that native games are correctly detected and errors are handled."""
with patch(
'vapor.api_interface.async_get',
return_value=Response(json.dumps(STEAM_GAME_PLATFORM_DATA), 200),
):
assert not await check_game_is_native('123')
assert await check_game_is_native('456')

with patch(
'vapor.api_interface.async_get',
return_value=Response(json.dumps(STEAM_GAME_PLATFORM_DATA), 401),
):
# this should say false even though 456 is native because it
# should fail with a non-200 status code
assert not await check_game_is_native('456')
6 changes: 4 additions & 2 deletions tests/test_arg_parsing.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
"""Tests related to argument parsing."""

import argparse
from unittest.mock import MagicMock, patch

from vapor.argument_handler import parse_args


def test_parse_args_without_clear_cache():
def test_parse_args_without_clear_cache() -> None:
"""Test parsing arguments without --clear-cache flag."""
with patch(
'argparse.ArgumentParser.parse_args',
Expand All @@ -15,7 +17,7 @@ def test_parse_args_without_clear_cache():


@patch('pathlib.Path.unlink', **{'other.side_effect': FileNotFoundError})
def test_parse_args_missing_cache(mock_unlink):
def test_parse_args_missing_cache(mock_unlink) -> None:
"""Test parsing arguments when cache file is missing."""
with patch(
'argparse.ArgumentParser.parse_args',
Expand Down
Loading

0 comments on commit e1f5758

Please sign in to comment.