Skip to content

Commit

Permalink
Fix get_dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
cokelaer committed Feb 13, 2024
1 parent 502fc34 commit 66453a7
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 37 deletions.
1 change: 1 addition & 0 deletions README.rst
Expand Up @@ -41,6 +41,7 @@ Changelog
========= ==========================================================================
Version Description
========= ==========================================================================
0.13.1 * fix get_dependencies
0.13.0 * fix requirements (line_profiler) and CI
0.12.2 * For developers: move to pyprojet. add precomit
* replace pkg_resources (deprecated) with importlib
Expand Down
2 changes: 1 addition & 1 deletion easydev/dependencies.py
Expand Up @@ -27,7 +27,7 @@ def get_dependencies(pkgname):
"""
try:

res = importlib.metadata.requires("easydev")
res = importlib.metadata.requires(pkgname)
res = [x.split()[0] for x in res]
res = list(set(res))
res.sort()
Expand Down
1 change: 1 addition & 0 deletions easydev/tools.py
Expand Up @@ -22,6 +22,7 @@
"swapdict",
"check_param_in_list",
"check_range",
"checkParam",
"precision",
"AttrDict",
"DevTools",
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Expand Up @@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"

[tool.poetry]
name = "easydev"
version = "0.13.0"
version = "0.13.1"
description = "Commn utilities to ease development of Python packages"
authors = ["Thomas Cokelaer <thomas.cokelaer@pasteur.fr>"]
license = "BSD-3-Clause"
Expand Down
72 changes: 37 additions & 35 deletions test/test_tools.py
@@ -1,103 +1,105 @@
from easydev import TempFile, tools
from easydev import TempFile
from easydev import tools as tools2
from easydev.tools import *


def test_check_range():
tools.check_range(1, 0, 1)
tools.check_range(0, 0, 1)
tools.check_range(0.5, 0, 1)
check_range(1, 0, 1)
check_range(0, 0, 1)
check_range(0.5, 0, 1)

try:
tools.check_range(1, 0, 1, strict=True)
check_range(1, 0, 1, strict=True)
assert False
except:
assert True
try:
tools.check_range(0, 0, 1, strict=True)
check_range(0, 0, 1, strict=True)
assert False
except:
assert True

try:
tools.check_range(10, 0, 1, strict=False)
check_range(10, 0, 1, strict=False)
assert False
except:
assert True
try:
tools.check_range(-10, 0, 1, strict=False)
check_range(-10, 0, 1, strict=False)
assert False
except:
assert True


def test_swapdict():
assert {1: "a"} == tools.swapdict({"a": 1})
assert {1: "a"} == swapdict({"a": 1})

# if the are non-unique values, we can catch the error or no:
try:
tools.swapdict({"a": 1, "b": 1})
swapdict({"a": 1, "b": 1})
assert False
except:
assert True
tools.swapdict({"a": 1, "b": 1}, check_ambiguity=False)
swapdict({"a": 1, "b": 1}, check_ambiguity=False)


def test_tools():
tools.shellcmd("ls")
tools.shellcmd("ls", show=False)
tools.shellcmd("ls", show=True)
output = tools.shellcmd("ls", verbose=True)
tools.shellcmd("lssssssss", verbose=True, ignore_errors=True)
shellcmd("ls")
shellcmd("ls", show=False)
shellcmd("ls", show=True)
output = shellcmd("ls", verbose=True)
shellcmd("lssssssss", verbose=True, ignore_errors=True)

tools.execute("ls")
execute("ls")


def test_tools2():
try:
tools.shellcmd("lsss", verbose=False)
shellcmd("lsss", verbose=False)
assert False
except:
assert True


def test_checkParams():
tools.checkParam(1, [1, 2])
checkParam(1, [1, 2])
try:
tools.checkParam(0, [1, 2])
checkParam(0, [1, 2])
assert False
except:
assert True

try:
tools.checkParam(0, 0)
checkParam(0, 0)
assert False
except TypeError:
assert True


def test_check_param_in_list():
tools.check_param_in_list(1, [0, 1, 5], "test")
check_param_in_list(1, [0, 1, 5], "test")
try:
tools.check_param_in_list(10, [0, 1, 5])
check_param_in_list(10, [0, 1, 5])
assert False
except:
assert True
try:
tools.check_param_in_list(10, [0, 1, 5], "testt")
check_param_in_list(10, [0, 1, 5], "testt")
assert False
except:
assert True


def test_precision():
assert tools.precision(2.123) == 2.12
assert tools.precision(2.123, 1) == 2.1
assert tools.precision(2.123, 3) == 2.123
assert tools.precision(2123, -2) == 2100
assert tools2.precision(2.123) == 2.12
assert tools2.precision(2.123, 1) == 2.1
assert tools2.precision(2.123, 3) == 2.123
assert tools2.precision(2123, -2) == 2100


def test_attrdict():

a = tools.AttrDict(value=1)
a = AttrDict(value=1)
assert a.value == 1
assert "value" in list(a.keys())
assert 1 in (a.values())
Expand All @@ -109,7 +111,7 @@ def test_attrdict():
assert a.output == "txt"

d = {"a": {"b": 1}, "aa": 2}
ad = tools.AttrDict(**d)
ad = AttrDict(**d)
assert ad.a.b == 1
ad.a.b = 2
assert ad.a.b == 2
Expand All @@ -132,7 +134,7 @@ def test_attrdict():


def test_devtools():
d = tools.DevTools()
d = DevTools()
d.check_param_in_list(1, [1, 2])
d.check_range(1, 0, 2)
assert d.list2string(["a", "b"]) == "a,b"
Expand All @@ -155,18 +157,18 @@ def test_mkdirs():
import os
import tempfile

tools.mkdirs(tempfile.mkdtemp() + os.sep + "test")
mkdirs(tempfile.mkdtemp() + os.sep + "test")
try:
tools.mkdirs(tempfile.mkdtemp() + os.sep + "test")
mkdirs(tempfile.mkdtemp() + os.sep + "test")
assert False
except:
assert True

# without / , was not working but is now part of the API
tools.mkdirs(tempfile.mkdtemp())
mkdirs(tempfile.mkdtemp())


def test_touch():
with TempFile() as fh:
fh.name
tools.touch(fh.name)
touch(fh.name)

0 comments on commit 66453a7

Please sign in to comment.