-
Notifications
You must be signed in to change notification settings - Fork 0
increase parser coverage #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,15 @@ | ||
| [CaseData] | ||
| git-tree-sha1 = "edcb5940e84a802a86ad4f2223214d33121ac044" | ||
| lazy = true | ||
|
|
||
| [[CaseData.download]] | ||
| url = "https://github.com/NREL-Sienna/PowerSystemsTestData/archive/refs/tags/4.0.2.tar.gz" | ||
| sha256 = "c844aba2ce37c1cc1bb4c496c809607f4ddb310cb76a5fdc266bf6a1345f2b51" | ||
|
|
||
| [rts] | ||
| git-tree-sha1 = "5098f357bad765bfefcff58f080818863ca776bd" | ||
| git-tree-sha1 = "c257b2c37b981f261fdc328b0fb9b96436a96537" | ||
| lazy = true | ||
|
|
||
| [[rts.download]] | ||
| url = "https://github.com/GridMod/RTS-GMLC/archive/refs/tags/v0.2.2.tar.gz" | ||
| sha256 = "f7a816f2390b96d44fa931c2790e2ec5ef81d0deb503c4c719b25ec1b585e2c2" | ||
| url = "https://github.com/GridMod/RTS-GMLC/archive/refs/tags/v0.2.3.tar.gz" | ||
| sha256 = "993429b8dc5f096e62479ca3b8551d52a53941322b452c825d12881cda915eae" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,16 +1,12 @@ | ||
| [deps] | ||
| Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595" | ||
| DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8" | ||
| Dates = "ade2ca70-3891-5945-98fb-dc099432e06a" | ||
| DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0" | ||
| InfrastructureSystems = "2cd47ed4-ca9b-11e9-27f2-ab636a7671f1" | ||
| LazyArtifacts = "4af54fe1-eca0-43a8-85a7-787d91b784e3" | ||
| LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" | ||
| Logging = "56ddb016-857b-54e1-b83d-db4d58db5568" | ||
| PowerSystemCaseBuilder = "f00506e0-b84f-492a-93c2-c0a9afc4364e" | ||
| PowerSystems = "bcd98974-b02a-5e2f-9ee0-a103f5c450dd" | ||
| PowerTableDataParser = "2b750c0e-0bff-11f1-9200-1befd75df6be" | ||
| SQLite = "0aa819cd-b072-5ff4-a722-6bc24af294d9" | ||
| Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" | ||
| YAML = "ddb6d928-2868-570f-bddf-ab3f9cf99eb6" | ||
|
|
||
| [compat] | ||
| julia = "^1.6" | ||
| julia = "^1.10" |
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| import LazyArtifacts | ||
|
|
||
| const RTS_SRC = joinpath( | ||
| LazyArtifacts.artifact"rts", | ||
| "RTS-GMLC-0.2.3", | ||
| "RTS_Data", | ||
| "SourceData", | ||
| ) | ||
| const RTS_DESCRIPTORS = joinpath(@__DIR__, "data", "rts", "user_descriptors.yaml") | ||
|
|
||
| const BUS118_SRC = joinpath( | ||
| LazyArtifacts.artifact"CaseData", | ||
| "PowerSystemsTestData-4.0.2", | ||
| "118-Bus", | ||
| ) | ||
| const BUS118_DESCRIPTORS = joinpath(@__DIR__, "data", "118_bus", "user_descriptors.yaml") | ||
| const BUS118_GEN_MAPPING = joinpath(@__DIR__, "data", "118_bus", "generator_mapping.yaml") | ||
|
|
||
| load_rts_data() = PDP.PowerSystemTableData(RTS_SRC, 100.0, RTS_DESCRIPTORS) | ||
|
|
||
| # 118-Bus CSVs ship with PLEXOS-style filenames (Buses.csv / Lines.csv) but the | ||
| # parser keys off lowercase stems (bus / branch / gen). Stage them in a tmpdir. | ||
| function load_118_bus_data() | ||
| tmpdir = mktempdir() | ||
| cp(joinpath(BUS118_SRC, "Buses.csv"), joinpath(tmpdir, "bus.csv")) | ||
| cp(joinpath(BUS118_SRC, "Lines.csv"), joinpath(tmpdir, "branch.csv")) | ||
| cp(joinpath(BUS118_SRC, "gen.csv"), joinpath(tmpdir, "gen.csv")) | ||
| return PDP.PowerSystemTableData( | ||
| tmpdir, | ||
| 100.0, | ||
| BUS118_DESCRIPTORS; | ||
| generator_mapping_file = BUS118_GEN_MAPPING, | ||
| ) | ||
| end | ||
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| @testset "get_generator_mapping" begin | ||
| # happy path — package default | ||
| mappings = PDP.get_generator_mapping(PDP.GENERATOR_MAPPING_FILE_CDM) | ||
| @test mappings isa Dict{NamedTuple, String} | ||
| @test !isempty(mappings) | ||
|
|
||
| # GenericBattery rename → EnergyReservoirStorage with a warning | ||
| tmp = tempname() * ".yaml" | ||
| write( | ||
| tmp, | ||
| """ | ||
| GenericBattery: | ||
| - {fuel: Battery, type: BA} | ||
| """, | ||
| ) | ||
| renamed = @test_logs (:warn,) PDP.get_generator_mapping(tmp) | ||
| @test renamed[(fuel = "Battery", unit_type = "BA")] == "EnergyReservoirStorage" | ||
|
|
||
| # duplicate (fuel, type) across two generator entries → error | ||
| dup = tempname() * ".yaml" | ||
| write( | ||
| dup, | ||
| """ | ||
| ThermalStandard: | ||
| - {fuel: NG, type: ST} | ||
| HydroDispatch: | ||
| - {fuel: NG, type: ST} | ||
| """, | ||
| ) | ||
| @test_throws ErrorException PDP.get_generator_mapping(dup) | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| @testset "Directory constructor edge cases" begin | ||
| # Empty directory | ||
| empty_dir = mktempdir() | ||
| @test_throws ErrorException PDP.PowerSystemTableData( | ||
| empty_dir, | ||
| 100.0, | ||
| BUS118_DESCRIPTORS, | ||
| ) | ||
|
|
||
| # Directory with only non-CSV / non-folder files | ||
| no_csv = mktempdir() | ||
| write(joinpath(no_csv, "README.md"), "nothing here") | ||
| @test_throws ErrorException PDP.PowerSystemTableData( | ||
| no_csv, | ||
| 100.0, | ||
| BUS118_DESCRIPTORS, | ||
| ) | ||
|
|
||
| # Bad generator mapping path → rethrown (parser also @errors, expected) | ||
| staging = mktempdir() | ||
| cp(joinpath(BUS118_SRC, "Buses.csv"), joinpath(staging, "bus.csv")) | ||
| cp(joinpath(BUS118_SRC, "Lines.csv"), joinpath(staging, "branch.csv")) | ||
| cp(joinpath(BUS118_SRC, "gen.csv"), joinpath(staging, "gen.csv")) | ||
| @test_logs (:error,) match_mode = :any begin | ||
| @test_throws Exception PDP.PowerSystemTableData( | ||
| staging, | ||
| 100.0, | ||
| BUS118_DESCRIPTORS; | ||
| generator_mapping_file = joinpath(staging, "does_not_exist.yaml"), | ||
| ) | ||
| end | ||
| end | ||
|
|
||
| @testset "Dict constructor: missing keys" begin | ||
| descriptors = Dict{Symbol, Vector}() | ||
| user_descriptors = Dict{Symbol, Vector}() | ||
| gen_mapping = Dict{NamedTuple, String}() | ||
|
|
||
| # Missing 'bus' key | ||
| @test_throws IS.DataFormatError PDP.PowerSystemTableData( | ||
| Dict{String, Any}(), | ||
| mktempdir(), | ||
| user_descriptors, | ||
| descriptors, | ||
| gen_mapping, | ||
| ) | ||
|
|
||
| # Missing 'base_power' → warns and falls back to DEFAULT_BASE_MVA | ||
| bus_df = DataFrames.DataFrame(; bus_id = [1]) | ||
| data = Dict{String, Any}("bus" => bus_df) | ||
| sys_data = @test_logs (:warn,) match_mode = :any PDP.PowerSystemTableData( | ||
| data, | ||
| mktempdir(), | ||
| user_descriptors, | ||
| descriptors, | ||
| gen_mapping, | ||
| ) | ||
| @test sys_data.base_power == PDP.DEFAULT_BASE_MVA | ||
| @test haskey(sys_data.category_to_df, :BUS) | ||
| end | ||
|
|
||
| @testset "Timeseries metadata fallback" begin | ||
| descriptors = Dict{Symbol, Vector}() | ||
| user_descriptors = Dict{Symbol, Vector}() | ||
| gen_mapping = Dict{NamedTuple, String}() | ||
| bus_df = DataFrames.DataFrame(; bus_id = [1]) | ||
| data() = Dict{String, Any}("bus" => bus_df, "base_power" => 100.0) | ||
|
|
||
| # .json present | ||
| d_json = mktempdir() | ||
| write(joinpath(d_json, "timeseries_pointers.json"), "{}") | ||
| sd_json = PDP.PowerSystemTableData( | ||
| data(), | ||
| d_json, | ||
| user_descriptors, | ||
| descriptors, | ||
| gen_mapping, | ||
| ) | ||
| @test endswith(sd_json.timeseries_metadata_file, ".json") | ||
|
|
||
| # .csv present (no .json) | ||
| d_csv = mktempdir() | ||
| write(joinpath(d_csv, "timeseries_pointers.csv"), "") | ||
| sd_csv = PDP.PowerSystemTableData( | ||
| data(), | ||
| d_csv, | ||
| user_descriptors, | ||
| descriptors, | ||
| gen_mapping, | ||
| ) | ||
| @test endswith(sd_csv.timeseries_metadata_file, ".csv") | ||
|
|
||
| # Neither present | ||
| d_none = mktempdir() | ||
| sd_none = PDP.PowerSystemTableData( | ||
| data(), | ||
| d_none, | ||
| user_descriptors, | ||
| descriptors, | ||
| gen_mapping, | ||
| ) | ||
| @test sd_none.timeseries_metadata_file === nothing | ||
| end | ||
|
|
||
| @testset "_read_config_file: reserves rename + Symbol uppercasing" begin | ||
| tmp = tempname() * ".yaml" | ||
| write( | ||
| tmp, | ||
| """ | ||
| bus: | ||
| - {custom_name: Number, name: bus_id} | ||
| reserves: | ||
| - {custom_name: R, name: name} | ||
| """, | ||
| ) | ||
| cfg = PDP._read_config_file(tmp) | ||
| @test haskey(cfg, :BUS) | ||
| @test haskey(cfg, :RESERVE) | ||
| @test !haskey(cfg, :RESERVES) | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| @testset "get_enum_value" begin | ||
| @test PDP.get_enum_value(PDP.InputCategory, "bus") == PDP.InputCategory.BUS | ||
| # case-insensitive | ||
| @test PDP.get_enum_value(PDP.InputCategory, "BUS") == PDP.InputCategory.BUS | ||
| @test PDP.get_enum_value(PDP.InputCategory, "Branch") == PDP.InputCategory.BRANCH | ||
|
|
||
| # invalid enum type — anything not in PDP.ENUM_MAPPINGS | ||
| @test_throws ArgumentError PDP.get_enum_value(Int, "bus") | ||
|
|
||
| # invalid value within a known enum | ||
| @test_throws ArgumentError PDP.get_enum_value(PDP.InputCategory, "not_a_category") | ||
| end |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RTS_DESCRIPTORS,BUS118_DESCRIPTORS, andBUS118_GEN_MAPPINGpoint attest/data/...paths, but there is notest/datadirectory in this PR/repo, so these tests will fail at runtime when attempting to open the YAML files. Add the missing YAML files undertest/data/..., or change these constants to reference descriptor/mapping files that are guaranteed to exist (e.g., shipped in the artifacts you download, or generated in the tests viamktempdir()/tempname()).