Skip to content

Commit

Permalink
quickExample fix #201 and pytest
Browse files Browse the repository at this point in the history
adding testfolder optional input to quickExample() so it can be used in the pytest, and also returning analysis so it can be used in the pytest. Also calls now the interative directory from main.py instead of re-defining it inside.
Solves #201

Added pytest
  • Loading branch information
shirubana committed Nov 27, 2019
1 parent bedea2a commit 856049c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
18 changes: 6 additions & 12 deletions bifacial_radiance/main.py
Expand Up @@ -3666,23 +3666,17 @@ def runJob(daydate):
rowWanted=rowWanted,
sensorsy=sensorsy)

def quickExample():
def quickExample(testfolder=None):
"""
Example of how to run a Radiance routine for a simple rooftop bifacial system
"""
def _interactive_directory(title=None):
# Tkinter directory picker. Now Py3.6 compliant!
import tkinter
from tkinter import filedialog
root = tkinter.Tk()
root.withdraw() #Start interactive file input
root.attributes("-topmost", True) #Bring to front
return filedialog.askdirectory(parent=root, title=title)

import bifacial_radiance
testfolder = _interactive_directory(title = 'Select or create an empty directory for the Radiance tree')
# testfolder = r'C:\Users\sayala\Documents\RadianceScenes\Demo3'

if testfolder == None:
testfolder = bifacial_radiance.main._interactive_directory(title = 'Select or create an empty directory for the Radiance tree')

demo = bifacial_radiance.RadianceObj('simple_panel',path = testfolder) # Create a RadianceObj 'object'

# A=load_inputvariablesfile()
Expand Down Expand Up @@ -3723,4 +3717,4 @@ def _interactive_directory(title=None):
print('Annual bifacial ratio average: %0.3f' %(
sum(analysis.Wm2Back) / sum(analysis.Wm2Front) ) )


return analysis
3 changes: 3 additions & 0 deletions tests/test_bifacial_radiance.py
Expand Up @@ -30,6 +30,9 @@
# also test a dummy TMY3 Denver file in /tests/
MET_FILENAME2 = "724666TYA.CSV"

def test_quickExample():
results = bifacial_radiance.main.quickExample(TESTDIR)
assert np.mean(results.Wm2Back) == pytest.approx(195380.94444444444, rel = 0.03) # was 182 in v0.2.2

def test_RadianceObj_set1axis():
# test set1axis. requires metdata for boulder.
Expand Down

0 comments on commit 856049c

Please sign in to comment.