Skip to content

Commit

Permalink
Even more ruff fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
bje- committed Jun 29, 2024
1 parent 051dce1 commit 0536423
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 20 deletions.
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

import time

from pathlib import Path
from setuptools import setup

with open('README.md', encoding='utf-8') as f:
with Path('README.md').open() as f:
long_description = f.read()

setup(name='nemopt',
Expand Down
7 changes: 4 additions & 3 deletions tests/test_generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"""A testsuite for the generators module."""

import inspect
import os
import unittest
from pathlib import Path

import numpy as np
import pandas as pd
Expand Down Expand Up @@ -77,7 +77,7 @@ class TestGenerators(unittest.TestCase):
def setUp(self):
"""Test harness setup."""
self.tracefile = 'tracedata.csv'
with open(self.tracefile, 'w', encoding='utf-8') as tracefile:
with Path(self.tracefile).open('w') as tracefile:
for i in range(100):
print(f'{0.01 * i:.2f}, 0', file=tracefile)

Expand Down Expand Up @@ -107,7 +107,8 @@ def setUp(self):

def tearDown(self):
"""Remove tracefile on teardown."""
os.unlink(self.tracefile)
path = Path(self.tracefile)
path.unlink()

def test_series(self):
"""Test series() method."""
Expand Down
1 change: 0 additions & 1 deletion tests/test_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ class TestPumpedHydro(unittest.TestCase):

def setUp(self):
"""Test harness setup."""

# Attach the reservroir to the pump and the turbine.
# In this case, the pump and turbine are symmetric at 100 MW.
self.reservoir = storage.PumpedHydroStorage(1000)
Expand Down
23 changes: 8 additions & 15 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
# Some protected members (eg _figure) are accessed to facilitate testing.
# pylint: disable=protected-access

import os
import unittest
from datetime import timedelta
from pathlib import Path

import pytest

Expand All @@ -24,32 +24,25 @@ class TestUtils(unittest.TestCase):

def unlink(self, filename):
"""Unlink filename without error."""
try:
os.unlink(filename)
except FileNotFoundError:
pass
Path(filename).unlink(missing_ok=True)

def exists(self, filename):
"""Return True if filename exists."""
try:
os.stat(filename)
return True
except FileNotFoundError:
return False
return Path(filename).exists()

def setUp(self):
"""Test harness setup."""
self.context = context.Context()
scenarios.ccgt(self.context)
sim.run(self.context)

@pytest.mark.mpl_image_compare
@pytest.mark.mpl_image_compare()
def test_figure_1(self):
"""Test simple supply/demand plot."""
utils._figure(self.context, spills=True, showlegend=True, xlim=None)
return utils.plt.gcf()

@pytest.mark.mpl_image_compare
@pytest.mark.mpl_image_compare()
def test_figure_2(self):
"""Test supply/demand plot with many generators."""
ngens = len(self.context.generators)
Expand All @@ -68,7 +61,7 @@ def test_plot_1(self):
self.unlink(fname)
utils.plot(self.context, filename=fname)
self.assertTrue(self.exists(fname))
os.unlink(fname)
self.unlink(fname)

def test_plot_2(self):
"""Test plot with only 7 days of data."""
Expand All @@ -78,7 +71,7 @@ def test_plot_2(self):
self.unlink(fname)
utils.plot(self.context, filename=fname, xlim=(start, end))
self.assertTrue(self.exists(fname))
os.unlink(fname)
self.unlink(fname)

def test_plot_3(self):
"""Test plot with only 7 days of data."""
Expand All @@ -88,4 +81,4 @@ def test_plot_3(self):
self.context.timesteps = lambda: 7 * 24
utils.plot(self.context, filename=fname)
self.assertTrue(self.exists(fname))
os.unlink(fname)
self.unlink(fname)

0 comments on commit 0536423

Please sign in to comment.