Skip to content

Commit

Permalink
Code satisfies flake8-docstring syntax (#35)
Browse files Browse the repository at this point in the history
* satisfies flake8

* D100

* D415

* D105

* flake8 exclude

* D300

* D209

* D202

* D403

* D402

* D107

* D417

* D205
  • Loading branch information
samuelduchesne committed Feb 12, 2021
1 parent 71be197 commit ca2ffa0
Show file tree
Hide file tree
Showing 56 changed files with 647 additions and 751 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,7 @@ target/

.idea/
/docs/reference/

test.dck

test_deck.txt
6 changes: 4 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""Docs module."""
# Configuration file for the Sphinx documentation builder.
#
# This file only contains a selection of the most common options. For a full
Expand All @@ -13,6 +14,8 @@
import os
import sys

from trnsystor import __version__

sys.path.insert(0, os.path.abspath("."))
sys.path.insert(0, os.path.abspath("trnsystor"))

Expand All @@ -23,9 +26,8 @@
author = "Samuel Letellier-Duchesne"

# The full version, including alpha/beta/rc tags
import trnsystor

version = release = trnsystor.__version__
version = release = __version__

# -- General configuration ---------------------------------------------------

Expand Down
9 changes: 8 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,11 @@ description-file = README.md
max-line-length = 88
extend-ignore =
# See https://github.com/PyCQA/pycodestyle/issues/373
E203,
E203,
docstring-convention=google
exclude =
.git,
__pycache__,
docs/conf.py,
tests
setup.py
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
"""Setup/install the package."""
# Always prefer setuptools over distutils
import codecs
import os
import re
from os import path

from setuptools import setup, find_packages
from setuptools import find_packages, setup

here = os.getcwd()

Expand Down
1 change: 1 addition & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Testing module."""
5 changes: 3 additions & 2 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Test utils module."""
import pytest

from trnsystor import redistribute_vertices
from trnsystor.utils import redistribute_vertices


class TestRedistributeVertices:
Expand Down Expand Up @@ -30,7 +31,7 @@ def test_redistribute_vertices(self, line):
assert newline.length == line.length

def test_redistribute_vertices_wrongtype(self, ring):
"""Tests unsupported geometry"""
"""Tests unsupported geometry."""
with pytest.raises(TypeError):
assert redistribute_vertices(ring, 10)

Expand Down
79 changes: 41 additions & 38 deletions tests/test_xml.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""Test module."""
import os
import sys
from tempfile import NamedTemporaryFile, TemporaryFile
Expand All @@ -13,7 +14,7 @@

@pytest.fixture(scope="class")
def fan_type():
"""Fixture to create a TrnsysModel from xml"""
"""Fixture to create a TrnsysModel from xml."""
from trnsystor.trnsysmodel import TrnsysModel

fan1 = TrnsysModel.from_xml(Path("tests/input_files/Type146.xml"))
Expand All @@ -22,7 +23,7 @@ def fan_type():

@pytest.fixture(scope="class")
def pipe_type():
"""Fixture to create a TrnsysModel from xml. Also tests using a Path"""
"""Fixture to create a TrnsysModel from xml. Also tests using a Path."""
from trnsystor.trnsysmodel import TrnsysModel

pipe = TrnsysModel.from_xml("tests/input_files/Type951.xml")
Expand Down Expand Up @@ -56,8 +57,10 @@ def weather_type():
class TestTrnsysModel:
@patch("builtins.input", return_value="y")
def test_chiller_type(self, input):
"""Fixture to create a TrnsysModel from xml from an xml that contains
unknown tags. Should prompt user. Passes when input == 'y'"""
"""Fixture to create a TrnsysModel from xml that contains unknown tags.
Should prompt user. Passes when input == 'y'
"""
from trnsystor.trnsysmodel import TrnsysModel

fan1 = TrnsysModel.from_xml("tests/input_files/Type107-simplified.xml")
Expand All @@ -79,9 +82,10 @@ def test_cycles(self, pipe_type):
assert actual == n_nodes

def test_cycles_2(self, pipe_type):
"""changing number of fluid nodes from 100 to 20 should create 20 outputs
for pipe 2 and 20 outputs for pipe 1"""
"""changing number of fluid nodes from 100 to 20 should create 20 outputs.
for pipe 2 and 20 outputs for pipe 1
"""
outputs = pipe_type.outputs
mylist = list(outputs.keys())
sub_1 = "Average_Fluid_Temperature_Pipe_1_"
Expand All @@ -106,7 +110,7 @@ def test_cycles_2(self, pipe_type):
assert n_nodes == expected_2

def test_cycles_issue14(self):
"""https://github.com/samuelduchesne/trnsystor/issues/14"""
"""https://github.com/samuelduchesne/trnsystor/issues/14."""
from trnsystor.trnsysmodel import TrnsysModel

valve = TrnsysModel.from_xml("tests/input_files/Type647.xml")
Expand Down Expand Up @@ -143,21 +147,21 @@ def test_cancel_missing_tag(self, tank_type):
with NamedTemporaryFile("w", delete=False) as tmp:
tmp.write(str(soup))
tmp.close()
tank = TrnsysModel.from_xml(tmp.name)
TrnsysModel.from_xml(tmp.name)
os.unlink(tmp.name)

def test_out_of_bounds(self, pipe_type):
"""should trigger ValueError because out of bounds"""
"""Trigger ValueError because out of bounds."""
with pytest.raises(ValueError):
pipe_type.parameters["Number_of_Radial_Soil_Nodes"] = 21

def test_get_attr(self, fan_type):
"""Test getter for class TypeVariable"""
"""Test getter for class TypeVariable."""
in_air_temp = fan_type.inputs["Inlet_Air_Temperature"]
assert in_air_temp

def test_set_attr(self, fan_type):
"""Test setter for class TypeVariable"""
"""Test setter for class TypeVariable."""
new_value = 12
attr_name = "Inlet_Air_Temperature"
fan_type.inputs[attr_name] = new_value
Expand All @@ -166,8 +170,10 @@ def test_set_attr(self, fan_type):
assert fan_type.inputs[attr_name].value == Q_.__class__(new_value, Q_.units)

def test_set_attr_quantity(self, fan_type):
"""Test setter for class TypeVariable with type _Quantity. This tests
setting a value with different but equivalent units"""
"""Test setter for class TypeVariable with type _Quantity.
This tests setting a value with different but equivalent units.
"""
attr_name = "Rated_Volumetric_Flow_Rate"
new_value = fan_type.parameters[attr_name].value.to("m^3/s") * 10
fan_type.parameters[attr_name] = new_value
Expand All @@ -184,12 +190,12 @@ def test_set_initial_input_values(self, fan_type):
assert fan_type.initial_input_values[attr_name]

def test_get_attr_derivative(self, tank_type):
"""Test setter for class Derivative"""
"""Test setter for class Derivative."""
attr_name = "Initial_temperature_of_node_1"
assert tank_type.derivatives[attr_name].value.m == 50.0

def test_set_attr_derivative(self, tank_type):
"""Test setter for class Derivative"""
"""Test setter for class Derivative."""
attr_name = "Initial_temperature_of_node_1"
tank_type.derivatives[attr_name] = 60
assert tank_type.derivatives[attr_name].value.m == 60.0
Expand All @@ -200,7 +206,7 @@ def test_get_attr_specialCards(self, plotter: TrnsysModel):
print(plotter.special_cards)

def test_set_attr_cycle_parameters(self, pipe_type):
"""Test setter for class TypeVariable"""
"""Test setter for class TypeVariable."""
attr_name = "Radial_Distance_of_Node_1"
new_value = 0.05
pipe_type.parameters[attr_name] = new_value
Expand All @@ -211,11 +217,11 @@ def test_set_attr_cycle_parameters(self, pipe_type):
)

def test_to_deck(self, fan_type):
"""test to Input File representation of a TrnsysModel"""
"""Test to Input File representation of a TrnsysModel."""
print(fan_type._to_deck())

def test_initial_input_values_to_deck(self, fan_type):
"""test to Input File representation of a TrnsysModel"""
"""Test to Input File representation of a TrnsysModel."""
print(fan_type.initial_input_values._to_deck())

def test_set_attr_cycle_question(self, tank_type):
Expand All @@ -237,13 +243,13 @@ def test_set_attr_cycle_question_2(self, tank_type):
)

def test_trnsysmodel_repr(self, tank_type):
"""test the __repr__ for :class:`TrnsysModel`"""
"""Test the __repr__ for :class:`TrnsysModel`."""
assert (
repr(tank_type)[3:] == "Type4: Storage Tank; Fixed Inlets, Uniform Losses"
)

def test_typecycle_repr(self, tank_type):
"""test the __repr__ for :class:`TypeCycle`"""
"""Test the __repr__ for :class:`TypeCycle`."""
assert repr(tank_type._meta.cycles[0]) == "output 1 to 13"

def test_collections_repr(self, tank_type):
Expand Down Expand Up @@ -285,7 +291,7 @@ def test_TypeVariable_repr(self, tank_type):
break

def test_set_wrong_type(self, fan_type):
"""try to assign a complexe number should raise a TypeError"""
"""Try to assign a complex number should raise a TypeError."""
with pytest.raises(TypeError):
fan_type.parameters["Rated_Volumetric_Flow_Rate"] = 2 + 3j

Expand All @@ -296,7 +302,7 @@ def test_set_wrong_type(self, fan_type):
"integer",
"real",
pytest.param(
"complexe", marks=pytest.mark.xfail(raises=NotImplementedError)
"complex", marks=pytest.mark.xfail(raises=NotImplementedError)
),
],
)
Expand Down Expand Up @@ -382,7 +388,7 @@ def test_get_external_file(self, weather_type):
)

def test_set_external_file(self, weather_type):
"""Test setting a different path for external files"""
"""Test setting a different path for external files."""
from path import Path

# test set Path behavior
Expand All @@ -408,13 +414,12 @@ def test_set_position(self, fan_type):
assert fan_type.studio.position == Point(50, 40)

def test_set_link_style_to_itself_error(self, fan_type):
"""Setting a link style on an non-existent connection should raise KeyError"""
"""Setting a link style on an non-existent connection should raise KeyError."""
fan_type.invalidate_connections()
with pytest.raises(KeyError):
fan_type.set_link_style(fan_type)

def test_set_link_style_to_itself(self, fan_type):
""""""
fan_type.connect_to(fan_type, mapping={0: 0})
fan_type.set_link_style(fan_type)

Expand Down Expand Up @@ -475,7 +480,7 @@ def test_statement_class(self):
from trnsystor.statement.statement import Statement

statement = Statement()
assert print(statement) == None
assert print(statement) is None

def test_version_statement(self):
from trnsystor.statement.version import Version
Expand Down Expand Up @@ -513,7 +518,7 @@ def test_width_statement(self):
width_statement = Width(80)
assert width_statement._to_deck() == "WIDTH 80"
with pytest.raises(ValueError):
wrong_statement = Width(1000)
Width(1000)

def test_nocheck_statement(self, fan_type):
from trnsystor.statement.nocheck import NoCheck
Expand All @@ -539,7 +544,7 @@ def test_nolist_statement(self):

@pytest.mark.parametrize("classmethod", ["all", "debug_template", "basic_template"])
def test_control_cards(self, classmethod):
"""Call different class methods on ControlCards"""
"""Call different class methods on ControlCards."""
from trnsystor.controlcards import ControlCards

cc = getattr(ControlCards, classmethod)()
Expand Down Expand Up @@ -644,12 +649,9 @@ def test_symbolic_expression_2(self, tank_type, fan_type):
print(eq)

def test_malformed_symbolic_expression(self, tank_type, fan_type):
"""passed only two args while expression asks for 3"""
from trnsystor.statement.constant import Constant

"""Pass only two args while expression asks for 3."""
name = "var_a"
exp = "log(a) + b / 12 - c"
c_ = Constant.from_expression("start=0")
from trnsystor.statement.equation import Equation

start = Equation("start", 0)
Expand All @@ -660,6 +662,7 @@ def test_empty_equationcollection(self):
from trnsystor.collections.equation import EquationCollection

eq = EquationCollection()
assert eq is not None

def test_equation_collection(self, equation_block):
from trnsystor.collections.equation import EquationCollection
Expand All @@ -675,10 +678,10 @@ def test_equation_collection(self, equation_block):

# An equal sign needs to be included in an expression
with pytest.raises(ValueError):
equa1 = Equation.from_expression("TdbAmb : [011,001]")
Equation.from_expression("TdbAmb : [011,001]")

def test_update_equation_collection(self, equation_block):
"""test different .update() recipes"""
"""Test different .update() recipes."""
from trnsystor.collections.equation import EquationCollection
from trnsystor.statement.equation import Equation

Expand Down Expand Up @@ -721,7 +724,7 @@ def test_equation_with_typevariable(self, fan_type):
)

def test_two_unnamed_equationcollection(self, fan_type):
"""make sure objects with same name=None can be created"""
"""Make sure objects with same name=None can be created."""
from trnsystor.collections.equation import EquationCollection
from trnsystor.statement.equation import Equation

Expand All @@ -742,7 +745,7 @@ def test_constant_collection(self, constant_block):
print(constant_block)

def test_update_constant_collection(self, constant_block):
"""test different .update() recipes"""
"""Test different .update() recipes."""
from trnsystor.collections.constant import ConstantCollection
from trnsystor.statement.constant import Constant

Expand Down Expand Up @@ -885,7 +888,7 @@ def test_save(self, pvt_deck):

class TestComponent:
def test_unique_hash(self, fan_type):
"""copying a component should change its hash"""
"""Copying a component should change its hash."""
fan_type_2 = fan_type.copy()
assert hash(fan_type) != hash(fan_type_2)

Expand Down Expand Up @@ -953,7 +956,7 @@ def test_type951(self, deck, tmp_path):


class TestStudioCanvas:
"""TODO: complete tests for Canvas LinkStyles and path positioning"""
"""TODO: complete tests for Canvas LinkStyles and path positioning."""

@pytest.mark.skip("known bug when copying type brakes cycles.")
def test_shortest_path(self, tank_type: TrnsysModel, pipe_type: TrnsysModel):
Expand Down
15 changes: 9 additions & 6 deletions trnsystor/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
"""Trnsystor Module."""

from outdated import warn_if_outdated

from .controlcards import ControlCards
from .deck import Deck
from .trnsysmodel import TrnsysModel

# Version of the package
__version__ = "1.3.1"

# warn if a newer version of archetypal is available
from outdated import warn_if_outdated

warn_if_outdated("trnsystor", __version__)

from .utils import *
from .trnsysmodel import TrnsysModel
from .deck import Deck
from .controlcards import ControlCards
__all__ = ["ControlCards", "Deck", "TrnsysModel", "__version__"]

0 comments on commit ca2ffa0

Please sign in to comment.