Skip to content

Commit

Permalink
fix: add exc to pyi
Browse files Browse the repository at this point in the history
  • Loading branch information
shpaker authored Nov 21, 2024
1 parent c232592 commit ab10e0d
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "epyxid"
version = "0.3.2"
edition = "2021"
version = "0.3.1"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[lib]
Expand Down
4 changes: 4 additions & 0 deletions epyxid.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ from typing import Optional, Union
__version__: str


class XIDError(ValueError):
pass


class XID:
"""
Globally unique sortable id.
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ requires-python = ">=3.8"
authors = [
{name = "Aleksandr Shpak", email = "shpaker@gmail.com"},
]
version = "0.3.1"
version = "0.3.2"
readme = "README.md"
license = { file = "LICENSE.txt" }
keywords = [
Expand Down
2 changes: 1 addition & 1 deletion src/errors.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use pyo3::create_exception;
use pyo3::exceptions::PyValueError;

create_exception!(mymodule, XIDError, PyValueError);
create_exception!(epyxid, XIDError, PyValueError);
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::errors::XIDError;
use crate::utils::{xid_create, xid_from_bytes, xid_from_str};
use crate::wrapper::XID;

const PY_MODULE_VERSION: &str = "0.3.0";
const PY_MODULE_VERSION: &str = "0.3.2";

mod errors;
mod utils;
Expand Down
10 changes: 8 additions & 2 deletions test_xid.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import Union, Optional

from epyxid import xid_from_bytes, xid_from_str, xid_create, XID
from epyxid import xid_from_bytes, xid_create, XID, XIDError, xid_from_str

from pytest import raises, param, mark

XID_STR = '9m4e2mr0ui3e8a215n4g'
Expand Down Expand Up @@ -30,11 +31,16 @@ def test_create_cls_param(value: Optional[Union[str, bytes]], ) -> None:
assert xid is not None


def test_create_cls_error() -> None:
def test_create_cls_type_error() -> None:
with raises(TypeError):
xid = XID(42)


def test_create_cls_xid_error() -> None:
with raises(XIDError):
xid = XID('42')


def test_from_str_valid() -> None:
xid = xid_from_str(XID_STR)
assert bytes(xid) == XID_BYTES
Expand Down

0 comments on commit ab10e0d

Please sign in to comment.