Skip to content

Commit

Permalink
#5192 - Add tests for both ruby and python
Browse files Browse the repository at this point in the history
```
The following tests FAILED:
	3705 - RubyTest-SwigJson_Test-swig_json_special_chars (Failed)
	3870 - CLITest-SwigJson_Test-swig_json_special_chars (Failed)
```
  • Loading branch information
jmarrec committed May 13, 2024
1 parent 53c1d69 commit a0318cf
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 0 deletions.
35 changes: 35 additions & 0 deletions python/test/test_swigjson.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from pathlib import Path

import openstudio


def test_swig_json_special_chars():
workflow = openstudio.WorkflowJSON()
runner = openstudio.measure.OSRunner(workflow)

step1 = openstudio.MeasureStep("MeasureName1")
step1.setArgument("Argument1", 100)

workflow_step_result1 = openstudio.WorkflowStepResult()
workflow_step_result1.setMeasureName("measure_name_1")

name = "name_(|)'*$£*µ%é"
val = "val_(|)'*$£*µ%é"
stepValue1 = openstudio.WorkflowStepValue(name, val)
assert name == stepValue1.name()
assert val == stepValue1.valueAsString()
assert val == stepValue1.valueAsJSON()

workflow_step_result1.addStepValue(stepValue1)

workflow_step_result1.setStepResult(openstudio.StepResult('Success'))
workflow_step_result1.setCompletedAt(openstudio.DateTime.nowUTC())
step1.setResult(workflow_step_result1)

workflow.setWorkflowSteps([step1])

d = runner.getPastStepValuesForMeasure("MeasureName1")
assert len(d) == 1
k, v = next(iter(d.items()))
assert k == name
assert v == val
43 changes: 43 additions & 0 deletions ruby/test/SwigJson_Test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
########################################################################################################################
# OpenStudio(R), Copyright (c) Alliance for Sustainable Energy, LLC.
# See also https://openstudio.net/license
########################################################################################################################

require 'openstudio'
require 'minitest/autorun'

class SwigJSONTest < Minitest::Test

def test_swig_json_special_chars
workflow = OpenStudio::WorkflowJSON.new()
runner = OpenStudio::Measure::OSRunner.new(workflow)

step1 = OpenStudio::MeasureStep.new("MeasureName1")
step1.setArgument("Argument1", 100)

workflow_step_result1 = OpenStudio::WorkflowStepResult.new()
workflow_step_result1.setMeasureName("measure_name_1")

name = "name_(|)'*$£*µ%é"
val = "val_(|)'*$£*µ%é"
stepValue1 = OpenStudio::WorkflowStepValue.new(name, val)
assert_equal(name, stepValue1.name)
assert_equal(val, stepValue1.valueAsString)
assert_equal(val, stepValue1.valueAsJSON)
workflow_step_result1.addStepValue(stepValue1)

workflow_step_result1.setStepResult('Success'.to_StepResult)
workflow_step_result1.setCompletedAt(OpenStudio::DateTime.nowUTC())
step1.setResult(workflow_step_result1)

workflow.setWorkflowSteps([step1])

# workflow.saveAs("OSRunner_getPastStepValues_special_chars.osw")

h = runner.getPastStepValuesForMeasure("MeasureName1")
assert_equal(1, h.size)
assert_equal(name.to_sym, h.keys.first)
assert_equal(val, h.values.first)
end

end

0 comments on commit a0318cf

Please sign in to comment.