Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ruff PR 2 #6961

Merged
merged 2 commits into from
Apr 25, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Ruff: Fix F
  • Loading branch information
Cadair authored and dstansby committed Apr 25, 2023
commit aef4ba369dad5bacb29ba68b8f94b0fe625f8697
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ exclude=[

select = [
"E",
#"F",
"F",
#"W",
#"UP",
#"PT",
Expand All @@ -126,6 +126,7 @@ extend-ignore = [
"docs/*.py" = [
"INP001", # implicit-namespace-package. The examples are not a package.
]
"sunpy/net/__init__.py" = ["F811"]
# These files are allowed to use warnings.warn
"sunpy/util/exceptions.py" = ["TID251"]
"sunpy/util/tests/test_logger.py" = ["TID251"]
Expand Down
1 change: 0 additions & 1 deletion sunpy/coordinates/wcs_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

from sunpy import log
from .frames import (
BaseCoordinateFrame,
Heliocentric,
HeliographicCarrington,
HeliographicStonyhurst,
Expand Down
2 changes: 1 addition & 1 deletion sunpy/data/sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@


# file_dict and file_list are not normal variables; see __getattr__() below
__all__ = list(sorted(_SAMPLE_DATA.keys())) + ['download_all', 'file_dict', 'file_list']
__all__ = list(sorted(_SAMPLE_DATA.keys())) + ['download_all', 'file_dict', 'file_list'] # noqa: F822


# See PEP 562 (https://peps.python.org/pep-0562/) for module-level __dir__()
Expand Down
8 changes: 4 additions & 4 deletions sunpy/database/tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def test_add_entry_repr(session):
expected_repr_result = (
'<AddEntry('
'session <sqlalchemy.orm.session.Session object at *>, '
'entry id 5)>'.format(id(session)))
'entry id 5)>')
assert fnmatch.fnmatch(repr_result, expected_repr_result)


Expand Down Expand Up @@ -129,7 +129,7 @@ def test_remove_entry_repr(session):
expected_repr_result = (
'<RemoveEntry('
'session <sqlalchemy.orm.session.Session object at *>, '
'entry DatabaseEntry(id=3))>'.format(id(session)))
'entry DatabaseEntry(id=3))>')
assert fnmatch.fnmatch(repr(RemoveEntry(session, entry)), expected_repr_result)


Expand Down Expand Up @@ -166,7 +166,7 @@ def test_add_tag_repr(session):
"<AddTag("
"tag 'spam', "
"session <sqlalchemy.orm.session.Session object at *>, "
"entry id 12)>".format(id(session)))
"entry id 12)>")
assert fnmatch.fnmatch(repr(AddTag(session, entry, tag)), expected_repr_result)


Expand Down Expand Up @@ -208,7 +208,7 @@ def test_remove_tag_repr(session):
"<RemoveTag("
"tag 'foo', "
"session <sqlalchemy.orm.session.Session object at *>, "
"entry id 8)>".format(id(session)))
"entry id 8)>")
assert fnmatch.fnmatch(repr(RemoveTag(session, entry, tag)), expected_repr_result)


Expand Down
6 changes: 3 additions & 3 deletions sunpy/database/tests/test_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ def test_vso_query_block_caching_with_overwrite_true_flag(database,

# Only downloading for the first query response block with caching disabled

num_of_fits_headers_1 = num_entries_from_vso_query(database, download_qr[:1],
num_entries_from_vso_query(database, download_qr[:1],
path=str(tmpdir.join('{file}.type1')),
file_pattern=str(tmpdir.join('*.type1')),
overwrite=True)
Expand Down Expand Up @@ -884,7 +884,7 @@ def test_query(filled_database):
DatabaseEntry(id=10, tags=[bar])]


def test_fetch_missing_arg(database):
def test_fetch_missing_arg_error(database):
with pytest.raises(TypeError):
database.fetch()

Expand Down Expand Up @@ -948,7 +948,7 @@ def test_fetch_missing_arg(database):

@pytest.mark.remote_data
@pytest.mark.skip
def test_fetch(database, download_query, tmpdir):
def test_fetch2(database, download_query, tmpdir):
assert len(database) == 0
database.default_waveunit = 'angstrom'
database.fetch(*download_query, path=str(tmpdir.join('{file}.fits')))
Expand Down
21 changes: 21 additions & 0 deletions sunpy/io/special/genx.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,27 @@

# This class has been copied from the Python 3.11 stdlib xdrlib.py file under
# the terms of the PSF licence 2.0
class Error(Exception):
"""Exception class for this module. Use:
except xdrlib.Error as var:
# var has the Error instance for the exception
Public ivars:
msg -- contains the message
"""
def __init__(self, msg):
self.msg = msg

def __repr__(self):
return repr(self.msg)

def __str__(self):
return str(self.msg)


class ConversionError(Error):
pass


class Unpacker:
"""Unpacks various data representations from the given buffer."""

Expand Down
38 changes: 0 additions & 38 deletions sunpy/io/tests/test_filetools.py
Copy link
Member Author

@dstansby dstansby Apr 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test deleted here are duplicates

Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,6 @@ def test_write_file_ana():
os.remove("ana_test_write.fz")


@skip_glymur
def test_read_file_header_jp2():
hlist = sunpy.io.read_file_header(os.path.join(sunpy.data.test.rootdir,
"2013_06_24__17_31_30_84__SDO_AIA_AIA_193.jp2"))
assert isinstance(hlist, list)
assert len(hlist) == 1
assert isinstance(hlist[0], sunpy.io.header.FileHeader)


@pytest.mark.parametrize('fname', ['aia_171_image.fits',
pathlib.Path('aia_171_image.fits')])
def test_write_file_fits(fname):
Expand All @@ -147,32 +138,3 @@ def test_write_file_fits_bytes():
assert np.all(np.equal(outpair[0], aiapair[0]))
assert outpair[1] == aiapair[1]
os.remove("aia_171_image_bytes.fits")


@skip_ana
def test_read_file_ana():
ana_data = sunpy.io.read_file(os.path.join(sunpy.data.test.rootdir, "test_ana.fz"))
assert isinstance(ana_data, list)
assert len(ana_data) == 1
assert len(ana_data[0]) == 2
assert isinstance(ana_data[0][0], np.ndarray)
assert isinstance(ana_data[0][1], sunpy.io.header.FileHeader)


@skip_ana
def test_read_file__header_ana():
ana_data = sunpy.io.read_file_header(os.path.join(sunpy.data.test.rootdir, "test_ana.fz"))
assert isinstance(ana_data, list)
assert len(ana_data) == 1
assert isinstance(ana_data[0], sunpy.io.header.FileHeader)


@skip_ana
def test_write_file_ana():
ana = sunpy.io.read_file(os.path.join(sunpy.data.test.rootdir, "test_ana.fz"))[0]
sunpy.io.write_file("ana_test_write.fz", ana[0], str(ana[1]))
assert os.path.exists("ana_test_write.fz")
outpair = sunpy.io.read_file(os.path.join(sunpy.data.test.rootdir, "test_ana.fz"))
assert np.all(np.equal(outpair[0][1], ana[1]))
assert outpair[0][1] == ana[1]
os.remove("ana_test_write.fz")
10 changes: 5 additions & 5 deletions sunpy/map/tests/test_header_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,17 +233,17 @@ def test_invalid_inputs(map_data, hcc_coord, hpc_coord_notime, hpc_coord):

# Check arguments not given as astropy Quantities
with pytest.raises(TypeError):
header = make_fitswcs_header(map_data, hpc_coord, reference_pixel=[0, 0])
make_fitswcs_header(map_data, hpc_coord, reference_pixel=[0, 0])
with pytest.raises(TypeError):
header = make_fitswcs_header(map_data, hpc_coord, scale=[0, 0])
make_fitswcs_header(map_data, hpc_coord, scale=[0, 0])

# Check arguments of reference_pixel and scale have to be given in astropy units of pix, and arcsec/pix
with pytest.raises(u.UnitsError):
header = make_fitswcs_header(map_data, hpc_coord, reference_pixel=u.Quantity([0, 0]))
make_fitswcs_header(map_data, hpc_coord, reference_pixel=u.Quantity([0, 0]))
with pytest.raises(u.UnitsError):
header = make_fitswcs_header(map_data, hpc_coord, scale=u.Quantity([0, 0]))
make_fitswcs_header(map_data, hpc_coord, scale=u.Quantity([0, 0]))
with pytest.raises(u.UnitsError):
header = make_fitswcs_header(map_data, hpc_coord, scale=u.Quantity([0, 0]*u.arcsec))
make_fitswcs_header(map_data, hpc_coord, scale=u.Quantity([0, 0]*u.arcsec))


@pytest.mark.parametrize('frame', ['carrington', 'stonyhurst'])
Expand Down
2 changes: 1 addition & 1 deletion sunpy/map/tests/test_map_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def test_errors(tmpdir):
p = tmpdir.mkdir("sub").join("hello.fits")
p.write("content")
files = [AIA_171_IMAGE, p.strpath]
with pytest.raises(OSError, match=(fr"Failed to read *")):
with pytest.raises(OSError, match=(r"Failed to read *")):
sunpy.map.Map(files)


Expand Down
6 changes: 3 additions & 3 deletions sunpy/map/tests/test_mapsequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,15 +142,15 @@ def test_repr(mapsequence_all_the_same, mapsequence_different_maps):
for mapsequence of same maps as well that of different maps.
"""
# Test the case of MapSequence having same maps
expected_out = f'MapSequence of 2 elements, with maps from AIAMap'
expected_out = 'MapSequence of 2 elements, with maps from AIAMap'
obtained_out = repr(mapsequence_all_the_same)
assert obtained_out.startswith(object.__repr__(mapsequence_all_the_same))
assert len(mapsequence_all_the_same) == 2
assert expected_out in obtained_out

# Test the case of MapSequence having different maps
expected_out1 = f'MapSequence of 2 elements, with maps from AIAMap, EITMap'
expected_out2 = f'MapSequence of 2 elements, with maps from EITMap, AIAMap'
expected_out1 = 'MapSequence of 2 elements, with maps from AIAMap, EITMap'
expected_out2 = 'MapSequence of 2 elements, with maps from EITMap, AIAMap'
obtained_out = repr(mapsequence_different_maps)
assert obtained_out.startswith(object.__repr__(mapsequence_different_maps))
assert len(mapsequence_different_maps) == 2
Expand Down
2 changes: 1 addition & 1 deletion sunpy/net/hek2vso/tests/test_hek2vso.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def test_full_query(h2v_client, hek_client):
@pytest.mark.remote_data
def test_quick_clean(h2v_client, hek_client):
h2v = h2v_client
h2v_q = h2v.full_query(
h2v.full_query(
(a.Time(startTime, endTime), a.hek.EventType(eventType), a.hek.FL.PeakFlux > 1000)
)

Expand Down
2 changes: 1 addition & 1 deletion sunpy/net/helio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
from .hec import *
from .parser import *

__all__ = ['HECClient', 'HECResponse', 'Chaincode']
__all__ = ['HECClient', 'HECResponse', 'Chaincode'] # noqa: F405
5 changes: 5 additions & 0 deletions sunpy/net/jsoc/jsoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,8 +483,13 @@ def get_request(self, requests, path=None, overwrite=False, progress=True,
# Private communication from JSOC say we should not use more than one connection.
max_splits = kwargs.get('max_splits', 1)
if max_splits != 1:
<<<<<<< HEAD
log.info(f"Setting max_splits to it's maximum allowed value of 1 for requests made by the JSOCClient.")
max_splits = 1
=======
log.info("Setting max_splits to it's maximum allowed value of 1 for requests made by the JSOCClient.")
kwargs['max_splits'] = 1
>>>>>>> d7f3edba9 (Ruff: Fix F)

# Convert Responses to a list if not already
if isinstance(requests, str) or not isiterable(requests):
Expand Down
2 changes: 1 addition & 1 deletion sunpy/net/scraper.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ def _ftpfileslist(self, timerange):
if self._check_timerange(fullpath, timerange):
filesurls.append(fullpath)

filesurls = [f'ftp://' + "{0.netloc}{0.path}".format(urlsplit(url))
filesurls = ['ftp://' + "{0.netloc}{0.path}".format(urlsplit(url))
for url in filesurls]

return filesurls
Expand Down
2 changes: 1 addition & 1 deletion sunpy/net/tests/test_attr.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class TestAttr(attr.Attr):
@pytest.mark.parametrize("different_type", [
int, str, float, list, set, tuple, dict, object
])
def test_empty(different_type):
def test_empty_type(different_type):
attr_ = attr.Attr()
assert attr_ != different_type()

Expand Down
2 changes: 1 addition & 1 deletion sunpy/physics/tests/test_differential_rotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def test_rigid(seconds_per_day):

def test_fail(seconds_per_day):
with pytest.raises(ValueError):
rot = diff_rot(10 * seconds_per_day, 30 * u.deg, rot_type='garbage')
diff_rot(10 * seconds_per_day, 30 * u.deg, rot_type='garbage')


def test_solar_rotate_coordinate():
Expand Down
2 changes: 1 addition & 1 deletion sunpy/visualization/colormaps/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
"""
from sunpy.visualization.colormaps.cm import *

for cmname in cmlist.keys():
for cmname in cmlist.keys(): # noqa: F405
__doc__ += f"\n* '{cmname}'\n"
18 changes: 9 additions & 9 deletions sunpy/visualization/visualization.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ def axis_labels_from_ctype(ctype, unit):
"""
ctype_short = ctype[:4]

labels = {'HGLN': f'Heliographic Longitude',
'CRLN': f'Carrington Longitude',
'HPLN': f'Helioprojective Longitude (Solar-X)',
'SOLX': f'Heliocentric X',

'HGLT': f'Latitude',
'CRLT': f'Latitude',
'HPLT': f'Helioprojective Latitude (Solar-Y)',
'SOLY': f'Heliocentric Y'}
labels = {'HGLN': 'Heliographic Longitude',
'CRLN': 'Carrington Longitude',
'HPLN': 'Helioprojective Longitude (Solar-X)',
'SOLX': 'Heliocentric X',

'HGLT': 'Latitude',
'CRLT': 'Latitude',
'HPLT': 'Helioprojective Latitude (Solar-Y)',
'SOLY': 'Heliocentric Y'}

label = labels.get(ctype_short, f"{ctype}")
if unit is not None:
Expand Down