Skip to content

Commit ff8af1b

Browse files
authored
[tests] Add test for creating missing file and parent dirs from conf_path() (#39)
1 parent 9a4c700 commit ff8af1b

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

pgserviceparser/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from .exceptions import ServiceFileNotFound, ServiceNotFound
1010

1111

12-
def conf_path(create_if_missing: bool = False) -> Path:
12+
def conf_path(create_if_missing: Optional[bool] = False) -> Path:
1313
"""Returns the path found for the pg_service.conf on the system as string.
1414
1515
Args:

test/test_lib.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,25 @@ def test_remove_service(self):
123123
self.assertIn("service_tmp", service_names())
124124
remove_service("service_tmp")
125125

126+
def test_missing_file(self):
127+
another_service_file_path = PGSERVICEPARSER_SRC_PATH / "test" / "data" / "new_folder" / "pgservice.conf"
128+
os.environ["PGSERVICEFILE"] = str(another_service_file_path)
129+
130+
self.assertEqual(another_service_file_path, conf_path())
131+
self.assertFalse(another_service_file_path.exists())
132+
self.assertFalse(another_service_file_path.parent.exists())
133+
134+
self.assertEqual(another_service_file_path, conf_path(create_if_missing=True))
135+
self.assertTrue(another_service_file_path.exists())
136+
self.assertTrue(another_service_file_path.parent.exists())
137+
138+
os.environ["PGSERVICEFILE"] = str(self.service_file_path)
139+
140+
def tearDown(self):
141+
new_folder_path = self.service_file_path.parent / "new_folder"
142+
if new_folder_path.exists():
143+
shutil.rmtree(new_folder_path)
144+
126145

127146
if __name__ == "__main__":
128147
unittest.main()

0 commit comments

Comments
 (0)