Skip to content

Commit

Permalink
Update pytest
Browse files Browse the repository at this point in the history
- Check TypeError on get_applied_colorscheme
  • Loading branch information
tnagorra committed Jul 12, 2022
1 parent 257e466 commit 7a10b75
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 74 deletions.
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,15 @@ usage: alacritty-colorscheme [-c configuration file] [-C colorscheme directory]
REPO="https://github.com/aaron-williamson/base16-alacritty.git"
DEST="$HOME/.aarors-williamson-colorschemes"

# Get colorschemes
# Get colorschemes
git clone $REPO $DEST

# Make sure the config directory exits
mkdir "$HOME/.config/alacritty/" -p

# Make sure the config file exists
touch -a "$HOME/.config/alacritty/alacritty.yml"

# Create symlink at default colors location (optional)
ln -s "$DEST/colors" "$HOME/.config/alacritty/colors"
```
Expand All @@ -40,8 +47,16 @@ usage: alacritty-colorscheme [-c configuration file] [-C colorscheme directory]
```bash
REPO=https://github.com/eendroroy/alacritty-theme.git
DEST="$HOME/.eendroroy-colorschemes"
# Make sure the config directory exits
mkdir "$HOME/.config/alacritty/" -p
# Make sure the config file exists
touch -a "$HOME/.config/alacritty/alacritty.yml"
# Get colorschemes
git clone $REPO $DEST
# Create symlink at default colors location (optional)
ln -s "$DEST/themes" "$HOME/.config/alacritty/colors"
```
Expand Down
26 changes: 14 additions & 12 deletions alacritty_colorscheme/cli.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#!/usr/bin/env python3

import os

from tap import Tap
from os.path import expanduser, isfile, join
from os import walk
from os.path import expanduser, isfile, isdir, join
from typing import List, Optional, cast
try:
from typing import Literal # type: ignore
Expand Down Expand Up @@ -92,15 +91,18 @@ def create_parser() -> TypedArgumentParser:

def get_files_in_directory(path: str) -> Optional[List[str]]:
expanded_path = expanduser(path)
if not isdir(expanded_path):
return None
try:
onlyfiles = []
for root, _dirs, files in os.walk(expanded_path, followlinks=True):
for file in files:
full_path = join(root, file)
if file.endswith(('.yml', '.yaml')) and isfile(full_path):
onlyfiles.append(full_path.removeprefix(expanded_path))
onlyfiles.sort()
return onlyfiles
files = [join(root, file)
for (root, __dirs, files) in walk(expanded_path, followlinks=True)
for file in files]
# NOTE: joining path with empty string to add a trailing slash to dir
onlyfiles = [file.removeprefix(join(expanded_path, ''))
for file in files
if isfile(file) and file.lower().endswith(('.yml', '.yaml'))]
sortedfiles = sorted(onlyfiles)
return sortedfiles
except OSError:
return None

Expand All @@ -109,7 +111,7 @@ def handle_args(args: TypedArgumentParser) -> None:
if args._subparser_name == 'list':
files = get_files_in_directory(args.colorscheme_dir)
if files is None:
raise RuntimeError(f'Could not find directory: {args.colorscheme_dir}')
raise RuntimeError(f'Could not find colorscheme directory: {args.colorscheme_dir}')
for file in files:
print(file)
elif args._subparser_name == 'status':
Expand Down
10 changes: 6 additions & 4 deletions alacritty_colorscheme/colorscheme.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ def get_applied_colorscheme(config_path: str) -> Optional[str]:
has_comment = _has_comment_token(config_yaml['colors'].ca.comment)
except KeyError:
return None
except TypeError:
return None

if not has_comment:
return None
Expand Down Expand Up @@ -70,13 +72,13 @@ def replace_colorscheme(
try:
# NOTE: update method doesn't read the first comment
config_yaml['colors'].update(colors_yaml['colors'])
# NOTE: We get a KeyError when accessing colors if colors does not exist
except KeyError:
config_yaml['colors'] = colors_yaml['colors']
# NOTE: config_yaml is None when config_file is an empty yml file
# We get a TypeError when accessing colors from None
except TypeError:
if not config_yaml:
config_yaml = {'colors': colors_yaml['colors']}
else:
raise
config_yaml = {'colors': colors_yaml['colors']}

new_comment_token = CommentToken(
f'# COLORSCHEME: {colorscheme}\n',
Expand Down
97 changes: 50 additions & 47 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ classifiers = [
]

[tool.poetry.dependencies]
python = "^3.6"
python = "^3.7"
"ruamel.yaml" = "^0.16.10"
typed-argument-parser = "^1.6.3"
pynvim = "^0.4.2"
typing-extensions = "^3.10.0"
pytest = "7.1.2"

[tool.poetry.dev-dependencies]
pytest = "^5.2"
pyright = "^0.0.7"
flake8 = "^3.9.2"

Expand Down
Empty file.
Loading

0 comments on commit 7a10b75

Please sign in to comment.