Skip to content

fix: import error for parsers #327

Closed
@ycexiao

Description

@ycexiao

Problem

Running pytest for diffpy.pdfmorph in the main branch.

FAILED tests/test_pdfmorphapp.py::TestApp::test_parser_systemexits - AttributeError: module 'diffpy.utils.parsers' has no attribute 'loaddata'
FAILED tests/test_pdfmorphapp.py::TestApp::test_morphsequence - AttributeError: module 'diffpy.utils.parsers' has no attribute 'loaddata'
FAILED tests/test_pdfmorphio.py::TestApp::test_morph_outputs - AttributeError: module 'diffpy.utils.parsers' has no attribute 'loaddata'
FAILED tests/test_tools.py::TestTools::test_field_sort - AttributeError: module 'diffpy.utils.parsers' has no attribute 'loaddata'

It comes from diffpy.pdfmorph tools.py

import diffpy.utils.parsers as parsers 
# ...
rv = parsers.loaddata.loadData(fname, unpack=True) 

The problem is related to diffpy.utils's sub-package parsers. Old parser is reconstructed as a sub-package and loaddata is a module now.

Proposed solution

A similar structure found in other projects under diffpy.
e.g. for diffpy.pdfmorph 's sub-package morph. The problem is avoided by importing the package's modules in its __init__.py.

from diffpy.pdfmorph.morphs.morph import Morph  # noqa: F401
from diffpy.pdfmorph.morphs.morphchain import MorphChain  # noqa: F401
# ...

Mirroring this method may solve the problem

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions