Skip to content

Commit

Permalink
Add initial tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mstuttgart committed Jun 18, 2024
1 parent 10ace7c commit 507d5c4
Show file tree
Hide file tree
Showing 10 changed files with 63 additions and 30 deletions.
18 changes: 9 additions & 9 deletions .github/workflows/pr_checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:
branches:
- main
paths:
- 'atty/**'
- "atty/**"

jobs:
changelog:
Expand All @@ -18,12 +18,12 @@ jobs:
if: github.event_name == 'pull_request'

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Check that CHANGELOG has been updated
run: |
# If this step fails, this means you haven't updated the CHANGELOG.md
# file with notes on your contribution.
git diff --name-only $(git merge-base origin/main HEAD) | grep '^CHANGELOG.md$' && echo "Thanks for helping keep our CHANGELOG up-to-date!"
- name: Check that CHANGELOG has been updated
run: |
# If this step fails, this means you haven't updated the CHANGELOG.md
# file with notes on your contribution.
git diff --name-only $(git merge-base origin/main HEAD) | grep '^CHANGELOG.md$' && echo "Thanks for helping keep our CHANGELOG up-to-date!"
36 changes: 20 additions & 16 deletions atty/__main__.py → atty/main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import os
from pathlib import Path
import pathlib

import click
import rich
Expand All @@ -10,17 +10,17 @@
from atty.version import VERSION

CONTEXT_SETTINGS = dict(help_option_names=["-h", "--help"])
ALACRITTY_CONFIG_DIR = Path(os.sep.join([str(Path.home()), ".config", "alacritty"]))
ALACRITTY_CONFIG_FILE = Path(os.sep.join([str(ALACRITTY_CONFIG_DIR), "alacritty.toml"]))
ALACRITTY_THEMES_DIR = Path(os.sep.join([str(ALACRITTY_CONFIG_DIR), "themes"]))

ALACRITTY_CONFIG_DIR = pathlib.Path(os.sep.join([str(pathlib.Path.home()), ".config", "alacritty"]))
ALACRITTY_CONFIG_FILE = pathlib.Path(os.sep.join([str(ALACRITTY_CONFIG_DIR), "alacritty.toml"]))
ALACRITTY_THEMES_DIR = pathlib.Path(os.sep.join([str(ALACRITTY_CONFIG_DIR), "themes"]))


console = rich.console.Console()


def _get_theme_file_names(themes_path):

themes = [f.stem for f in Path(themes_path).glob("*.toml")]
themes = [f.stem for f in pathlib.Path(themes_path).glob("*.toml")]
themes.sort()

return themes
Expand All @@ -33,14 +33,13 @@ def _get_atty_symlink_path(config):
def _create_symlink(config, themes_dir, theme_selected):
theme_file = os.sep.join([str(themes_dir), f"{theme_selected}.toml"])

atty_path = Path(_get_atty_symlink_path(config))
atty_path = pathlib.Path(_get_atty_symlink_path(config))

atty_path.unlink(missing_ok=True)
atty_path.symlink_to(theme_file)


def _update_config(config):

alacritty_conf_file = str(config)
alacritty_conf_file_content = {}

Expand All @@ -61,14 +60,10 @@ def _set_theme(config, themes_dir, theme_selected):


def _theme_selection(config, themes_dir, theme):

if not theme:

themes_list = _get_theme_file_names(themes_dir)

msg = (
"Up and Down keys: navegate on themes list\nLeft and Right keys: switch page\nESC key: abort\nSelect Color:"
)
msg = "Up and Down keys: navegate on themes list\nLeft and Right keys: switch page\nESC key: abort\nSelect Color:"

console.print(msg)

Expand All @@ -82,9 +77,18 @@ def _theme_selection(config, themes_dir, theme):

@click.command(context_settings=CONTEXT_SETTINGS)
@click.version_option(VERSION, prog_name="atty")
@click.option("-c", "--config", default=ALACRITTY_CONFIG_FILE, help="Absolute path of Alacritty configuration file")
@click.option("-d", "--theme_dir", default=ALACRITTY_THEMES_DIR, help="Absolute path of themes folder")
@click.option("-t", "--theme", default=None, help="Select a theme by name instead of showing prompt.")
@click.option(
"-c",
"--config",
default=ALACRITTY_CONFIG_FILE,
help="Absolute path of Alacritty configuration file",
)
@click.option(
"-d", "--theme_dir", default=ALACRITTY_THEMES_DIR, help="Absolute path of themes folder"
)
@click.option(
"-t", "--theme", default=None, help="Select a theme by name instead of showing prompt."
)
def atty(config, theme_dir, theme):
"""
CLI for Alacritty color theme and configuration switching.
Expand Down
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ dev = [
]

[project.scripts]
atty = "atty.__main__:atty"
atty = "atty.main:atty"

[tool.setuptools.packages.find]
exclude = ["*.tests", "*.tests.*", "tests.*", "tests", "docs*", "scripts*"]
Expand Down Expand Up @@ -83,9 +83,9 @@ reportPrivateImportUsage = false

[tool.ruff]
line-length = 115
target-version = "py39"
target-version = "py310"

[tool.ruff.per-file-ignores]
[tool.ruff.lint.per-file-ignores]
"__init__.py" = ["F401"]

[tool.mypy]
Expand Down
Empty file.
1 change: 1 addition & 0 deletions tests/.config/alacritty/color.toml
Empty file.
Empty file.
Empty file.
2 changes: 0 additions & 2 deletions tests/hello_test.py

This file was deleted.

30 changes: 30 additions & 0 deletions tests/test_main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import os

from atty.main import _create_symlink, _get_atty_symlink_path, _get_theme_file_names

test_folder_dir = os.path.dirname(os.path.abspath(__file__))


def test__get_atty_symlink_path():
config = ".config/alacritty/alacritty.toml"
res = _get_atty_symlink_path(config)
assert res == ".config/alacritty/color.toml"


def test__get_theme_file_names():
themes_path = f"{test_folder_dir}/.config/alacritty/themes"
themes_filename = _get_theme_file_names(themes_path)

assert themes_filename == ["t1", "t2", "t3"]


def test__create_symlink():
config_file = os.sep.join([test_folder_dir, ".config", "alacritty", "alacritty.toml"])
themes_path = os.sep.join([test_folder_dir, ".config", "alacritty", "themes"])
theme_selected = "t3"

_create_symlink(config_file, themes_path, theme_selected)

symlink_file = os.sep.join([test_folder_dir, ".config", "alacritty", "color.toml"])
assert os.path.exists(symlink_file)
assert os.path.islink(symlink_file)

0 comments on commit 507d5c4

Please sign in to comment.