File tree 2 files changed +56
-2
lines changed
2 files changed +56
-2
lines changed Original file line number Diff line number Diff line change 1
1
import logging
2
2
import sys
3
3
from abc import ABC , abstractmethod
4
- from argparse import ArgumentDefaultsHelpFormatter , ArgumentParser
4
+ from argparse import ArgumentDefaultsHelpFormatter , ArgumentParser , Namespace
5
5
from pathlib import Path
6
- from typing import List , Optional , Dict , Any
6
+ from typing import Any , Dict , List , Optional
7
7
8
8
from lxml import etree
9
9
Original file line number Diff line number Diff line change
1
+ import pytest # noqa
2
+
3
+ from tctools .common import Tool
4
+
5
+
6
+ class MyTool (Tool ):
7
+ """Dummy tool."""
8
+
9
+ CONFIG_KEY = "dummy"
10
+
11
+ @classmethod
12
+ def set_arguments (cls , parser ):
13
+ super ().set_arguments (parser )
14
+
15
+ parser .add_argument (
16
+ "--my-option" ,
17
+ action = "store" ,
18
+ default = "default-text" ,
19
+ )
20
+ return parser
21
+
22
+ def run (self ) -> int :
23
+ return 0 # Do nothing
24
+
25
+
26
+ class TestCommon :
27
+ """Directly test the common interface."""
28
+
29
+ def test_cli_arguments (self ):
30
+ tool = MyTool ("--my-option" , "xyz123" )
31
+ assert tool .args .my_option == "xyz123"
32
+
33
+ def test_cli_arguments_default (self ):
34
+ tool = MyTool ()
35
+ assert tool .args .my_option == "default-text"
36
+
37
+ def test_config_file (self , tmp_path , monkeypatch ):
38
+ conf_dir = tmp_path / "project"
39
+ work_dir = conf_dir / "subdir1" / "subdir2"
40
+ work_dir .mkdir (parents = True )
41
+
42
+ conf_file = conf_dir / "tctools.toml"
43
+ conf_file .write_text (
44
+ """[tctools.dummy]
45
+ my_option = "xyz123"
46
+ """
47
+ )
48
+
49
+ monkeypatch .chdir (work_dir )
50
+
51
+ tool = MyTool ()
52
+ assert tool .args .my_option == "xyz123"
53
+
54
+ # TODO: Add test for section priority
You can’t perform that action at this time.
0 commit comments