diff --git a/lib/measures/urban_geometry_creation/measure.rb b/lib/measures/urban_geometry_creation/measure.rb index 1771f7e..2df83b5 100644 --- a/lib/measures/urban_geometry_creation/measure.rb +++ b/lib/measures/urban_geometry_creation/measure.rb @@ -51,8 +51,8 @@ def arguments(model) surrounding_buildings.setDefaultValue('ShadingOnly') args << surrounding_buildings # not a required argument - scale_footprint_area_by_floor_area = OpenStudio::Ruleset::OSArgument.makeBoolArgument('scale_footprint_area_by_floor_area', false) - scale_footprint_area_by_floor_area.setDisplayName('Scale Footprint Area by the Floor Area?') + scale_footprint_area_by_floor_area = OpenStudio::Measure::OSArgument.makeBoolArgument('scale_footprint_area_by_floor_area', false) + scale_footprint_area_by_floor_area.setDisplayName('Scale Footprint Area by the Floor Area') scale_footprint_area_by_floor_area.setDescription('If true, the footprint area from GeoJSON will be scaled by the floor_area provided by the user in URBANopt.') scale_footprint_area_by_floor_area.setDefaultValue(false) args << scale_footprint_area_by_floor_area diff --git a/lib/measures/urban_geometry_creation/tests/shadowed_tests.rb b/lib/measures/urban_geometry_creation/tests/shadowed_tests.rb index b46263c..69cea89 100644 --- a/lib/measures/urban_geometry_creation/tests/shadowed_tests.rb +++ b/lib/measures/urban_geometry_creation/tests/shadowed_tests.rb @@ -12,7 +12,7 @@ require_relative '../measure' require 'fileutils' -class UrbanGeometryCreationTest < MiniTest::Unit::TestCase +class UrbanGeometryCreationTest < MiniTest::Test def test_shadowed_case denver_zoo = OpenStudio::PointLatLon.new(39.749242, -104.951024, 0) blocky = [ diff --git a/lib/measures/urban_geometry_creation/tests/urban_geometry_creation_test.rb b/lib/measures/urban_geometry_creation/tests/urban_geometry_creation_test.rb index f9054aa..9039218 100644 --- a/lib/measures/urban_geometry_creation/tests/urban_geometry_creation_test.rb +++ b/lib/measures/urban_geometry_creation/tests/urban_geometry_creation_test.rb @@ -12,7 +12,7 @@ require_relative '../measure' require 'fileutils' -class UrbanGeometryCreationTest < MiniTest::Unit::TestCase +class UrbanGeometryCreationTest < MiniTest::Test def test_one_building # create an instance of the measure measure = UrbanGeometryCreation.new diff --git a/lib/measures/urban_geometry_creation_zoning/tests/urban_geometry_creation_zoning_test.rb b/lib/measures/urban_geometry_creation_zoning/tests/urban_geometry_creation_zoning_test.rb index 1aa888a..0686ee7 100644 --- a/lib/measures/urban_geometry_creation_zoning/tests/urban_geometry_creation_zoning_test.rb +++ b/lib/measures/urban_geometry_creation_zoning/tests/urban_geometry_creation_zoning_test.rb @@ -11,7 +11,7 @@ require_relative '../measure.rb' require 'fileutils' -class UrbanGeometryCreationZoningTest < MiniTest::Unit::TestCase +class UrbanGeometryCreationZoningTest < MiniTest::Test def test_one_building # create an instance of the measure measure = UrbanGeometryCreationZoning.new diff --git a/lib/urbanopt/geojson/geo_file.rb b/lib/urbanopt/geojson/geo_file.rb index 645da13..6a1fbe4 100644 --- a/lib/urbanopt/geojson/geo_file.rb +++ b/lib/urbanopt/geojson/geo_file.rb @@ -84,7 +84,8 @@ def self.from_file(path) raise('No name found for Building Feature') end if feature[:properties][:number_of_stories].nil? - @@logger.warn("Number of stories is required to calculate shading using the UrbanGeometryCreation measure...ignoring #{feature[:properties][:id]} in shading calculations") + @@logger.warn("Number of stories is required to calculate shading using the UrbanGeometryCreation measure.\n" \ + "Not validating #{feature[:properties][:id]} against schema and ignoring in shading calculations") end feature[:additionalProperties] = true # In case hpxml_directory present check for fewer properties @@ -95,6 +96,8 @@ def self.from_file(path) if feature[:properties][:name].nil? raise('No name found for Building Feature') end + @@logger.warn("OS-HPXML files may not conform to schema, which is usually ok.\n" \ + "Not validating #{feature[:properties][:id]} against schema") # Else validate for all required properties in the schema else errors = validate(@@building_schema, properties) diff --git a/spec/files/id_6_missing_number_of_stories.json b/spec/files/id_6_missing_number_of_stories.json new file mode 100644 index 0000000..0a74f85 --- /dev/null +++ b/spec/files/id_6_missing_number_of_stories.json @@ -0,0 +1,768 @@ +{ + "type": "FeatureCollection", + "project": { + "id": "7c33a001-bccb-413e-ac87-67558b5d4b07", + "name": "New Project", + "surface_elevation": null, + "import_surrounding_buildings_as_shading": null, + "weather_filename": "USA_NY_Buffalo-Greater.Buffalo.Intl.AP.725280_TMY3.epw", + "tariff_filename": null, + "climate_zone": "6A", + "cec_climate_zone": null, + "begin_date": "2017-01-01T07:00:00.000Z", + "end_date": "2017-12-31T07:00:00.000Z", + "timesteps_per_hour": 1, + "default_template": "90.1-2013", + "emissions": true, + "electricity_emissions_future_subregion": "NYSTc", + "electricity_emissions_hourly_historical_subregion": "New York", + "electricity_emissions_annual_historical_subregion": "NYCW", + "electricity_emissions_future_year": "2030", + "electricity_emissions_hourly_historical_year": "2019", + "electricity_emissions_annual_historical_year": "2019" + }, + "features": [ + { + "type": "Feature", + "properties": { + "id": "53340c2c-ab20-40db-aba1-11ac607c52a7", + "name": "Site Origin", + "type": "Site Origin", + "begin_date": "2017-01-01T07:00:00.000Z", + "end_date": "2017-12-31T07:00:00.000Z", + "cec_climate_zone": null, + "climate_zone": "6A", + "default_template": "90.1-2013", + "import_surrounding_buildings_as_shading": null, + "surface_elevation": null, + "tariff_filename": null, + "timesteps_per_hour": 1, + "weather_filename": "USA_NY_Buffalo-Greater.Buffalo.Intl.AP.725280_TMY3.epw" + }, + "geometry": { + "type": "Point", + "coordinates": [ + -78.84948467732348, + 42.81677154451123 + ] + } + }, + { + "type": "Feature", + "properties": { + "id": "1", + "name": "Mixed_use 1", + "type": "Building", + "building_type": "Mixed use", + "floor_area": 752184, + "footprint_area": 188046, + "number_of_stories": 4, + "mixed_type_1": "Office", + "mixed_type_1_percentage": 50, + "mixed_type_2": "Food service", + "mixed_type_2_percentage": 50, + "mixed_type_3": "Strip shopping mall", + "mixed_type_3_percentage": 0, + "mixed_type_4": "Lodging", + "mixed_type_4_percentage": 0 + }, + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [ + -78.84650338745196, + 42.81331301863236 + ], + [ + -78.84652443964629, + 42.81463974371101 + ], + [ + -78.84680142363833, + 42.815293654042537 + ], + [ + -78.84744455124724, + 42.81514110006128 + ], + [ + -78.84728610028628, + 42.81478165791734 + ], + [ + -78.84786797764677, + 42.814643631760137 + ], + [ + -78.84721106637106, + 42.813153418927019 + ], + [ + -78.84650338745196, + 42.81331301863236 + ] + ] + ] + } + }, + { + "type": "Feature", + "properties": { + "id": "2", + "name": "Restaurant 1", + "type": "Building", + "building_type": "Food service", + "floor_area": 22313, + "footprint_area": 22313, + "number_of_stories": 1 + }, + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [ + -78.8500120420453, + 42.81812185529549 + ], + [ + -78.85038975191084, + 42.81803226424341 + ], + [ + -78.850630729414, + 42.81857888627522 + ], + [ + -78.85025301954843, + 42.81866847653532 + ], + [ + -78.8500120420453, + 42.81812185529549 + ] + ] + ] + } + }, + { + "type": "Feature", + "properties": { + "id": "3", + "name": "Restaurant 10", + "type": "Building", + "building_type": "Food service", + "floor_area": 125631, + "footprint_area": 41877, + "number_of_stories": 3 + }, + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [ + -78.84962224800356, + 42.81329273502644 + ], + [ + -78.84929833482822, + 42.81337083838241 + ], + [ + -78.84983265832118, + 42.814563298664669 + ], + [ + -78.85015657149653, + 42.81448519681467 + ], + [ + -78.84962224800356, + 42.81329273502644 + ] + ] + ] + } + }, + { + "type": "Feature", + "properties": { + "id": "4", + "name": "Restaurant 12", + "type": "Building", + "building_type": "Food service", + "floor_area": 31623, + "footprint_area": 10541, + "number_of_stories": 3 + }, + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [ + -78.84907318596754, + 42.81342719667407 + ], + [ + -78.84862090048105, + 42.81353625345659 + ], + [ + -78.84871721918239, + 42.813751210926799 + ], + [ + -78.84916950466888, + 42.81364215452331 + ], + [ + -78.84907318596754, + 42.81342719667407 + ] + ] + ] + } + }, + { + "type": "Feature", + "properties": { + "id": "5", + "name": "Restaurant 14", + "type": "Building", + "building_type": "Food service", + "floor_area": 8804, + "footprint_area": 8804, + "number_of_stories": 1 + }, + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [ + -78.84809175426629, + 42.81367038997507 + ], + [ + -78.84848670778973, + 42.81357515750889 + ], + [ + -78.84857883872144, + 42.81378076888831 + ], + [ + -78.84818388519801, + 42.81387600103781 + ], + [ + -78.84809175426629, + 42.81367038997507 + ] + ] + ] + } + }, + { + "type": "Feature", + "properties": { + "id": "6", + "name": "Restaurant 15", + "type": "Building", + "building_type": "Food service", + "floor_area": 10689, + "footprint_area": 10689 + }, + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [ + -78.84846106738529, + 42.814495803077367 + ], + [ + -78.8486903952376, + 42.81444050756261 + ], + [ + -78.8484977578349, + 42.81401059666683 + ], + [ + -78.84826842998261, + 42.81406589256599 + ], + [ + -78.84846106738529, + 42.814495803077367 + ] + ] + ] + } + }, + { + "type": "Feature", + "properties": { + "id": "7", + "name": "Office 1", + "type": "Building", + "building_type": "Office", + "detailed_model_filename": "7.osm", + "number_of_stories": 3 + }, + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [ + -78.84733878006863, + 42.816466983030839 + ], + [ + -78.84854275129324, + 42.81617669028003 + ], + [ + -78.848356395545, + 42.81576080994094 + ], + [ + -78.84715242432039, + 42.81605110464406 + ], + [ + -78.84733878006863, + 42.816466983030839 + ] + ] + ] + } + }, + { + "type": "Feature", + "properties": { + "id": "8", + "name": "Hospital 1", + "type": "Building", + "building_type": "Outpatient health care", + "number_of_stories": 10, + "detailed_model_filename": "8.osm" + }, + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [ + -78.84973966335251, + 42.8154441454509 + ], + [ + -78.85049562542395, + 42.81525669280299 + ], + [ + -78.85078257620686, + 42.81588131780643 + ], + [ + -78.8505086568277, + 42.81594736368234 + ], + [ + -78.85041233812638, + 42.815732413845669 + ], + [ + -78.84991755499783, + 42.81585689105046 + ], + [ + -78.84973966335251, + 42.8154441454509 + ] + ] + ] + } + }, + { + "type": "Feature", + "properties": { + "id": "9", + "name": "Hospital 2", + "type": "Building", + "building_type": "Inpatient health care", + "number_of_stories": 3, + "detailed_model_filename": "9.osm" + }, + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [ + -78.85083627755732, + 42.81600678613279 + ], + [ + -78.85056039001892, + 42.816076133580569 + ], + [ + -78.85072568130569, + 42.816450649528039 + ], + [ + -78.84940134236577, + 42.81677160705479 + ], + [ + -78.84958014898304, + 42.81716858994267 + ], + [ + -78.8507262115271, + 42.816890840117029 + ], + [ + -78.8508565789851, + 42.81719595796099 + ], + [ + -78.85132137101688, + 42.81708331517635 + ], + [ + -78.85083627755732, + 42.81600678613279 + ] + ] + ] + } + }, + { + "type": "Feature", + "properties": { + "id": "10", + "name": "Mixed use 2", + "type": "Building", + "building_type": "Mixed use", + "floor_area": 1278384, + "footprint_area": 159798, + "number_of_stories": 8, + "mixed_type_1": "Strip shopping mall", + "mixed_type_1_percentage": 25, + "mixed_type_2": "Food service", + "mixed_type_2_percentage": 25, + "mixed_type_3": "Office", + "mixed_type_3_percentage": 15, + "mixed_type_4": "Lodging", + "mixed_type_4_percentage": 35 + }, + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [ + -78.85115264550463, + 42.81786093060211 + ], + [ + -78.85163483958879, + 42.81774467026972 + ], + [ + -78.85246596719499, + 42.819583261120758 + ], + [ + -78.85082390085432, + 42.819979162017748 + ], + [ + -78.85060552295335, + 42.81947573727234 + ], + [ + -78.85174564783776, + 42.81920483484765 + ], + [ + -78.85115264550463, + 42.81786093060211 + ] + ] + ] + } + }, + { + "type": "Feature", + "properties": { + "id": "11", + "name": "Restaurant 13", + "type": "Building", + "building_type": "Food service", + "floor_area": 32511, + "footprint_area": 10837, + "number_of_stories": 3 + }, + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [ + -78.84961163640645, + 42.81460851835703 + ], + [ + -78.84914661048372, + 42.81472064501696 + ], + [ + -78.84905029178236, + 42.81450569091638 + ], + [ + -78.84951531770513, + 42.81439356386673 + ], + [ + -78.84961163640645, + 42.81460851835703 + ] + ] + ] + } + }, + { + "type": "Feature", + "properties": { + "id": "12", + "name": "Mall 1", + "type": "Building", + "building_type": "Strip shopping mall", + "floor_area": 374409, + "footprint_area": 124803, + "number_of_stories": 3 + }, + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [ + -78.84768338040897, + 42.817161656757068 + ], + [ + -78.8482630702579, + 42.8170218879136 + ], + [ + -78.84915297130292, + 42.81900776764229 + ], + [ + -78.84857328145401, + 42.81914753199706 + ], + [ + -78.84768338040897, + 42.817161656757068 + ] + ] + ] + } + }, + { + "type": "Feature", + "properties": { + "id": "13", + "name": "Hotel 1", + "type": "Building", + "building_type": "Lodging", + "floor_area": 316160, + "footprint_area": 31616, + "number_of_stories": 10 + }, + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [ + -78.8494955083645, + 42.819748790984338 + ], + [ + -78.84891089471263, + 42.81989327725856 + ], + [ + -78.8491389243777, + 42.82038967009544 + ], + [ + -78.84972353802957, + 42.82024518498119 + ], + [ + -78.8494955083645, + 42.819748790984338 + ] + ] + ] + } + }, + { + "type": "Feature", + "properties": { + "id": "14", + "name": "Residential 1", + "type": "Building", + "building_type": "Single-Family Detached", + "floor_area": 3055, + "footprint_area": 3055, + "number_of_stories_above_ground": 1, + "number_of_stories": 1, + "number_of_bedrooms": 3, + "foundation_type": "crawlspace - unvented", + "attic_type": "attic - vented", + "system_type": "Residential - furnace and central air conditioner", + "heating_system_fuel_type": "natural gas", + "template": "Residential IECC 2015 - Customizable Template Sep 2020" + }, + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [ + -78.84782863379475, + 42.81308406513335 + ], + [ + -78.84789445741784, + 42.813211653666147 + ], + [ + -78.8481085224459, + 42.81315222398479 + ], + [ + -78.84804269882281, + 42.813024635329359 + ], + [ + -78.84782863379475, + 42.81308406513335 + ] + ] + ] + } + }, + { + "type": "Feature", + "properties": { + "id": "15", + "name": "Residential 2", + "type": "Building", + "building_type": "Single-Family Detached", + "floor_area": 4260, + "footprint_area": 2130, + "number_of_stories_above_ground": 2, + "number_of_stories": 3, + "number_of_bedrooms": 4, + "foundation_type": "basement - unconditioned", + "attic_type": "attic - unvented", + "system_type": "Residential - boiler and room air conditioner", + "heating_system_fuel_type": "propane", + "template": "Residential IECC 2015 - Customizable Template Sep 2020" + }, + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [ + -78.84841249573596, + 42.81294385519362 + ], + [ + -78.8484849661432, + 42.81308642712324 + ], + [ + -78.84861900200103, + 42.81304976336804 + ], + [ + -78.84854653159381, + 42.8129071913539 + ], + [ + -78.84841249573596, + 42.81294385519362 + ] + ] + ] + } + }, + { + "type": "Feature", + "properties": { + "id": "16", + "name": "Residenital 3", + "type": "Building", + "building_type": "Single-Family Detached", + "floor_area": 5500, + "footprint_area": 4655, + "number_of_stories_above_ground": 1, + "number_of_stories": 2, + "number_of_bedrooms": 5, + "foundation_type": "basement - conditioned", + "attic_type": "attic - conditioned", + "system_type": "Residential - electric resistance and no cooling", + "heating_system_fuel_type": "electricity", + "template": "Residential IECC 2015 - Customizable Template Sep 2020" + }, + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [ + -78.84901642777548, + 42.81281054264619 + ], + [ + -78.8492166996002, + 42.81276856688589 + ], + [ + -78.8492882250648, + 42.81294171638328 + ], + [ + -78.84919524192809, + 42.812957457222669 + ], + [ + -78.84925246216879, + 42.81307288984212 + ], + [ + -78.84915232658385, + 42.8130833837933 + ], + [ + -78.84901642777548, + 42.81281054264619 + ] + ] + ] + } + } + ], + "mappers": [], + "scenarios": [ + { + "feature_mappings": [], + "id": "72301739-c6c3-4dd7-bf1a-f37c8eff40db", + "name": "New Scenario" + } + ] + } diff --git a/spec/urbanopt/geojson/feature_spec.rb b/spec/urbanopt/geojson/feature_spec.rb index 0fc06b1..132e6c0 100644 --- a/spec/urbanopt/geojson/feature_spec.rb +++ b/spec/urbanopt/geojson/feature_spec.rb @@ -7,7 +7,7 @@ RSpec.describe URBANopt::GeoJSON do before(:each) do - path = File.join(File.dirname(__FILE__), '..', '..', 'files', 'nrel_stm_footprints.geojson') + path = Pathname(__FILE__).dirname.parent.parent / 'files' / 'nrel_stm_footprints.geojson' feature_id = '59a9ce2b42f7d007c059d2fa' @model = OpenStudio::Model::Model.new @origin_lat_lon = OpenStudio::PointLatLon.new(0, 0, 0) @@ -15,6 +15,10 @@ @feature = URBANopt::GeoJSON::GeoFile.from_file(path).get_feature_by_id(feature_id) end + it 'validates that the feature is valid' do + expect { @feature }.not_to raise_error + end + it 'creates minimum longitute and latitude given a polygon' do min_lon_and_lat = @feature.get_min_lon_lat expect(min_lon_and_lat).to eq([-105.17319738864896, 39.74026448960319]) diff --git a/spec/urbanopt/geojson/geo_file_spec.rb b/spec/urbanopt/geojson/geo_file_spec.rb index ca59c49..70c40e1 100644 --- a/spec/urbanopt/geojson/geo_file_spec.rb +++ b/spec/urbanopt/geojson/geo_file_spec.rb @@ -6,14 +6,11 @@ require_relative '../../spec_helper' RSpec.describe URBANopt::GeoJSON::GeoFile do - before(:each) do - @spec_files_dir = File.join(File.dirname(__FILE__), '..', '..', 'files') - end + spec_files_dir = Pathname(__FILE__).dirname.parent.parent / 'files' + schema_dir = Pathname(__FILE__).dirname.parent.parent.parent / 'lib' / 'urbanopt' / 'geojson' / 'schema' it 'gets feature, given a feature_id' do - geofile = URBANopt::GeoJSON::GeoFile.from_file( - File.join(@spec_files_dir, 'nrel_stm_footprints.geojson') - ) + geofile = URBANopt::GeoJSON::GeoFile.from_file(spec_files_dir / 'nrel_stm_footprints.geojson') feature = geofile.get_feature_by_id('59a9ce2b42f7d007c059d306') expect(feature.feature_json[:type]).to eq('Feature') @@ -23,9 +20,7 @@ end it 'gets feature, given a feature_id geojson example' do - geofile = URBANopt::GeoJSON::GeoFile.from_file( - File.join(@spec_files_dir, 'example_project_combined.json') - ) + geofile = URBANopt::GeoJSON::GeoFile.from_file(spec_files_dir / 'example_project_combined.json') feature = geofile.get_feature_by_id('1') expect(feature.feature_json[:type]).to eq('Feature') @@ -33,11 +28,11 @@ end it 'validate geojson file' do - geojson_file = File.open(File.join(@spec_files_dir, 'nrel_stm_footprints.geojson')) do |f| + geojson_file = File.open(spec_files_dir / 'nrel_stm_footprints.geojson') do |f| result = JSON.parse(f.read, symbolize_names: true) end - schema = File.open(File.dirname(__FILE__) + '/../../../lib/urbanopt/geojson/schema/geojson_schema.json') do |f| + schema = File.open(schema_dir / 'geojson_schema.json') do |f| result = JSON.parse(f.read, symbolize_names: true) end @@ -47,11 +42,11 @@ end it 'validate geojson file with ground heat exchanger' do - geojson_file = File.open(File.join(@spec_files_dir, 'example_project_combine_GHE.json')) do |f| + geojson_file = File.open(spec_files_dir / 'example_project_combine_GHE.json') do |f| result = JSON.parse(f.read, symbolize_names: true) end - schema = File.open(File.dirname(__FILE__) + '/../../../lib/urbanopt/geojson/schema/geojson_schema.json') do |f| + schema = File.open(schema_dir / 'geojson_schema.json') do |f| result = JSON.parse(f.read, symbolize_names: true) end @@ -60,12 +55,12 @@ expect(geojson_errors).to be_empty end - it 'validate geojson file with two ground heat exchangers_1' do - geojson_file = File.open(File.join(@spec_files_dir, 'example_project_combine_GHE_2.json')) do |f| + it 'validate geojson file with two ground heat exchangers' do + geojson_file = File.open(spec_files_dir / 'example_project_combine_GHE_2.json') do |f| result = JSON.parse(f.read, symbolize_names: true) end - schema = File.open(File.dirname(__FILE__) + '/../../../lib/urbanopt/geojson/schema/geojson_schema.json') do |f| + schema = File.open(schema_dir / 'geojson_schema.json') do |f| result = JSON.parse(f.read, symbolize_names: true) end @@ -90,36 +85,37 @@ it 'raise error' do - geojson_file = File.open(File.join(@spec_files_dir, 'invalid.geojson')) do |f| + geojson_file = File.open(spec_files_dir / 'invalid.geojson') do |f| result = JSON.parse(f.read, symbolize_names: true) end - schema = File.open(File.dirname(__FILE__) + '/../../../lib/urbanopt/geojson/schema/geojson_schema.json') do |f| + schema = File.open(schema_dir / 'geojson_schema.json') do |f| result = JSON.parse(f.read, symbolize_names: true) end geojson_errors = URBANopt::GeoJSON::GeoFile.validate(schema, geojson_file) - expect(geojson_errors).not_to be_nil + expect(geojson_errors).not_to be_empty + end + + it 'fails validation if missing a required property' do + expect { URBANopt::GeoJSON::GeoFile.from_file(spec_files_dir / 'id_6_missing_number_of_stories.json') } + .to raise_error(RuntimeError) end it 'raise error for bad emissions value' do - geojson_file = File.open(File.join(@spec_files_dir, 'invalid_emissions.geojson')) do |f| + geojson_file = File.open(spec_files_dir / 'invalid_emissions.geojson') do |f| result = JSON.parse(f.read, symbolize_names: true) end - schema = File.open(File.dirname(__FILE__) + '/../../../lib/urbanopt/geojson/schema/geojson_schema.json') do |f| + schema = File.open(schema_dir / 'geojson_schema.json') do |f| result = JSON.parse(f.read, symbolize_names: true) end geojson_errors = URBANopt::GeoJSON::GeoFile.validate(schema, geojson_file) expect(geojson_errors).to be_empty - # validate one feature (and project hash) - this should fail - expect { geofile = URBANopt::GeoJSON::GeoFile.from_file( - File.join(@spec_files_dir, 'invalid_emissions.geojson') - ) }.to raise_error(RuntimeError) - + # validate one feature (and project hash) - this should raise an error + expect { URBANopt::GeoJSON::GeoFile.from_file(spec_files_dir / 'invalid_emissions.geojson') }.to raise_error(RuntimeError) end - end