Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Workflow actions #9

Merged
merged 4 commits into from
May 8, 2024
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
34 changes: 34 additions & 0 deletions .github/workflows/codeconv.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Upload coverage reports to Codecov

jobs:
run:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python 3.12
uses: actions/setup-python@v4
with:
python-version: '3.12'
- name: Install dependencies
run: pip install -r requirements.txt
- name: Run ATS
uses: codecov/codecov-ats@v0
env:
# CODECOV_STATIC_TOKEN: ${{ secrets.CODECOV_STATIC_TOKEN }}
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
- name: Run tests and collect coverage
run: pytest --cov --cov-report=xml ${{ env.CODECOV_ATS_TESTS }}
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4.2.0
with:
flags: smart-tests
verbose: true
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

flag_management:
default_rules:
carryforward: true
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,7 @@ schools_data.json
log.log

.DS_Store

__pycache__/

.vscode/
12 changes: 11 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,17 @@ All notable changes to this project will be documented in this file.

## [Unreleased]

## [0.0.1] - 2014-05-31
### Added

- better excetions handling and logging
- `class Komens`
- count unread messages

### Fixed

- Invalid refresh token

## [0.0.1]

### Added

Expand Down
16 changes: 11 additions & 5 deletions exceptions.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
"""Exceptions."""

from logger_api import api_logger

logger = api_logger("Bakalari API").get


class APIException(Exception):
"""General API exception."""


def __init__(self, message, *args, **kwargs):
super().__init__(message)
logger.error(f"({self.__class__.__name__}): {self}")

class Ex(APIException):
"""Root exception class."""

Expand All @@ -25,13 +32,12 @@ class InvalidHTTPMethod(APIException):

class InvalidLogin(APIException):
"""Invalid login (username/password)."""

class AccessTokenExpired(APIException):
"""Access token expired. Refresh with refresh token."""

class RefreshTokenExpired(APIException):
"""Refresh token expired. You have to login with username and password."""

class TokensExpired(APIException):
"""Access token and refresh token expired."""

51 changes: 51 additions & 0 deletions logger_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
"""Bakalari API logger"""

import logging


class CustomFormatter(logging.Formatter):

black = "\u001b[30m"
yellow = "\u001b[33m"
red = "\u001b[31m"
bold_red = "\x1b[31;1m"
reset = "\\u001b[0m"
green = "\u001b[32m"
grey = "\u001b[30m;1"
blue = "\u001b[34m"
magenta = "\u001b[35m"
cyan = "\u001b[36m"
white= "\u001b[37m"

format = f"%(asctime)s - %(name)s - %(levelname)s - %(threadName)s:\n {cyan}Message: %(message)s\n{magenta}@(%(filename)s:%(lineno)d)"
dateformat = "%d/%m/%Y %H:%M:%S"

FORMATS = {
logging.DEBUG: grey + format + reset,
logging.INFO: green + format + reset,
logging.WARNING: yellow + format + reset,
logging.ERROR: bold_red + format + reset,
logging.CRITICAL: bold_red + format + reset,
}

def format(self, record):
log_fmt = self.FORMATS.get(record.levelno)
formatter = logging.Formatter(log_fmt)
return formatter.format(record)


class api_logger(object):

def __init__(self, name):
self.name = name

self.console_formatter = CustomFormatter()
self.console_logger = logging.StreamHandler()
self.console_logger.setFormatter(CustomFormatter())

self.logger = logging.getLogger(name)
self.logger.addHandler(self.console_logger)

@property
def get(self):
return self.logger
24 changes: 24 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
aiohttp==3.9.5
aioresponses==0.7.6
aiosignal==1.3.1
asyncio==3.4.3
attrs==23.2.0
coverage==7.5.1
frozenlist==1.4.1
idna==3.7
iniconfig==2.0.0
logger==1.4
multidict==6.0.5
orjson==3.10.3
packaging==24.0
pluggy==1.5.0
pytest==8.2.0
pytest-aiohttp==1.0.5
pytest-asyncio==0.23.6
pytest-cov==5.0.0
pytest-mock==3.14.0
pytest_async==0.1.1
setuptools==69.5.1
StrEnum==0.4.15
typing==3.7.4.3
yarl==1.9.4