Skip to content

Commit

Permalink
Removed test for extra.force_sudo_password_promt()
Browse files Browse the repository at this point in the history
It removes user's sudo timestamp which may be inconvenient.
Removed meaningless quantifier "{1}" from gnu_coreutils.cd().
Formatted comments in test files to impove consistency and readability.
  • Loading branch information
Andrew15-5 committed Jan 20, 2022
1 parent f8b29cc commit b1d2055
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 23 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ python3 -m pip install niceshell

```bash
cd /tmp/
version=1.0.1 # Choose desired version
version=1.0.2 # Choose desired version
wget -c "https://github.com/Andrew15-5/niceshell/releases/download/v${version}/niceshell-${version}-py3-none-any.whl"
python3 -m pip -U --user install niceshell-${version}-py3-none-any.whl
```
Expand Down
2 changes: 1 addition & 1 deletion niceshell/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"normalize_short_and_long_args", "quotes_wrapper", "rm", "shell",
"Shell", "ShortArgsOption", "UID", "USER"]
__author__ = "Andrew Voynov"
__version__ = "1.0.1"
__version__ = "1.0.2"

GID = Shell("id -g").output()[:-1]
GROUP = Shell("id -gn").output()[:-1]
Expand Down
2 changes: 1 addition & 1 deletion niceshell/extra.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def force_sudo_password_promt():
def get_root_privileges():
"""
Shows sudo password prompt. Returns True if correct password has been
entered, otherwise returns False (e.g. Ctrl+C was pressed).
entered, otherwise returns False (e.g., Ctrl+C was pressed).
"""
return not shell("sudo true").exit_code()

Expand Down
2 changes: 1 addition & 1 deletion niceshell/gnu_coreutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def cd(path: str = '',
if path:
path = expose_tilde(quotes_wrapper(path))
path = re.sub(r'(?<=[^\\])\*', '"*"', path) # Expose wildcard (*)
path = re.sub(r'\\{1}\*', '*', path) # Preserve '*'
path = re.sub(r'\\\*', '*', path) # Preserve '*'
args = normalize_short_and_long_args(
short_args, [], ShortArgsOption.APART)
command = f"cd {args} -- {path}".strip()
Expand Down
9 changes: 5 additions & 4 deletions niceshell/tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def test_expose_tilde(self):
quotes_wrapper = core.quotes_wrapper

# Errors
# quoted_path must be str
# quoted_path must be str.
with pytest.raises(TypeError):
expose_tilde(1)
with pytest.raises(TypeError):
Expand Down Expand Up @@ -44,13 +44,13 @@ def test_normalize_short_and_long_args(self):
with pytest.raises(TypeError):
normalize('', [1])

# No spaces are allowed in short args which are TOGETHER
# No spaces are allowed in short args which are TOGETHER.
with pytest.raises(ValueError):
normalize(' ')
with pytest.raises(ValueError):
normalize("-a -b")

# (Iterable[str]) Short args which are TOGETHER must be 1 char. long
# (Iterable[str]) Short args which are TOGETHER must be 1 char. long.
with pytest.raises(ValueError):
normalize(["ab"], [])
with pytest.raises(ValueError):
Expand All @@ -60,6 +60,7 @@ def test_normalize_short_and_long_args(self):
with pytest.raises(ValueError):
normalize([], [], True)

# Asserts
# No args
assert normalize() == ''

Expand Down Expand Up @@ -157,7 +158,7 @@ def test_quotes_wrapper(self):
with pytest.raises(TypeError):
wrapper([1])

# Quotes
# Asserts
assert wrapper('') == '""'
assert wrapper(' ') == '" "'
assert wrapper(set(' ')) == '" "'
Expand Down
3 changes: 0 additions & 3 deletions niceshell/tests/test_extra.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@


class TestExtra:
def test_force_sudo_password_promt(self):
assert extra.force_sudo_password_promt() == None

def test_has_root_privileges(self):
assert type(extra.has_root_privileges()) == bool

Expand Down
25 changes: 15 additions & 10 deletions niceshell/tests/test_gnu_coreutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ def test_cp(self):
with pytest.raises(TypeError):
cp('', 1)

# Asserts batch=False
# Asserts
# batch=False
def cp(source_path: Union[str, Iterable[str]],
destination_path: str,
sudo=False,
Expand Down Expand Up @@ -89,7 +90,7 @@ def cp(source_path: Union[str, Iterable[str]],
short_args=['r', 'f', 'b', "S .bak"], long_args=["verbose"]
) == 'sudo cp -r -f -b -S .bak --verbose -- "tmp/dir1" "dir2" ~/"d i r 3/src/" ~'

# Asserts batch=True
# batch=True
def cp(source_path: Union[str, Iterable[str]],
destination_path: str,
sudo=False,
Expand Down Expand Up @@ -141,7 +142,8 @@ def test_ln(self):
with pytest.raises(TypeError):
ln('', 1)

# Asserts batch=False
# Asserts
# batch=False
def ln(source_path: Union[str, Iterable[str]],
destination_path: str,
sudo=False,
Expand Down Expand Up @@ -173,7 +175,7 @@ def ln(source_path: Union[str, Iterable[str]],
short_args=['r', 's', 'f', "S .bak"], long_args=["verbose"]
) == 'sudo ln -r -s -f -S .bak --verbose -- "tmp/dir1" "dir2" ~/"d i r 3/src/" ~'

# Asserts batch=True
# batch=True
def ln(source_path: Union[str, Iterable[str]],
destination_path: str,
sudo=False,
Expand Down Expand Up @@ -219,7 +221,8 @@ def test_ls(self):
with pytest.raises(TypeError):
ls([1], test=True)

# Asserts batch=False
# Asserts
# batch=False
def ls(path: Union[str, Iterable[str]] = '',
sudo=False,
short_args: Union[str, Iterable[str]] = [],
Expand Down Expand Up @@ -251,7 +254,7 @@ def ls(path: Union[str, Iterable[str]] = '',
short_args=['l', 'd', "-I PATTERN"], long_args=["all"]
) == 'sudo ls -l -d -I PATTERN --all -- ~/"here/*" ~/"there/*"'

# Asserts batch=True
# batch=True
def ls(path: Union[str, Iterable[str]] = '',
sudo=False,
short_args: Union[str, Iterable[str]] = [],
Expand Down Expand Up @@ -305,7 +308,8 @@ def test_mv(self):
with pytest.raises(TypeError):
mv('', 1)

# Asserts batch=False
# Asserts
# batch=False
def mv(source_path: Union[str, Iterable[str]],
destination_path: str,
sudo=False,
Expand Down Expand Up @@ -336,7 +340,7 @@ def mv(source_path: Union[str, Iterable[str]],
short_args=['f', 'b', "S .bak"], long_args=["verbose"]
) == 'sudo mv -f -b -S .bak --verbose -- "tmp/dir1" "dir2" ~/"d i r 3/src/" ~'

# Asserts batch=True
# batch=True
def mv(source_path: Union[str, Iterable[str]],
destination_path: str,
sudo=False,
Expand Down Expand Up @@ -384,7 +388,8 @@ def test_rm(self):
with pytest.raises(TypeError):
rm([1])

# Asserts batch=False
# Asserts
# batch=False
def rm(path: Union[str, Iterable[str]],
sudo=False,
short_args: Union[str, Iterable[str]] = [],
Expand Down Expand Up @@ -413,7 +418,7 @@ def rm(path: Union[str, Iterable[str]],
short_args=['r', 'f', "I"], long_args=["verbose"]
) == 'sudo rm -r -f -I --verbose -- "tmp/dir1" "dir2" ~/"d i r 3/src/"'

# Asserts batch=True
# batch=True
def rm(path: Union[str, Iterable[str]],
sudo=False,
short_args: Union[str, Iterable[str]] = [],
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@

setuptools.setup(
name="niceshell",
version="1.0.1",
version="1.0.2",
author="Andrew Voynov",
author_email="[email protected]",
description="Integration of shell and basic GNU core unilities for better coding.",
long_description=long_description,
long_description_content_type="text/markdown",
license="MIT",
url="https://github.com/Andrew15-5/niceshell",
download_url="https://github.com/Andrew15-5/niceshell/releases/download/v1.0.1/niceshell-1.0.1-py3-none-any.whl",
download_url="https://github.com/Andrew15-5/niceshell/releases/download/v1.0.2/niceshell-1.0.2-py3-none-any.whl",
packages=["niceshell", "niceshell/tests"],
package_data={
"niceshell": ['*']
Expand Down

0 comments on commit b1d2055

Please sign in to comment.