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

[MISC] Fix compilation on python3.10, correct workflow file for python3.10, fix pre-commit-config.yaml + github CI #29

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
f48a22c390eed8c49d762af35006aaa3a225a468
2 changes: 1 addition & 1 deletion .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: [3.8, 3.9, 3.10, 3.11]
python-version: [3.8, 3.9, "3.10", 3.11]

steps:
- uses: actions/checkout@v2
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,6 @@ htmlcov
.mypy_cache
.ropeproject
tags

.coverage.*
.tool-versions
57 changes: 33 additions & 24 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,31 +1,40 @@
- repo: https://github.com/pre-commit/pre-commit-hooks.git
sha: 5bf6c09bfa1297d3692cadd621ef95f1284e33c0
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks.git
rev: "v4.5.0"
hooks:
- id: check-added-large-files
- id: check-ast
- id: check-byte-order-marker
- id: check-docstring-first
- id: check-merge-conflict
- id: check-symlinks
- id: debug-statements
- id: detect-private-key
- id: end-of-file-fixer
- id: forbid-new-submodules
- id: check-json
- id: check-xml
- id: check-yaml
- repo: https://github.com/Lucas-C/pre-commit-hooks-safety
sha: v1.1.0
- id: check-added-large-files
- id: check-ast
- id: check-byte-order-marker
- id: check-docstring-first
- id: check-merge-conflict
- id: check-symlinks
- id: debug-statements
- id: detect-private-key
- id: end-of-file-fixer
- id: forbid-new-submodules
- id: check-json
- id: check-xml
- id: check-yaml
- repo: https://github.com/Lucas-C/pre-commit-hooks-safety
rev: v1.1.0
hooks:
- id: python-safety-dependencies-check
- repo: https://github.com/Lucas-C/pre-commit-hooks-bandit
sha: v1.0.3
- id: python-safety-dependencies-check
- repo: https://github.com/Lucas-C/pre-commit-hooks-bandit
rev: v1.0.3
hooks:
- id: python-bandit-vulnerability-check
- repo: local
- id: python-bandit-vulnerability-check
- repo: local
hooks:
- id: py.test
- id: py.test
name: py.test
language: system
entry: sh -c 'TEST_SKIP_CAPPED=1 py.test'
files: ''
files: ""
- id: black
name: Black formatter
description: "Black: The uncompromising Python code formatter"
entry: black
language: system
minimum_pre_commit_version: 2.9.2
require_serial: true
types_or: [python, pyi]
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,3 @@ release:
${PROJECT}.egg-info/PKG-INFO: pyproject.toml
@mkdir -p ${VIRTUAL_ENV}/lib/pip-cache
pip install --cache-dir "${VIRTUAL_ENV}/lib/pip-cache" -Ue ".[${USE}]"

3 changes: 1 addition & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ classifiers = [
"Topic :: Software Development :: Libraries :: Python Modules",
"Topic :: Utilities"
]
dependencies = [] # URI has no direct runtime dependencies.
dependencies = ["importlib_metadata"]
dynamic = ["version"]

[project.urls]
Expand Down Expand Up @@ -144,4 +144,3 @@ warn_no_return = false
# required to support namespace packages
# https://github.com/python/mypy/issues/14057
explicit_package_bases = true

46 changes: 23 additions & 23 deletions test/test_003_path_like_division.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,35 @@


def test_issue_003_path_like_division_trailing():
base = URI("http://example.com/foo/")
assert str(base) == "http://example.com/foo/"
assert str(base / "bar.html") == "http://example.com/foo/bar.html"
base = URI("http://example.com/foo")
assert str(base) == "http://example.com/foo"
assert str(base / "bar.html") == "http://example.com/bar.html"
base = URI("http://example.com/foo/")
assert str(base) == "http://example.com/foo/"
assert str(base / "bar.html") == "http://example.com/foo/bar.html"

base = URI("http://example.com/foo")
assert str(base) == "http://example.com/foo"
assert str(base / "bar.html") == "http://example.com/bar.html"


def test_issue_003_path_like_division_operators():
base = URI("http://example.com/foo/bar.html")
assert str(base / "baz.html") == 'http://example.com/foo/baz.html'
assert str(base // "cdn.example.com" / "baz.html") == 'http://cdn.example.com/baz.html'
assert str(base / "/diz") == 'http://example.com/diz'
assert str(base / "#diz") == 'http://example.com/foo/bar.html#diz'
assert str(base / "https://example.com") == 'https://example.com/'
base = URI("http://example.com/foo/bar.html")
assert str(base / "baz.html") == "http://example.com/foo/baz.html"
assert str(base // "cdn.example.com" / "baz.html") == "http://cdn.example.com/baz.html"
assert str(base / "/diz") == "http://example.com/diz"
assert str(base / "#diz") == "http://example.com/foo/bar.html#diz"
assert str(base / "https://example.com") == "https://example.com/"


def test_issue_003_path_on_path_division():
base = URI("http://ats.example.com/job/listing")
# scrape the listing, identify a job URL from that listing
target = URI("detail/sample-job") # oh no, it's relative!
# And it's resolved.
assert str(base / target) == "http://ats.example.com/job/detail/sample-job"
base = URI("http://ats.example.com/job/listing")

# scrape the listing, identify a job URL from that listing
target = URI("detail/sample-job") # oh no, it's relative!

# And it's resolved.
assert str(base / target) == "http://ats.example.com/job/detail/sample-job"


def test_pathlike_construction():
target = URI("http:") // "example.com"
assert str(target) == "http://example.com/"
assert str(target / "foo") == "http://example.com/foo"
target = URI("http:") // "example.com"
assert str(target) == "http://example.com/"
assert str(target / "foo") == "http://example.com/foo"
111 changes: 54 additions & 57 deletions test/test_bucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,66 +3,63 @@
from uri.bucket import Bucket

EXAMPLES = [
# String, Arguments, Name, Value, Valid

( '', ('', ), None, '', True ),
( 'foo', ('foo', ), None, 'foo', True ),
( 'foo', (None, 'foo'), None, 'foo', True ),
( 'foo=bar', ('foo', 'bar'), 'foo', 'bar', True ),

( '=foo=bar', ('=foo=bar', ), '', 'foo=bar', False ),
( '=foo=bar', ('=foo', 'bar'), '=foo', 'bar', False ),
( '=foo=bar', ('', 'foo=bar'), '', 'foo=bar', False ),
( 'foo=bar=', ('foo', 'bar='), 'foo', 'bar=', False ),
( 'foo==bar=', ('foo=', 'bar='), 'foo=', 'bar=', False ),
( 'foo==bar=', ('foo==bar=', ), 'foo', '=bar=', False ),
( '=foo=bar=', ('=foo=bar=', ), '', 'foo=bar=', False ),

]
# String, Arguments, Name, Value, Valid
("", ("",), None, "", True),
("foo", ("foo",), None, "foo", True),
("foo", (None, "foo"), None, "foo", True),
("foo=bar", ("foo", "bar"), "foo", "bar", True),
("=foo=bar", ("=foo=bar",), "", "foo=bar", False),
("=foo=bar", ("=foo", "bar"), "=foo", "bar", False),
("=foo=bar", ("", "foo=bar"), "", "foo=bar", False),
("foo=bar=", ("foo", "bar="), "foo", "bar=", False),
("foo==bar=", ("foo=", "bar="), "foo=", "bar=", False),
("foo==bar=", ("foo==bar=",), "foo", "=bar=", False),
("=foo=bar=", ("=foo=bar=",), "", "foo=bar=", False),
]


@pytest.mark.parametrize('string,args,name,value,valid', EXAMPLES)
@pytest.mark.parametrize("string,args,name,value,valid", EXAMPLES)
class TestBucketExamples:
def test_string_identity(self, string, args, name, value, valid):
bucket = Bucket(string)
assert str(bucket) == string

def test_names(self, string, args, name, value, valid):
bucket = Bucket(*args)
assert bucket.name == name

def test_values(self, string, args, name, value, valid):
bucket = Bucket(*args)
assert bucket.value == value

def test_validity(self, string, args, name, value, valid):
bucket = Bucket(string)
assert bucket.valid == valid

def test_identity_comparison(self, string, args, name, value, valid):
bucket = Bucket(string)
assert bucket == string

def test_unequal_comparison(self, string, args, name, value, valid):
bucket = Bucket(*args)
assert not (bucket == "xxx")

def test_not_equal_comparison(self, string, args, name, value, valid):
bucket = Bucket(*args)
assert bucket != "xxx"

def test_repr(self, string, args, name, value, valid):
bucket = Bucket(*args)
assert repr(bucket) == "Bucket(" + str(bucket) + ")"

def test_length(self, string, args, name, value, valid):
bucket = Bucket(*args)
expected = 2 if '=' in string else 1
assert len(bucket) == expected
def test_string_identity(self, string, args, name, value, valid):
bucket = Bucket(string)
assert str(bucket) == string

def test_names(self, string, args, name, value, valid):
bucket = Bucket(*args)
assert bucket.name == name

@pytest.mark.parametrize('string,args,name,value,valid', [i for i in EXAMPLES if not i[4]])
def test_values(self, string, args, name, value, valid):
bucket = Bucket(*args)
assert bucket.value == value

def test_validity(self, string, args, name, value, valid):
bucket = Bucket(string)
assert bucket.valid == valid

def test_identity_comparison(self, string, args, name, value, valid):
bucket = Bucket(string)
assert bucket == string

def test_unequal_comparison(self, string, args, name, value, valid):
bucket = Bucket(*args)
assert not (bucket == "xxx")

def test_not_equal_comparison(self, string, args, name, value, valid):
bucket = Bucket(*args)
assert bucket != "xxx"

def test_repr(self, string, args, name, value, valid):
bucket = Bucket(*args)
assert repr(bucket) == "Bucket(" + str(bucket) + ")"

def test_length(self, string, args, name, value, valid):
bucket = Bucket(*args)
expected = 2 if "=" in string else 1
assert len(bucket) == expected


@pytest.mark.parametrize("string,args,name,value,valid", [i for i in EXAMPLES if not i[4]])
class TestBucketExamplesInvalid:
def test_strict_string_failure(self, string, args, name, value, valid):
with pytest.raises(ValueError):
Bucket(string, strict=True)
def test_strict_string_failure(self, string, args, name, value, valid):
with pytest.raises(ValueError):
Bucket(string, strict=True)
87 changes: 40 additions & 47 deletions test/test_parser_dburi.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,53 +5,46 @@
from uri.qso import SENTINEL

EXAMPLES = {
# Examples from: https://github.com/ferrix/dj-mongohq-url/blob/master/test_dj_mongohq_url.py
'': {
'name': '',
'host': None,
'user': None,
'password': None,
'port': None
},
'mongodb://heroku:wegauwhgeuioweg@linus.mongohq.com:10031/app4523234': {
'engine': 'mongodb',
'name': 'app4523234',
'host': 'linus.mongohq.com',
'user': 'heroku',
'password': 'wegauwhgeuioweg',
'port': 10031
},
'postgis://uf07k1i6d8ia0v:wegauwhgeuioweg@ec2-107-21-253-135.compute-1.amazonaws.com:5431/d8r82722r2kuvn': {
'engine': 'postgis',
'name': 'd8r82722r2kuvn',
'host': 'ec2-107-21-253-135.compute-1.amazonaws.com',
'user': 'uf07k1i6d8ia0v',
'password': 'wegauwhgeuioweg',
'port': 5431
},

# '': {
# 'engine': '',
# 'name': ''
# 'host': ''
# 'user': ''
# 'password': ''
# 'port':
# },
}
# Examples from: https://github.com/ferrix/dj-mongohq-url/blob/master/test_dj_mongohq_url.py
"": {"name": "", "host": None, "user": None, "password": None, "port": None},
"mongodb://heroku:wegauwhgeuioweg@linus.mongohq.com:10031/app4523234": {
"engine": "mongodb",
"name": "app4523234",
"host": "linus.mongohq.com",
"user": "heroku",
"password": "wegauwhgeuioweg",
"port": 10031,
},
"postgis://uf07k1i6d8ia0v:wegauwhgeuioweg@ec2-107-21-253-135.compute-1.amazonaws.com:5431/d8r82722r2kuvn": {
"engine": "postgis",
"name": "d8r82722r2kuvn",
"host": "ec2-107-21-253-135.compute-1.amazonaws.com",
"user": "uf07k1i6d8ia0v",
"password": "wegauwhgeuioweg",
"port": 5431,
},
# '': {
# 'engine': '',
# 'name': ''
# 'host': ''
# 'user': ''
# 'password': ''
# 'port':
# },
}


@pytest.mark.parametrize('string,attributes', EXAMPLES.items())
@pytest.mark.parametrize("string,attributes", EXAMPLES.items())
class TestDBURIParsing:
@pytest.mark.parametrize('component', URI.__all_parts__ | {'base', 'qs', 'summary', 'relative'})
def test_component(self, string, attributes, component):
return
instance = URI(string)
value = getattr(instance, component, SENTINEL)
if component not in attributes:
assert value in (None, SENTINEL, '')
return
assert value == attributes[component]
@pytest.mark.parametrize("component", URI.__all_parts__ | {"base", "qs", "summary", "relative"})
def test_component(self, string, attributes, component):
return

instance = URI(string)
value = getattr(instance, component, SENTINEL)

if component not in attributes:
assert value in (None, SENTINEL, "")
return

assert value == attributes[component]
Loading