Skip to content

Commit

Permalink
Merge pull request #139 from tecnavia-dev/master
Browse files Browse the repository at this point in the history
Create monitored directory if does not exist
  • Loading branch information
mraspaud authored Jul 6, 2023
2 parents 3b60b7e + 6bb2de7 commit 4e30862
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
31 changes: 17 additions & 14 deletions pytroll_collectors/tests/test_trollstalker.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,20 @@ def test_trollstalker(tmp_path, caplog):
assert message.data['uri'] == os.fspath(trigger_file)


# def test_trollstalker_directory_does_not_exist(tmp_path, caplog):
# dir_to_watch = tmp_path / "to_watch"
#
# config_file = create_config_file(dir_to_watch, tmp_path)
#
# thread = Thread(target=main, args=[["-c", os.fspath(config_file), "-C", "noaa_hrpt"]])
# thread.start()
# time.sleep(.5)
# with open(dir_to_watch / "hrpt_noaa18_20230524_1017_10101.l1b", "w") as fd:
# fd.write("hej")
# time.sleep(.5)
# stop()
# thread.join()
# assert "Publishing message pytroll://HRPT/l1b/dev/mystation file " in caplog.text
def test_trollstalker_directory_does_not_exist(tmp_path):
"""Test that monitored directories are created."""
dir_to_watch = tmp_path / "to_watch"

config_file = create_config_file(dir_to_watch, tmp_path)

thread = Thread(target=main, args=[["-c", os.fspath(config_file), "-C", "noaa_hrpt"]])
thread.start()
time.sleep(.5)
trigger_file = dir_to_watch / "hrpt_noaa18_20230524_1017_10101.l1b"
with open(trigger_file, "w") as fd:
fd.write("hej")
time.sleep(.5)
stop()
thread.join()

assert os.path.exists(dir_to_watch)
1 change: 1 addition & 0 deletions pytroll_collectors/trollstalker.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ def create_notifier(topic, instrument, posttroll_port, filepattern,

# Add directories and event masks to watch manager
for monitored_dir in monitored_dirs:
os.makedirs(monitored_dir, exist_ok=True)
manager.add_watch(monitored_dir, event_mask, rec=True)

return notifier
Expand Down

0 comments on commit 4e30862

Please sign in to comment.