Skip to content

loading the datetime of the analysis into args #64

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/diffpy/labpdfproc/labpdfprocapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from diffpy.labpdfproc.functions import apply_corr, compute_cve
from diffpy.labpdfproc.tools import (
known_sources,
load_datetime,
load_user_metadata,
set_input_lists,
set_output_directory,
Expand Down Expand Up @@ -100,6 +101,7 @@ def main():
args.output_directory = set_output_directory(args)
args.wavelength = set_wavelength(args)
args = load_user_metadata(args)
args = load_datetime(args)

for filepath in args.input_paths:
outfilestem = filepath.stem + "_corrected"
Expand Down
18 changes: 18 additions & 0 deletions src/diffpy/labpdfproc/tests/test_tools.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import os
import re
from datetime import datetime
from pathlib import Path
from unittest.mock import patch

import pytest

from diffpy.labpdfproc.labpdfprocapp import get_args
from diffpy.labpdfproc.tools import (
known_sources,
load_datetime,
load_user_metadata,
set_input_lists,
set_output_directory,
Expand Down Expand Up @@ -241,3 +244,18 @@ def test_load_user_metadata_bad(inputs, msg):
actual_args = get_args(cli_inputs)
with pytest.raises(ValueError, match=msg[0]):
actual_args = load_user_metadata(actual_args)


params_time = [
(datetime(2024, 5, 20, 10, 30, 0)),
]


@pytest.mark.parametrize("expected", params_time)
def test_load_datetime(expected):
with patch("diffpy.labpdfproc.tools.datetime") as mock_datetime:
mock_datetime.now.return_value = expected
cli_inputs = ["2.5", "data.xy"]
actual_args = get_args(cli_inputs)
actual_args = load_datetime(actual_args)
assert actual_args.creation_time == expected
20 changes: 20 additions & 0 deletions src/diffpy/labpdfproc/tools.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from datetime import datetime
from pathlib import Path

WAVELENGTHS = {"Mo": 0.71, "Ag": 0.59, "Cu": 1.54}
Expand Down Expand Up @@ -171,3 +172,22 @@ def load_user_metadata(args):
setattr(args, key, value)
delattr(args, "user_metadata")
return args


def load_datetime(args):
"""
Create time-stamp and load it into args

Parameters
----------
args argparse.Namespace
the arguments from the parser

Returns
-------
the updated argparse Namespace with time-stamp inserted as creation_time

"""
creation_time = datetime.now()
setattr(args, "creation_time", creation_time)
return args
Loading