Skip to content

Tests of capacity scaling fail #96

@danielolsen

Description

@danielolsen

The first issue: from mock import patch. mock isn't a requirement and so it isn't always installed (like in my case). From the pypi page (https://pypi.org/project/mock/), it seems like we can replace that with from unittest.mock import patch

The second issue: tests fail when they are run from root, I think because they expect to be run from a certain directory.

Calling pytest from package root:

PS C:\Users\dolsen\repos\iv\powersimdata> python -m pytest
============================= test session starts =============================
platform win32 -- Python 3.7.4, pytest-5.3.1, py-1.8.0, pluggy-0.13.1
rootdir: C:\Users\dolsen\repos\iv\powersimdata
collected 74 items

powersimdata\input\tests\test_design_transmission.py ................... [ 25%]
...........                                                              [ 40%]
powersimdata\input\tests\test_grid.py .....                              [ 47%]
powersimdata\scaling\clean_capacity_scaling\tests\test_install_package.py s [ 48%]
                                                                         [ 48%]
powersimdata\scaling\clean_capacity_scaling\tests\test_object_persistence.py . [ 50%]
.FF                                                                      [ 54%]
powersimdata\scaling\clean_capacity_scaling\tests\test_resource_target_manager.py . [ 55%]
...............                                                          [ 75%]
powersimdata\scaling\clean_capacity_scaling\tests\test_strategies.py ... [ 79%]
.......                                                                  [ 89%]
powersimdata\scaling\clean_capacity_scaling\tests\test_target_manager_input.py . [ 90%]
..sssss                                                                  [100%]

================================== FAILURES ===================================
____________________ test_write_read_json_of_target_object ____________________

    def test_write_read_json_of_target_object():
        # create Pacific
        pacific_solar = Resource('solar', 3)
        pacific_solar.set_capacity(0.25, 3700, 0.215379)
        pacific_solar.set_generation(7000)
        pacific_solar.set_curtailment(0.138483)
        pacific_solar.set_addl_curtailment(0)

        pacific_wind = Resource('wind', 3)
        pacific_wind.set_capacity(0.4, 3600, 0.347855)
        pacific_wind.set_generation(11000)
        pacific_wind.set_curtailment(0.130363)
        pacific_wind.set_addl_curtailment(0)

        pacific_geo = Resource('geo', 3)
        pacific_geo.set_capacity(1, 4000, 1)
        pacific_geo.set_generation(8000)
        pacific_geo.set_curtailment(0)
        pacific_geo.set_addl_curtailment(0)

        pacific_hydro = Resource('hydro', 3)
        pacific_hydro.set_capacity(1, 3900, 1)
        pacific_hydro.set_generation(7000)
        pacific_hydro.set_curtailment(0)
        pacific_hydro.set_addl_curtailment(0)

        pacific_nuclear = Resource('nuclear', 3)
        pacific_nuclear.set_capacity(1, 4300, 1)
        pacific_nuclear.set_generation(6500)
        pacific_nuclear.set_curtailment(0)
        pacific_nuclear.set_addl_curtailment(0)

        pacific_target = TargetManager('Pacific', 0.25, 'renewables', 200000)
        pacific_target.set_allowed_resources(['solar', 'wind', 'geo'])
        pacific_target.add_resource(pacific_solar)
        pacific_target.add_resource(pacific_wind)
        pacific_target.add_resource(pacific_geo)
        pacific_target.add_resource(pacific_hydro)
        pacific_target.add_resource(pacific_nuclear)

>       pacific_target.save_target_as_json()

powersimdata\scaling\clean_capacity_scaling\tests\test_object_persistence.py:97:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <powersimdata.scaling.clean_capacity_scaling.auto_capacity_scaling.TargetManager object at 0x0000019A3D423D08>

    def save_target_as_json(self):
        print(os.getcwd())
>       json_file = open(os.path.relpath(os.path.join("save_files", self.region_name+".json")), "w")
E       FileNotFoundError: [Errno 2] No such file or directory: 'save_files\\Pacific.json'

powersimdata\scaling\clean_capacity_scaling\auto_capacity_scaling.py:384: FileNotFoundError
---------------------------- Captured stdout call -----------------------------
C:\Users\dolsen\repos\iv\powersimdata
___________________ test_write_read_pickle_of_target_object ___________________

    def test_write_read_pickle_of_target_object():
        # create Pacific
        pacific_solar = Resource('solar', 3)
        pacific_solar.set_capacity(0.25, 3700, 0.215379)
        pacific_solar.set_generation(7000)
        pacific_solar.set_curtailment(0.138483)
        pacific_solar.set_addl_curtailment(0)

        pacific_wind = Resource('wind', 3)
        pacific_wind.set_capacity(0.4, 3600, 0.347855)
        pacific_wind.set_generation(11000)
        pacific_wind.set_curtailment(0.130363)
        pacific_wind.set_addl_curtailment(0)

        pacific_geo = Resource('geo', 3)
        pacific_geo.set_capacity(1, 4000, 1)
        pacific_geo.set_generation(8000)
        pacific_geo.set_curtailment(0)
        pacific_geo.set_addl_curtailment(0)

        pacific_hydro = Resource('hydro', 3)
        pacific_hydro.set_capacity(1, 3900, 1)
        pacific_hydro.set_generation(7000)
        pacific_hydro.set_curtailment(0)
        pacific_hydro.set_addl_curtailment(0)

        pacific_nuclear = Resource('nuclear', 3)
        pacific_nuclear.set_capacity(1, 4300, 1)
        pacific_nuclear.set_generation(6500)
        pacific_nuclear.set_curtailment(0)
        pacific_nuclear.set_addl_curtailment(0)

        pacific_target = TargetManager('Pacific', 0.25, 'renewables', 200000)
        pacific_target.set_allowed_resources(['solar', 'wind', 'geo'])
        pacific_target.add_resource(pacific_solar)
        pacific_target.add_resource(pacific_wind)
        pacific_target.add_resource(pacific_geo)
        pacific_target.add_resource(pacific_hydro)
        pacific_target.add_resource(pacific_nuclear)

>       pacific_target.save_target_as_pickle()

powersimdata\scaling\clean_capacity_scaling\tests\test_object_persistence.py:144:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <powersimdata.scaling.clean_capacity_scaling.auto_capacity_scaling.TargetManager object at 0x0000019A3D072988>

    def save_target_as_pickle(self):
        print(os.getcwd())
>       json_file = open(os.path.relpath(os.path.join("save_files", self.region_name+".pkl")), "wb")
E       FileNotFoundError: [Errno 2] No such file or directory: 'save_files\\Pacific.pkl'

powersimdata\scaling\clean_capacity_scaling\auto_capacity_scaling.py:391: FileNotFoundError
---------------------------- Captured stdout call -----------------------------
C:\Users\dolsen\repos\iv\powersimdata
============================== warnings summary ===============================
C:\Python37\lib\site-packages\win32\lib\pywintypes.py:2
  C:\Python37\lib\site-packages\win32\lib\pywintypes.py:2: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
    import imp, sys, os

-- Docs: https://docs.pytest.org/en/latest/warnings.html
============= 2 failed, 66 passed, 6 skipped, 1 warning in 1.97s ==============
PS C:\Users\dolsen\repos\iv\powersimdata>

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions