From 22f4f123a3102e7f03d7f9a68b8d2d9b8bdc912a Mon Sep 17 00:00:00 2001 From: Tieqiong Zhang Date: Thu, 9 Jan 2025 21:20:53 -0500 Subject: [PATCH 1/5] feat: add option to skip copyright header --- src/diffpy/pdffit2/pdffit.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/diffpy/pdffit2/pdffit.py b/src/diffpy/pdffit2/pdffit.py index 392ef07..1ecd6ae 100644 --- a/src/diffpy/pdffit2/pdffit.py +++ b/src/diffpy/pdffit2/pdffit.py @@ -1252,13 +1252,14 @@ def rcut(): # End refinable variables. - def __init__(self): + def __init__(self, intro=True): self.stru_files = [] self.data_files = [] self._handle = pdffit2.create() - self.intro() + if intro: + self.intro() return def __getRef(self, var_string): From ee05250d754e0a456ee871e928c10826bb4e144a Mon Sep 17 00:00:00 2001 From: Tieqiong Zhang Date: Fri, 10 Jan 2025 22:40:43 -0500 Subject: [PATCH 2/5] add PdfFit class __init__ docstring and tests --- src/diffpy/pdffit2/pdffit.py | 17 +++++- tests/test_pdffit.py | 111 +++++++++++++++++++---------------- 2 files changed, 78 insertions(+), 50 deletions(-) diff --git a/src/diffpy/pdffit2/pdffit.py b/src/diffpy/pdffit2/pdffit.py index 1ecd6ae..383fbac 100644 --- a/src/diffpy/pdffit2/pdffit.py +++ b/src/diffpy/pdffit2/pdffit.py @@ -104,7 +104,6 @@ def _convertCallable(var): class PdfFit(object): - """Create PdfFit object.""" # constants and enumerators from pdffit.h: # selection of all atoms @@ -1253,6 +1252,22 @@ def rcut(): # End refinable variables. def __init__(self, intro=True): + """Initialize the Pdffit class, create a new PdfFit object. + + Parameters + ---------- + intro : bool, optional + If True, display an introduction message. Default is True. + + Attributes + ---------- + stru_files : list + A list to store structure files. + data_files : list + A list to store data files. + _handle : PyCapsule + A python capsules to retrieve the printer to PdfFit object. + """ self.stru_files = [] self.data_files = [] diff --git a/tests/test_pdffit.py b/tests/test_pdffit.py index 508f29f..a5085cc 100644 --- a/tests/test_pdffit.py +++ b/tests/test_pdffit.py @@ -702,56 +702,69 @@ def test_occ(self): self.assertEqual(1, pf.getvar(pf.occ(i))) return + # def test_pscale(self): + # """check PdfFit.pscale() + # """ + # return + # + # def test_pscale(self): + # """check PdfFit.pscale() + # """ + # return + # + # def test_sratio(self): + # """check PdfFit.sratio() + # """ + # return + # + # def test_delta1(self): + # """check PdfFit.delta1() + # """ + # return + # + # def test_delta2(self): + # """check PdfFit.delta2() + # """ + # return + # + # def test_dscale(self): + # """check PdfFit.dscale() + # """ + # return + # + # def test_qdamp(self): + # """check PdfFit.qdamp() + # """ + # return + # + # def test_qbroad(self): + # """check PdfFit.qbroad() + # """ + # return + # + # def test_rcut(self): + # """check PdfFit.rcut() + # """ + # return + # + + def test___init__(self): + """Check PdfFit.__init__()""" + P = PdfFit() + self.assertEqual([], P.stru_files) + self.assertEqual([], P.data_files) + + output_true = self.capture_output(PdfFit, intro=True).strip() + output_false = self.capture_output(PdfFit, intro=False).strip() + + import diffpy.pdffit2.pdffit as pdffit + + self.assertEqual(len(output_true), len(pdffit.__intro_message__.strip())) + self.assertEqual(len(output_false), 0) + + return + -# def test_pscale(self): -# """check PdfFit.pscale() -# """ -# return -# -# def test_pscale(self): -# """check PdfFit.pscale() -# """ -# return -# -# def test_sratio(self): -# """check PdfFit.sratio() -# """ -# return -# -# def test_delta1(self): -# """check PdfFit.delta1() -# """ -# return -# -# def test_delta2(self): -# """check PdfFit.delta2() -# """ -# return -# -# def test_dscale(self): -# """check PdfFit.dscale() -# """ -# return -# -# def test_qdamp(self): -# """check PdfFit.qdamp() -# """ -# return -# -# def test_qbroad(self): -# """check PdfFit.qbroad() -# """ -# return -# -# def test_rcut(self): -# """check PdfFit.rcut() -# """ -# return -# -# def test___init__(self): -# """check PdfFit.__init__() -# """ -# return # # def test__PdfFit__getRef(self): # """check PdfFit._PdfFit__getRef() From 6b413a19b298e70e625f3e9bccc0c139391710b6 Mon Sep 17 00:00:00 2001 From: Tieqiong Zhang Date: Fri, 10 Jan 2025 22:45:58 -0500 Subject: [PATCH 3/5] add news --- news/intro.rst | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 news/intro.rst diff --git a/news/intro.rst b/news/intro.rst new file mode 100644 index 0000000..0d3f259 --- /dev/null +++ b/news/intro.rst @@ -0,0 +1,23 @@ +**Added:** + +* Add skip intro option when initializing the `PdfFit` class, with related docstrings and tests. + +**Changed:** + +* + +**Deprecated:** + +* + +**Removed:** + +* + +**Fixed:** + +* + +**Security:** + +* From 93c88be938441a24eb2a0985db5d8f4553867a4d Mon Sep 17 00:00:00 2001 From: Simon Billinge Date: Sat, 11 Jan 2025 05:36:36 -0500 Subject: [PATCH 4/5] Simon's tweak to news. --- news/intro.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/news/intro.rst b/news/intro.rst index 0d3f259..d0a911b 100644 --- a/news/intro.rst +++ b/news/intro.rst @@ -1,6 +1,6 @@ **Added:** -* Add skip intro option when initializing the `PdfFit` class, with related docstrings and tests. +* Option to skip printing of introductory information when initializing the `PdfFit` class. **Changed:** From b3b654f5bc7e81e65677a0aced373b8dfbfa6a15 Mon Sep 17 00:00:00 2001 From: Tieqiong Zhang Date: Sun, 12 Jan 2025 15:58:21 -0500 Subject: [PATCH 5/5] doc: docstring to numpy style --- src/diffpy/pdffit2/pdffit.py | 27 ++++++++++++++------------- tests/test_pdffit.py | 12 +++--------- 2 files changed, 17 insertions(+), 22 deletions(-) diff --git a/src/diffpy/pdffit2/pdffit.py b/src/diffpy/pdffit2/pdffit.py index 383fbac..43e9763 100644 --- a/src/diffpy/pdffit2/pdffit.py +++ b/src/diffpy/pdffit2/pdffit.py @@ -104,6 +104,15 @@ def _convertCallable(var): class PdfFit(object): + """Class for PdfFit. + + Attributes + ---------- + stru_files : list + The list to store structure files. + data_files : list + The list to store data files. + """ # constants and enumerators from pdffit.h: # selection of all atoms @@ -1251,29 +1260,21 @@ def rcut(): # End refinable variables. - def __init__(self, intro=True): + def __init__(self, create_intro=True): """Initialize the Pdffit class, create a new PdfFit object. Parameters ---------- - intro : bool, optional - If True, display an introduction message. Default is True. - - Attributes - ---------- - stru_files : list - A list to store structure files. - data_files : list - A list to store data files. - _handle : PyCapsule - A python capsules to retrieve the printer to PdfFit object. + create_intro : bool, optional + The flag to control the display of an introduction message. + If True, display an introduction message, else not. Default is True. """ self.stru_files = [] self.data_files = [] self._handle = pdffit2.create() - if intro: + if create_intro: self.intro() return diff --git a/tests/test_pdffit.py b/tests/test_pdffit.py index a5085cc..ee1e715 100644 --- a/tests/test_pdffit.py +++ b/tests/test_pdffit.py @@ -750,16 +750,10 @@ def test_occ(self): def test___init__(self): """Check PdfFit.__init__()""" - P = PdfFit() - self.assertEqual([], P.stru_files) - self.assertEqual([], P.data_files) + output_true = self.capture_output(PdfFit, create_intro=True).strip() + output_false = self.capture_output(PdfFit, create_intro=False).strip() - output_true = self.capture_output(PdfFit, intro=True).strip() - output_false = self.capture_output(PdfFit, intro=False).strip() - - import diffpy.pdffit2.pdffit as pdffit - - self.assertEqual(len(output_true), len(pdffit.__intro_message__.strip())) + self.assertGreater(len(output_true), 0) self.assertEqual(len(output_false), 0) return