Skip to content

Commit

Permalink
chore: manual fix ruff 0.7 lint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
IronCore864 committed Oct 18, 2024
1 parent 00d0bba commit 3f7d81e
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 9 deletions.
4 changes: 3 additions & 1 deletion ops/pebble.py
Original file line number Diff line number Diff line change
Expand Up @@ -3216,7 +3216,9 @@ def feed(self, data: bytes):
self._parser.feed(data)

def _prepare_tempfile(self, filename: str):
tf = tempfile.NamedTemporaryFile(delete=False)
# TODO: Remove noqa SIM115 when the following issue is fixed.
# https://github.com/astral-sh/ruff/issues/7313
tf = tempfile.NamedTemporaryFile(delete=False) # noqa: SIM115
self._files[filename] = tf # type: ignore # we have a custom protocol for it
self.current_filename = filename

Expand Down
8 changes: 6 additions & 2 deletions test/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1231,7 +1231,9 @@ def test_hook_and_dispatch_with_failing_hook(
request: pytest.FixtureRequest,
fake_script: FakeScript,
):
self.stdout = self.stderr = tempfile.TemporaryFile()
# TODO: Remove noqa SIM115 when the following issue is fixed.
# https://github.com/astral-sh/ruff/issues/7313
self.stdout = self.stderr = tempfile.TemporaryFile() # noqa: SIM115
request.addfinalizer(self.stdout.close)

fake_script_hooks = FakeScript(request, self.hooks_dir)
Expand Down Expand Up @@ -1383,7 +1385,9 @@ def _call_event(
@pytest.mark.usefixtures('setup_charm')
def test_crash_action(self, request: pytest.FixtureRequest, fake_script: FakeScript):
self._prepare_actions()
self.stderr = tempfile.TemporaryFile('w+t')
# TODO: Remove noqa SIM115 when the following issue is fixed.
# https://github.com/astral-sh/ruff/issues/7313
self.stderr = tempfile.TemporaryFile('w+t') # noqa: SIM115
request.addfinalizer(self.stderr.close)
fake_script.write('action-get', "echo '{}'")
with pytest.raises(subprocess.CalledProcessError):
Expand Down
4 changes: 3 additions & 1 deletion test/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -2808,7 +2808,9 @@ def test_relation_set_juju_version_quirks(
version: str,
):
# on 2.7.0+, things proceed as expected
t = tempfile.NamedTemporaryFile()
# TODO: Remove noqa SIM115 when the following issue is fixed.
# https://github.com/astral-sh/ruff/issues/7313
t = tempfile.NamedTemporaryFile() # noqa: SIM115
try:
fake_script.write(
'relation-set',
Expand Down
8 changes: 5 additions & 3 deletions test/test_pebble.py
Original file line number Diff line number Diff line change
Expand Up @@ -3691,9 +3691,11 @@ def test_wait_passed_output_bad_command(
assert io_ws.sends == []

def test_wait_file_io(self, client: MockClient):
fin = tempfile.TemporaryFile(mode='w+', encoding='utf-8')
out = tempfile.TemporaryFile(mode='w+', encoding='utf-8')
err = tempfile.TemporaryFile(mode='w+', encoding='utf-8')
# TODO: Remove noqa SIM115 when the following issue is fixed.
# https://github.com/astral-sh/ruff/issues/7313
fin = tempfile.TemporaryFile(mode='w+', encoding='utf-8') # noqa: SIM115
out = tempfile.TemporaryFile(mode='w+', encoding='utf-8') # noqa: SIM115
err = tempfile.TemporaryFile(mode='w+', encoding='utf-8') # noqa: SIM115
try:
fin.write('foo\n')
fin.seek(0)
Expand Down
8 changes: 6 additions & 2 deletions test/test_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,9 @@ def test_is_available(self, fake_script: FakeScript):
assert fake_script.calls(clear=True) == []

def test_set_encodes_args(self, fake_script: FakeScript):
t = tempfile.NamedTemporaryFile()
# TODO: Remove noqa SIM115 when the following issue is fixed.
# https://github.com/astral-sh/ruff/issues/7313
t = tempfile.NamedTemporaryFile() # noqa: SIM115
try:
fake_script.write(
'state-set',
Expand Down Expand Up @@ -478,7 +480,9 @@ def test_get(self, fake_script: FakeScript):
]

def test_set_and_get_complex_value(self, fake_script: FakeScript):
t = tempfile.NamedTemporaryFile()
# TODO: Remove noqa SIM115 when the following issue is fixed.
# https://github.com/astral-sh/ruff/issues/7313
t = tempfile.NamedTemporaryFile() # noqa: SIM115
try:
fake_script.write(
'state-set',
Expand Down

0 comments on commit 3f7d81e

Please sign in to comment.