Skip to content

Commit

Permalink
Drop pkg_resources; test on Python 3.12
Browse files Browse the repository at this point in the history
  • Loading branch information
ajjackson committed Oct 8, 2024
1 parent 837b0d9 commit 80c29b2
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 21 deletions.
14 changes: 6 additions & 8 deletions galore/cross_sections.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os.path
from collections.abc import Iterable
from pkg_resources import resource_filename
from importlib.resources import files
from json import load as json_load


Expand Down Expand Up @@ -174,12 +174,10 @@ def get_cross_sections_yeh(source):
"""

weighting_files = {'alka': resource_filename(
__name__, "data/cross_sections.json"),
'he2': resource_filename(
__name__, "data/cross_sections_ups.json"),
'yeh_haxpes': resource_filename(
__name__, "data/cross_sections_haxpes.json")}
weighting_files = {'alka': files("galore") / "data/cross_sections.json",
'he2': files("galore") / "data/cross_sections_ups.json",
'yeh_haxpes':
files("galore") / "data/cross_sections_haxpes.json"}

if source.lower() in weighting_files:
path = weighting_files[source.lower()]
Expand Down Expand Up @@ -243,7 +241,7 @@ def _high_value(energy):
elif energy > max_energy:
_high_value(energy)

db_file = resource_filename(__name__, "data/scofield_data.db")
db_file = files("galore") / "data/scofield_data.db"

if elements is None:
elements = ['H', 'He', 'Li', 'Be', 'B', 'C', 'N', 'O', 'F', 'Ne', 'Na',
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,15 @@ legacy_tox_ini = """
3.9
3.10
3.10-gpaw
3.12
[testenv]
deps = coverage
extras = vasp
allowlist_externals = coverage
commands = coverage run --source=galore -m unittest discover test
[testenv:3.10-gpaw]
[testenv:py310-gpaw]
platform = linux
allowlist_externals =
{[testenv]allowlist_externals}
Expand Down
4 changes: 2 additions & 2 deletions test/test_cross_sections.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from pathlib import Path
import unittest
try:
from unittest import mock
except ImportError:
import mock
from pkg_resources import resource_filename

from galore.cross_sections import get_cross_sections
from galore.cross_sections import get_cross_sections_json
Expand Down Expand Up @@ -62,7 +62,7 @@ def test_json_error(self):

def test_json_read(self):
"""Check JSON file is opened without trouble"""
json_file = resource_filename(__name__, 'json_test.json')
json_file = Path(__file__).parent / 'json_test.json'
json_data = get_cross_sections_json(json_file)
self.assertEqual(json_data['He']['s'], 'CORRECT')

Expand Down
12 changes: 6 additions & 6 deletions test/test_gpaw.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import unittest
import sys
from contextlib import contextmanager
import io
from os.path import join as path_join
from pkg_resources import resource_filename
from pathlib import Path
import sys
import unittest

from galore.formats import read_gpaw_totaldos, read_gpaw_pdos
from contextlib import contextmanager

try:
from gpaw import GPAW
Expand All @@ -29,7 +29,7 @@ def stdout_redirect():

@unittest.skipIf(not has_gpaw, "GPAW not available")
class TestGPAW(unittest.TestCase):
gpaw_file = resource_filename(__name__, path_join('CdTe', 'CdTe.gpw'))
gpaw_file = Path(__file__).parent / 'CdTe/CdTe.gpw'

ref_vbm = 4.948260
efermi = 5.0761385
Expand Down
11 changes: 7 additions & 4 deletions test/test_process_pdos.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from pkg_resources import resource_filename
import numpy as np
import galore
from pathlib import Path
import unittest

import numpy as np
from numpy.testing import assert_array_almost_equal

import galore


class test_process_pdos(unittest.TestCase):
def test_lorentzian(self):
Expand All @@ -26,7 +28,8 @@ def test_broaden(self):
]))

def test_process_pdos(self):
vasprun = resource_filename(__name__, 'SnO2/vasprun.xml.gz')
vasprun = str(
(Path(__file__).parent / 'SnO2/vasprun.xml.gz').resolve())
xmin, xmax = (-10, 4)
weighting = 'Alka'

Expand Down

0 comments on commit 80c29b2

Please sign in to comment.