-
Notifications
You must be signed in to change notification settings - Fork 0
Upgrade to use glossarist-ruby 2.11.3 #21
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
Show all changes
4 commits
Select commit
Hold shift + click to select a range
5cb8bf4
fix: upgrade to glossarist 2.11.3 and repair data-backed model constr…
HassanAkbar 07580d3
fix: run standalone-load spec without a shell so it passes on Windows
HassanAkbar 797f231
refactor: address review — reuse detailed_definitions and anchor subp…
HassanAkbar 57762c8
resolve copilot comments
HassanAkbar 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
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
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,17 +1,131 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| require "open3" | ||
| require "rbconfig" | ||
| require "tmpdir" | ||
| require "yaml" | ||
|
|
||
| RSpec.describe Termium do | ||
| # let(:concept_folder) { "concept_collection_v2" } | ||
| # let(:concept_files) { Dir.glob(File.join(fixtures_path(concept_folder), "concept", "*.{yaml,yml}")) } | ||
| # let(:localized_concepts_folder) { File.join(fixtures_path(concept_folder), "localized_concept") } | ||
|
|
||
| let(:termium_extract_file) { fixtures_path("Characters.xml") } | ||
| let(:glossarist_output_file) { fixtures_path("Characters-Glossarist") } | ||
|
|
||
| it "does something useful" do | ||
| termium_extract = Termium::Extract.from_xml(File.read(termium_extract_file)) | ||
| glossarist_col = termium_extract.to_concept | ||
| FileUtils.mkdir_p(glossarist_output_file) | ||
| glossarist_col.save_to_files(glossarist_output_file) | ||
| let(:extract) do | ||
| Termium::Extract.from_xml(File.read(fixtures_path("Characters.xml"))) | ||
| end | ||
|
|
||
| # The TERMIUM entry used throughout: identificationNumber 2123225, which has | ||
| # both an EN and a FR languageModule. | ||
| let(:identification_number) { "2123225" } | ||
| let(:core) do | ||
| extract.core.find { |c| c.identification_number == identification_number } | ||
| end | ||
|
|
||
| def save_to_tmp(options = {}) | ||
| Dir.mktmpdir do |dir| | ||
| extract.to_concept(options).save_to_files(dir) | ||
| yield( | ||
| Dir.glob("#{dir}/concept/*.yaml").map { |f| YAML.load_file(f) }, | ||
| Dir.glob("#{dir}/localized_concept/*.yaml").map { |f| YAML.load_file(f) } | ||
| ) | ||
|
HassanAkbar marked this conversation as resolved.
|
||
| end | ||
| end | ||
|
|
||
| describe "#to_concept" do | ||
| it "carries the TERMIUM identification number as the concept identifier" do | ||
| doc = core.to_concept.to_yaml_hash | ||
|
|
||
| expect(doc.dig("data", "identifier")).to eq(identification_number) | ||
| end | ||
|
|
||
| it "registers one localization per language, keyed by language code" do | ||
| expect(core.to_concept.localizations.keys).to contain_exactly("eng", "fre") | ||
| end | ||
|
|
||
| it "cross-references every localization from the concept" do | ||
| doc = core.to_concept.to_yaml_hash | ||
|
|
||
| expect(doc.dig("data", "localized_concepts").keys) | ||
| .to contain_exactly("eng", "fre") | ||
| end | ||
|
|
||
| it "gives each localization a distinct uuid" do | ||
| map = core.to_concept.to_yaml_hash.dig("data", "localized_concepts") | ||
|
|
||
| expect(map["eng"]).not_to eq(map["fre"]) | ||
| end | ||
|
|
||
| it "populates the localized concept from the TERMIUM entry" do | ||
| data = core.to_concept.localization("eng").to_yaml_hash["data"] | ||
|
|
||
| aggregate_failures do | ||
| expect(data["language_code"]).to eq("eng") | ||
| expect(data["terms"].map { |t| t["designation"] }) | ||
| .to include("average information rate") | ||
| expect(data.dig("definition", 0, "content")) | ||
| .to start_with("quotient of the character mean entropy") | ||
| end | ||
| end | ||
|
|
||
| it "wraps notes as detailed definitions" do | ||
| data = core.to_concept.localization("eng").to_yaml_hash["data"] | ||
|
|
||
| expect(data["notes"].map { |n| n["content"] }) | ||
| .to include(a_string_including("average information rate may be expressed")) | ||
| end | ||
| end | ||
|
|
||
| describe "#to_concept with date_accepted" do | ||
| let(:date_accepted) { "2024-01-15" } | ||
|
|
||
| it "records the accepted date on the concept" do | ||
| save_to_tmp(date_accepted: date_accepted) do |concepts, _localized| | ||
| expect(concepts) | ||
| .to all(include("date_accepted" => a_string_starting_with(date_accepted))) | ||
| end | ||
| end | ||
|
|
||
| it "records the accepted date on every localized concept" do | ||
| save_to_tmp(date_accepted: date_accepted) do |_concepts, localized| | ||
| expect(localized) | ||
| .to all(include("date_accepted" => a_string_starting_with(date_accepted))) | ||
| end | ||
| end | ||
| end | ||
|
|
||
| # glossarist's save_to_files calls FileUtils without requiring it, so requiring | ||
| # "termium" must be sufficient on its own. This has to run in a clean subprocess: | ||
| # in-process the spec's own `require "tmpdir"` loads fileutils and masks the bug, | ||
| # which is why it reaches production while the suite stays green. | ||
| describe "loading termium standalone" do | ||
| # Passes argv directly rather than through a shell: POSIX quoting would | ||
| # reach cmd.exe verbatim on Windows and mangle the script. | ||
| def save_in_clean_process(dir) | ||
| root = File.expand_path("..", __dir__) | ||
| script = <<~RUBY | ||
| require "termium" | ||
| xml = File.read(#{File.join(root, 'spec/fixtures/Characters.xml').inspect}) | ||
| Termium::Extract.from_xml(xml).to_concept.save_to_files(#{dir.inspect}) | ||
| RUBY | ||
| Open3.capture2e(RbConfig.ruby, "-I#{File.join(root, 'lib')}", "-e", script, | ||
| chdir: root) | ||
| end | ||
|
|
||
| it "can save a dataset without the caller requiring fileutils" do | ||
| output, status = Dir.mktmpdir { |dir| save_in_clean_process(dir) } | ||
|
|
||
| aggregate_failures do | ||
| expect(output).not_to include("NameError") | ||
| expect(status).to be_success | ||
| end | ||
| end | ||
| end | ||
|
|
||
| describe "#save_to_files" do | ||
| it "writes one concept per entry and one localized concept per language" do | ||
| save_to_tmp do |concepts, localized| | ||
| aggregate_failures do | ||
| expect(concepts.size).to eq(extract.core.size) | ||
| expect(localized.size) | ||
| .to eq(extract.core.sum { |c| c.language_module.size }) | ||
| end | ||
| end | ||
| end | ||
| end | ||
| 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
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.
Uh oh!
There was an error while loading. Please reload this page.