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

Clean up code with black, add tests workflow #5

Merged
3 commits merged into from
Feb 27, 2022
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
61 changes: 61 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: Tests

on:
push:
branches:
- main
pull_request:

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup Python
uses: actions/setup-python@v1
with:
python-version: '3.9'
- uses: psf/black@stable
with:
options: "--check --verbose"

run-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
submodules: recursive
- name: Setup Python
uses: actions/setup-python@v1
with:
python-version: '3.9'
- name: Install dependencies
run: |
python3 -m pip install --upgrade pip
python3 -m pip install poetry
- name: Install project and its dependencies
run: poetry install
- name: Run tests
run: poetry run pytest --cache-clear tests

comment-coverage:
if: github.event.pull_request
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
submodules: recursive
- name: Setup Python
uses: actions/setup-python@v1
with:
python-version: '3.9'
- name: Install dependencies
run: |
python3 -m pip install --upgrade pip
python3 -m pip install poetry
- name: Install project and its dependencies
run: poetry install
- name: Build coverage file
run: poetry run pytest --cache-clear --cov=urtypes tests > pytest-coverage.txt
- name: Comment coverage
uses: coroo/[email protected]
375 changes: 375 additions & 0 deletions poetry.lock

Large diffs are not rendered by default.

36 changes: 36 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# The MIT License (MIT)

# Copyright (c) 2021 Tom J. Sun

# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:

# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.

# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

[tool.poetry]
name = "urtypes"
version = "0.1.0"
description = "Python implementation of the Blockchain Commons UR Types specification"
authors = ["Jeff S <[email protected]>"]

[tool.poetry.dependencies]
python = "^3.9.1"

[tool.poetry.dev-dependencies]
pytest = "^6.2.5"
pytest-mock = "^3.6.1"
pytest-cov = "^3.0.0"
black = "^22.1.0"
2 changes: 1 addition & 1 deletion src/urtypes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@
# THE SOFTWARE.

from .registry import *
from .bytes import *
from .bytes import *
37 changes: 19 additions & 18 deletions src/urtypes/bytes.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,24 @@

from urtypes import RegistryType, RegistryItem

BYTES = RegistryType('bytes', None)
BYTES = RegistryType("bytes", None)


class Bytes(RegistryItem):
def __init__(self, data):
super().__init__()
self.data = data
def __eq__(self, o):
return self.data == o.data
@classmethod
def registry_type(cls):
return BYTES
def to_data_item(self):
return self.data

@classmethod
def from_data_item(cls, item):
return cls(cls.mapping(item))
def __init__(self, data):
super().__init__()
self.data = data

def __eq__(self, o):
return self.data == o.data

@classmethod
def registry_type(cls):
return BYTES

def to_data_item(self):
return self.data

@classmethod
def from_data_item(cls, item):
return cls(cls.mapping(item))
2 changes: 1 addition & 1 deletion src/urtypes/cbor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@

from .data import *
from .decoder import *
from .encoder import *
from .encoder import *
65 changes: 39 additions & 26 deletions src/urtypes/cbor/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,41 +23,54 @@
# THE SOFTWARE.
# coding: utf-8


class Tagging(object):
__slots__ = ("tag", "obj")
def __init__(self, tag, obj):
self.tag = tag
self.obj = obj
def __eq__(self, other):
return isinstance(other, Tagging) and self.tag == other.tag and self.obj == other.obj
__slots__ = ("tag", "obj")

def __init__(self, tag, obj):
self.tag = tag
self.obj = obj

def __eq__(self, other):
return (
isinstance(other, Tagging)
and self.tag == other.tag
and self.obj == other.obj
)


class Mapping(object):
__slots__ = ('map')
def __init__(self, map):
self.map = map
def mapping(obj):
return Mapping(obj)
__slots__ = "map"

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

def mapping(obj):
return Mapping(obj)


class DataItem(Tagging):
def __init__(self, tag, map):
super().__init__(tag, Mapping(map))
self.tag = tag
self.map = map

def __init__(self, tag, map):
super().__init__(tag, Mapping(map))
self.tag = tag
self.map = map


class _Undefined(object):
_instance = None
_instance = None

def __new__(cls, *args, **kwargs):
if not isinstance(cls._instance, cls):
cls._instance = object.__new__(cls, *args, **kwargs)
return cls._instance

def __new__(cls, *args, **kwargs):
if not isinstance(cls._instance, cls):
cls._instance = object.__new__(cls, *args, **kwargs)
return cls._instance
def __str__(self):
return "Undefined"

def __str__(self):
return "Undefined"
def __repr__(self):
return "Undefined"

def __repr__(self):
return "Undefined"

Undefined = _Undefined()

__all__ = ["Tagging", "Mapping", "DataItem"]
__all__ = ["Tagging", "Mapping", "DataItem"]
Loading