Add pytest to pyproject.toml dependencies

This commit is contained in:
2025-02-05 10:23:59 +01:00
parent 10169d51e2
commit 3ede967aef
8 changed files with 57 additions and 11 deletions
+21
View File
@@ -0,0 +1,21 @@
# Set up hf-cli for automatic daily downloads
To enable daily runs, you first need to generate a config.json file defining what
to download and where to put it:
```bash
hf-cli --setup
```
then you need to enable the timer for the user and enable lingering, so the timer
is executed even when the user is not logged in:
```bash
systemctl --user enable hf-cli.timer hf-cli.service
loginctl enable-linger
```
You can test the service by running it manually:
```bash
systemctl --user start hf-cli.service
```
+6 -1
View File
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
[project]
name = "hf-cli"
version = "1.0.0"
version = "1.1.1"
description = "Huafetcher CLI"
readme = "README.md"
license = {file = "LICENSE"}
@@ -20,6 +20,11 @@ classifiers = [
"Programming Language :: Python"
]
[dependency-groups]
test = [
"pytest"
]
[tool.setuptools]
include-package-data = true
View File
+8 -2
View File
@@ -4,6 +4,7 @@ AmazFit key and agps fetcher, that can also be used to schedule daily updates
"""
import tempfile
import sys
from argparse import ArgumentError
from .fetcher import Fetcher
from .config_handler import ConfigHandler
@@ -12,11 +13,16 @@ from .config_error import ConfigError
def run():
handler = ArgsHandler()
args = handler.parse_args(sys.argv)
try:
args = handler.parse_args(sys.argv[1:])
except ArgumentError as e:
print(e.message)
print(handler.print_help())
exit(4)
try:
config = ConfigHandler(args, 'hf-cli')
except ConfigError as e:
except ConfigError:
print('Neither -k, -a or targets where provided and no config file containing targets could be found')
exit(3)
+1 -2
View File
@@ -5,8 +5,7 @@ from argparse import Namespace
from enum import Enum
from tempfile import TemporaryFile, TemporaryDirectory
from ..hf_cli.config_handler import ConfigHandler
from hf_cli.config_handler import ConfigHandler
class Part(Enum):
TARGET_DIR = 1
+15 -1
View File
@@ -1,7 +1,7 @@
import unittest
from argparse import ArgumentError
from ..hf_cli.args_handler import ArgsHandler
from hf_cli.args_handler import ArgsHandler
class ArgsHandlerTest(unittest.TestCase):
@@ -33,6 +33,20 @@ class ArgsHandlerTest(unittest.TestCase):
self.assertIsNone(actual.target_dir)
self.assertIsNone(actual.config_path)
def test_setup_doesnt_require_targets(self):
sut = ArgsHandler()
actual = sut.parse_args(['--setup'])
self.assertSequenceEqual([], actual.targets, "Targets don't match")
self.assertFalse(actual.verbose)
self.assertFalse(actual.save)
self.assertFalse(actual.uihh)
self.assertFalse(actual.all)
self.assertTrue(actual.setup)
self.assertFalse(actual.keys)
self.assertFalse(actual.use_config)
self.assertIsNone(actual.target_dir)
self.assertIsNone(actual.config_path)
def test_unknown_target_fails(self):
sut = ArgsHandler()
with self.assertRaises(ArgumentError) as ctx:
+4 -3
View File
@@ -6,8 +6,8 @@ import inspect
from systemd.journal import JournalHandler
from ..hf_cli.args_handler import ArgsHandler
from ..hf_cli.config_handler import ConfigHandler
from hf_cli.args_handler import ArgsHandler
from hf_cli.config_handler import ConfigHandler
from .config_generator import Part, ConfigGenerator, get_failure_message
@@ -19,7 +19,8 @@ class ConfigHandlerTest(unittest.TestCase):
def test_default_config_path(self):
args = ArgsHandler().parse_args(['EPO'])
actual = ConfigHandler.get_config_path(args)
self.assertEqual(os.path.expanduser('~/.config/hf-cli/config.json'), actual)
expect = '/etc/hf-cli/config.json' if os.getuid() == 0 else os.path.expanduser('~/.config/hf-cli/config.json')
self.assertEqual(expect, actual)
def test_provided_config_path(self):
with self.__config_file_generator.create_config_file(Part.TARGETS) as config_dir_path:
+2 -2
View File
@@ -3,8 +3,8 @@ import os
import unittest
from tempfile import TemporaryDirectory
from ..hf_cli.args_handler import ArgsHandler
from ..hf_cli.config_handler import ConfigHandler
from hf_cli.args_handler import ArgsHandler
from hf_cli.config_handler import ConfigHandler
from .config_generator import Part, ConfigGenerator, get_failure_message