@@ -30,32 +30,31 @@ def test_load_invalid_yaml_raise() -> None:
30
30
@unittest .mock .patch ("joft.utils.pathlib.Path.cwd" )
31
31
@unittest .mock .patch ("joft.utils.platformdirs" )
32
32
def test_load_toml_app_config (mock_platformdirs , mock_cwd ) -> None :
33
- """Test if we can find the app config file in one of the platform dirs"""
34
- hostname = "test"
35
- pat_token = "pat_token"
33
+ """Test if we can find the app config file in one of the platform dirs
36
34
37
- config_file_contents = b"""[jira.server]
38
- hostname = "test"
39
- pat_token = "pat_token"
35
+ Assert that user_config_dir is preferred over site_config_dir."""
36
+ config_file_contents = """[jira.server]
37
+ hostname = "{name}"
38
+ pat_token = "__pat_token__"
40
39
"""
41
40
42
41
with tempfile .TemporaryDirectory () as tmpdir :
43
42
mock_cwd .return_value = tmpdir
44
43
dir_names = ["etc" , ".config" ]
45
44
for name in dir_names :
46
- config_dir = tmpdir + "/" + name
45
+ config_dir = os . path . join ( tmpdir , name )
47
46
os .makedirs (config_dir )
48
47
49
- with open ( tmpdir + "/" + dir_names [ 1 ] + "/" + " joft.config.toml" , "wb " ) as fp :
50
- fp .write (config_file_contents )
48
+ with open ( os . path . join ( config_dir , " joft.config.toml") , "w " ) as fp :
49
+ fp .write (config_file_contents . format ( name = name ) )
51
50
52
- mock_platformdirs .user_config_dir .return_value = tmpdir + "/" + " .config"
53
- mock_platformdirs .site_config_dir .return_value = ""
51
+ mock_platformdirs .user_config_dir .return_value = os . path . join ( tmpdir , " .config")
52
+ mock_platformdirs .site_config_dir .return_value = os . path . join ( tmpdir , "etc" )
54
53
55
54
config = joft .utils .load_toml_app_config ()
56
55
57
- assert config ["jira" ]["server" ]["hostname" ] == hostname
58
- assert config ["jira" ]["server" ]["pat_token" ] == pat_token
56
+ assert config ["jira" ]["server" ]["hostname" ] == ".config"
57
+ assert config ["jira" ]["server" ]["pat_token" ] == "__pat_token__"
59
58
60
59
61
60
@unittest .mock .patch ("joft.utils.pathlib.Path.cwd" )
0 commit comments