Skip to content

Commit 6116cf3

Browse files
author
Andrew Yang
committed
Refactoring and improve coverage
1 parent 7f3618e commit 6116cf3

File tree

9 files changed

+291
-314
lines changed

9 files changed

+291
-314
lines changed

Diff for: src/diffpy/utils/parsers/__init__.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@
1717
"""
1818

1919
from .loaddata import loadData
20-
from .loadmetafile import serialize_data, deserialize_data, apply_schema_to_file, serial_oneline
20+
from .serialization import serialize_data, deserialize_data
2121
from .resample import resample
2222

2323
# silence the pyflakes syntax checker
2424
assert loadData or resample or True
25+
assert serialize_data or deserialize_data or True
2526

2627
# End of file

Diff for: src/diffpy/utils/parsers/custom_exceptions.py

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/usr/bin/env python
2+
##############################################################################
3+
#
4+
# diffpy.utils by DANSE Diffraction group
5+
# Simon J. L. Billinge
6+
# (c) 2010 The Trustees of Columbia University
7+
# in the City of New York. All rights reserved.
8+
#
9+
# File coded by:
10+
#
11+
# See AUTHORS.txt for a list of people who contributed.
12+
# See LICENSE_DANSE.txt for license information.
13+
#
14+
##############################################################################
15+
16+
class UnsupportedTypeError(Exception):
17+
"""For file types not supported by our parsers.
18+
19+
supported_types -- List of supported types.
20+
file -- file triggering the error.
21+
message -- for writing a custom message.
22+
"""
23+
24+
def __init__(self, file, supported_types=None, message=None):
25+
if message is None:
26+
self.message = f"The file {file} is not supported."
27+
if supported_types is not None:
28+
self.message += " Supported file types include: "
29+
for t in supported_types:
30+
self.message += t + ", "
31+
self.message = self.message[:-2] + "."
32+
super().__init__(self.message)
33+
34+
35+
class ImproperSizeError(Exception):
36+
"""When the size of an object does not match expectations.
37+
38+
bad_object -- Object with improper size.
39+
message -- for writing a custom message.
40+
"""
41+
42+
def __init__(self, bad_object, message=None):
43+
if message is None:
44+
self.message = f"The size of {bad_object} is different than expected."
45+
super().__init__(self.message)

Diff for: src/diffpy/utils/parsers/loadmetafile.py

-242
This file was deleted.

0 commit comments

Comments
 (0)