Skip to content

Commit e6773e6

Browse files
committed
Some small cleanups
1 parent 2ac17b8 commit e6773e6

File tree

3 files changed

+34
-4
lines changed

3 files changed

+34
-4
lines changed

bindings/python/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ You can install the package using pip like this:
5656
mkdir my_venv
5757
python -m venv my_venv
5858
59-
pip install SandiaSpecUtils
6059
source my_venv/bin/activate
60+
pip install SandiaSpecUtils
6161
6262
python
6363
>>> import SpecUtils

bindings/python/SpecFile_py.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -170,10 +170,8 @@ namespace
170170

171171
// Get more data from Python stream
172172
py::object pyread = python_stream_.attr("read");
173-
if (pyread.is_none()){
174-
cerr << "PythonInputStreambuf::underflow: pyread is none" << endl;
173+
if (pyread.is_none())
175174
return traits_type::eof();
176-
}
177175

178176
// Try to fill our buffer
179177
py::object py_data = pyread(buffer_size);

bindings/python/tests/test_specutils.py

+32
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,38 @@ def test_load_file(self):
1616
self.spec.loadFile(file_path, SpecUtils.ParserType.Auto)
1717
self.assertTrue(self.spec.numMeasurements() > 0)
1818

19+
def test_load_save_file(self):
20+
script_dir = Path(__file__).parent.resolve()
21+
file_path = os.path.join(script_dir, "..", "examples", "passthrough.n42")
22+
23+
orig = SpecUtils.SpecFile()
24+
orig.loadFile(file_path, SpecUtils.ParserType.Auto)
25+
self.assertTrue(orig.numMeasurements() > 0)
26+
27+
pcffile = open("passthrough_saved.pcf", "wb")
28+
orig.writeToStream(pcffile, orig.sampleNumbers(), orig.detectorNames(), SpecUtils.SaveSpectrumAsType.Pcf )
29+
pcffile.close()
30+
31+
pcfreread = SpecUtils.SpecFile()
32+
pcfreread.loadFile("passthrough_saved.pcf", SpecUtils.ParserType.Pcf)
33+
self.assertEqual(pcfreread.numMeasurements(), orig.numMeasurements())
34+
35+
pcfinfile = open("passthrough_saved.pcf", "rb")
36+
pcfreread2 = SpecUtils.SpecFile()
37+
pcfreread2.loadFromPcf(pcfinfile)
38+
self.assertEqual(pcfreread2.numMeasurements(), orig.numMeasurements())
39+
pcfinfile.close()
40+
41+
n42outfile = open("passthrough_saved.n42", "wb")
42+
orig.writeToStream(n42outfile, orig.sampleNumbers(), orig.detectorNames(), SpecUtils.SaveSpectrumAsType.N42_2012 )
43+
n42outfile.close()
44+
45+
n42infile = open("passthrough_saved.n42", "rb")
46+
n42reread = SpecUtils.SpecFile()
47+
n42reread.loadFromN42( n42infile )
48+
self.assertEqual(n42reread.numMeasurements(), orig.numMeasurements())
49+
n42infile.close()
50+
1951
def test_create_measurement(self):
2052
# Create and configure a new measurement
2153
meas = SpecUtils.Measurement()

0 commit comments

Comments
 (0)