Skip to content

Commit

Permalink
Fix pylint C0200 warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
martinholmer committed Jan 3, 2025
1 parent 3542cc6 commit 6cacfa9
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 67 deletions.
7 changes: 2 additions & 5 deletions taxcalc/tests/test_growfactors.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,8 @@ def fixture_bad_gf_file():
"""
txt = (u'YEAR,AWAGE,ACPIU,ABADNAME,ASOCSEC\n'
u'2015,1.000,1.000,1.000000,1.00000\n')
tfile = tempfile.NamedTemporaryFile( # pylint: disable=consider-using-with
mode='a', delete=False
)
tfile.write(txt)
tfile.close()
with tempfile.NamedTemporaryFile(mode='a', delete=False) as tfile:
tfile.write(txt)
yield tfile
os.remove(tfile.name)

Expand Down
2 changes: 1 addition & 1 deletion taxcalc/tests/test_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ def test_order_of_indexing_and_level_reforms():
ppo = [Policy(), Policy()]
# apply reforms to corresponding Policy object & check post-reform values
syr = Policy.JSON_START_YEAR
for ref in range(len(reform)): # pylint: disable=consider-using-enumerate
for ref, _ in enumerate(reform):
# confirm pre-reform MTE values in 2014-2017
mte = ppo[ref]._SS_Earnings_c
assert mte[2014 - syr] == 117000
Expand Down
110 changes: 49 additions & 61 deletions taxcalc/tests/test_taxcalcio.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import tempfile
import pytest
import pandas as pd
from taxcalc import TaxCalcIO # pylint: disable=import-error
from taxcalc import TaxCalcIO


RAWINPUT = (
Expand All @@ -37,11 +37,10 @@ def fixture_reformfile0():
}
}
"""
rfile = tempfile.NamedTemporaryFile( # pylint: disable=consider-using-with
suffix='.json', mode='a', delete=False
)
rfile.write(txt + '\n')
rfile.close()
with tempfile.NamedTemporaryFile(
suffix='.json', mode='a', delete=False
) as rfile:
rfile.write(txt + '\n')
yield rfile
if os.path.isfile(rfile.name):
try:
Expand All @@ -55,18 +54,17 @@ def fixture_assumpfile0():
"""
Temporary assumption file with .json extension.
"""
afile = tempfile.NamedTemporaryFile( # pylint: disable=consider-using-with
suffix='.json', mode='a', delete=False
)
contents = """
{
"consumption": {},
"growdiff_baseline": {"ABOOK": {"2015": -0.01}},
"growdiff_response": {}
}
"""
afile.write(contents)
afile.close()
with tempfile.NamedTemporaryFile(
suffix='.json', mode='a', delete=False
) as afile:
afile.write(contents)
yield afile
if os.path.isfile(afile.name):
try:
Expand All @@ -80,9 +78,6 @@ def fixture_reformfile1():
"""
Temporary reform file with .json extension.
"""
rfile = tempfile.NamedTemporaryFile( # pylint: disable=consider-using-with
suffix='.json', mode='a', delete=False
)
contents = """
{"policy": {
"AMT_brk1": { // top of first AMT tax bracket
Expand Down Expand Up @@ -110,8 +105,10 @@ def fixture_reformfile1():
}
}
"""
rfile.write(contents)
rfile.close()
with tempfile.NamedTemporaryFile(
suffix='.json', mode='a', delete=False
) as rfile:
rfile.write(contents)
yield rfile
if os.path.isfile(rfile.name):
try:
Expand All @@ -125,12 +122,11 @@ def fixture_baselinebad():
"""
Temporary baseline file with .json extension.
"""
rfile = tempfile.NamedTemporaryFile( # pylint: disable=consider-using-with
suffix='.json', mode='a', delete=False
)
contents = '{ "policy": {"AMT_brk1": {"2011": 0.0}}}'
rfile.write(contents)
rfile.close()
with tempfile.NamedTemporaryFile(
suffix='.json', mode='a', delete=False
) as rfile:
rfile.write(contents)
yield rfile
if os.path.isfile(rfile.name):
try:
Expand All @@ -144,12 +140,11 @@ def fixture_errorreformfile():
"""
Temporary reform file with .json extension.
"""
rfile = tempfile.NamedTemporaryFile( # pylint: disable=consider-using-with
suffix='.json', mode='a', delete=False
)
contents = '{ "policy": {"xxx": {"2015": 0}}}'
rfile.write(contents)
rfile.close()
with tempfile.NamedTemporaryFile(
suffix='.json', mode='a', delete=False
) as rfile:
rfile.write(contents)
yield rfile
if os.path.isfile(rfile.name):
try:
Expand All @@ -163,18 +158,17 @@ def fixture_errorassumpfile():
"""
Temporary assumption file with .json extension.
"""
rfile = tempfile.NamedTemporaryFile( # pylint: disable=consider-using-with
suffix='.json', mode='a', delete=False
)
contents = """
{
"consumption": {"MPC_e18400": {"2018": -9}},
"growdiff_baseline": {"ABOOKxx": {"2017": 0.02}},
"growdiff_response": {"ABOOKxx": {"2017": 0.02}}
}
"""
rfile.write(contents)
rfile.close()
with tempfile.NamedTemporaryFile(
suffix='.json', mode='a', delete=False
) as rfile:
rfile.write(contents)
yield rfile
if os.path.isfile(rfile.name):
try:
Expand All @@ -188,18 +182,17 @@ def fixture_assumpfile1():
"""
Temporary assumption file with .json extension.
"""
afile = tempfile.NamedTemporaryFile( # pylint: disable=consider-using-with
suffix='.json', mode='a', delete=False
)
contents = """
{
"consumption": { "MPC_e18400": {"2018": 0.05} },
"growdiff_baseline": {},
"growdiff_response": {}
}
"""
afile.write(contents)
afile.close()
with tempfile.NamedTemporaryFile(
suffix='.json', mode='a', delete=False
) as afile:
afile.write(contents)
yield afile
if os.path.isfile(afile.name):
try:
Expand All @@ -213,12 +206,11 @@ def fixture_lumpsumreformfile():
"""
Temporary reform file without .json extension.
"""
rfile = tempfile.NamedTemporaryFile( # pylint: disable=consider-using-with
suffix='.json', mode='a', delete=False
)
lumpsum_reform_contents = '{"policy": {"LST": {"2013": 200}}}'
rfile.write(lumpsum_reform_contents)
rfile.close()
with tempfile.NamedTemporaryFile(
suffix='.json', mode='a', delete=False
) as rfile:
rfile.write(lumpsum_reform_contents)
yield rfile
if os.path.isfile(rfile.name):
try:
Expand All @@ -232,18 +224,17 @@ def fixture_assumpfile2():
"""
Temporary assumption file with .json extension.
"""
afile = tempfile.NamedTemporaryFil( # pylint: disable=consider-using-with
suffix='.json', mode='a', delete=False
)
assump2_contents = """
{
"consumption": {"BEN_snap_value": {"2018": 0.90}},
"growdiff_baseline": {},
"growdiff_response": {}
}
"""
afile.write(assump2_contents)
afile.close()
with tempfile.NamedTemporaryFil(
suffix='.json', mode='a', delete=False
) as afile:
afile.write(assump2_contents)
yield afile
if os.path.isfile(afile.name):
try:
Expand Down Expand Up @@ -668,12 +659,11 @@ def fixture_warnreformfile():
"""
Temporary reform file with .json extension.
"""
rfile = tempfile.NamedTemporaryFile( # pylint: disable=consider-using-with
suffix='.json', mode='a', delete=False
)
contents = '{"policy": {"STD_Dep": {"2015": 0}}}'
rfile.write(contents)
rfile.close()
with tempfile.NamedTemporaryFile(
suffix='.json', mode='a', delete=False
) as rfile:
rfile.write(contents)
yield rfile
if os.path.isfile(rfile.name):
try:
Expand Down Expand Up @@ -712,9 +702,6 @@ def fixture_reformfile9():
"""
Temporary reform file with .json extension.
"""
rfile = tempfile.NamedTemporaryFile( # pylint: disable=consider-using-with
suffix='.json', mode='a', delete=False
)
contents = """
{ "policy": {
"SS_Earnings_c": {
Expand All @@ -724,8 +711,10 @@ def fixture_reformfile9():
}
}
"""
rfile.write(contents)
rfile.close()
with tempfile.NamedTemporaryFile(
suffix='.json', mode='a', delete=False
) as rfile:
rfile.write(contents)
yield rfile
if os.path.isfile(rfile.name):
try:
Expand All @@ -742,12 +731,11 @@ def fixture_regression_reform_file():
Example causing regression reported in issue:
https://github.com/PSLmodels/Tax-Calculator/issues/2622
"""
rfile = tempfile.NamedTemporaryFile( # pylint: disable=consider-using-with
suffix='.json', mode='a', delete=False
)
contents = '{ "policy": {"AMEDT_rt": {"2021": 1.8}}}'
rfile.write(contents)
rfile.close()
with tempfile.NamedTemporaryFile(
suffix='.json', mode='a', delete=False
) as rfile:
rfile.write(contents)
yield rfile
if os.path.isfile(rfile.name):
try:
Expand Down

0 comments on commit 6cacfa9

Please sign in to comment.