Skip to content

Commit d71c51b

Browse files
initial commit on loading the datetime of the analysis into args
1 parent 5c3eed7 commit d71c51b

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

src/diffpy/labpdfproc/labpdfprocapp.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from diffpy.labpdfproc.functions import apply_corr, compute_cve
55
from diffpy.labpdfproc.tools import (
66
known_sources,
7+
load_datetime,
78
load_user_metadata,
89
set_input_lists,
910
set_output_directory,
@@ -100,6 +101,7 @@ def main():
100101
args.output_directory = set_output_directory(args)
101102
args.wavelength = set_wavelength(args)
102103
args = load_user_metadata(args)
104+
args = load_datetime(args)
103105

104106
for filepath in args.input_paths:
105107
outfilestem = filepath.stem + "_corrected"

src/diffpy/labpdfproc/tests/test_tools.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
import os
22
import re
3+
from datetime import datetime
34
from pathlib import Path
5+
from unittest.mock import patch
46

57
import pytest
68

79
from diffpy.labpdfproc.labpdfprocapp import get_args
810
from diffpy.labpdfproc.tools import (
911
known_sources,
12+
load_datetime,
1013
load_user_metadata,
1114
set_input_lists,
1215
set_output_directory,
@@ -241,3 +244,18 @@ def test_load_user_metadata_bad(inputs, msg):
241244
actual_args = get_args(cli_inputs)
242245
with pytest.raises(ValueError, match=msg[0]):
243246
actual_args = load_user_metadata(actual_args)
247+
248+
249+
params_time = [
250+
(datetime(2024, 5, 20, 10, 30, 0)),
251+
]
252+
253+
254+
@pytest.mark.parametrize("expected", params_time)
255+
def test_load_datetime(expected):
256+
with patch("diffpy.labpdfproc.tools.datetime") as mock_datetime:
257+
mock_datetime.now.return_value = expected
258+
cli_inputs = ["2.5", "data.xy"]
259+
actual_args = get_args(cli_inputs)
260+
actual_args = load_datetime(actual_args)
261+
assert actual_args.creation_time == expected

src/diffpy/labpdfproc/tools.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from datetime import datetime
12
from pathlib import Path
23

34
WAVELENGTHS = {"Mo": 0.71, "Ag": 0.59, "Cu": 1.54}
@@ -171,3 +172,22 @@ def load_user_metadata(args):
171172
setattr(args, key, value)
172173
delattr(args, "user_metadata")
173174
return args
175+
176+
177+
def load_datetime(args):
178+
"""
179+
Create time-stamp and load it into args
180+
181+
Parameters
182+
----------
183+
args argparse.Namespace
184+
the arguments from the parser
185+
186+
Returns
187+
-------
188+
the updated argparse Namespace with time-stamp inserted as creation_time
189+
190+
"""
191+
creation_time = datetime.now()
192+
setattr(args, "creation_time", creation_time)
193+
return args

0 commit comments

Comments
 (0)