data_gov_au.rb 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG +15 -0
- data/README.md +111 -6
- data/TODO +3 -4
- data/data_gov_au.rb.gemspec +3 -0
- data/exe/data_gov_au +53 -3
- data/lib/DataGovAu/ABR/Error.rb +4 -1
- data/lib/DataGovAu/ABR/Extract.rb +48 -0
- data/lib/DataGovAu/ABR/Fetch.rb +5 -4
- data/lib/DataGovAu/ABR/Parser.rb +181 -0
- data/lib/DataGovAu/ABR/Release.rb +7 -0
- data/lib/DataGovAu/ABR.rb +2 -0
- data/lib/DataGovAu/VERSION.rb +1 -1
- data/lib/Thoran/Array/NaturalSort/natural_sort.rb +27 -0
- data/lib/Thoran/String/NaturalComparison/natural_comparison.rb +37 -0
- data/test/DataGovAu/ABR/Extract_test.rb +90 -0
- data/test/DataGovAu/ABR/Fetch_test.rb +10 -0
- data/test/DataGovAu/ABR/Parser_test.rb +194 -0
- data/test/Thoran/Array/NaturalSort/natural_sort_test.rb +21 -0
- data/test/Thoran/String/NaturalComparison/natural_comparison_test.rb +35 -0
- data/test/exe/data_gov_au_test.rb +94 -0
- data/test/fixtures/20261020Public01.xml +225 -0
- data/test/helper.rb +20 -0
- metadata +167 -118
data/lib/DataGovAu/VERSION.rb
CHANGED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# Thoran/Array/NaturalSort/natural_sort.rb
|
|
2
|
+
# Thoran::Array::NaturalSort#natural_sort
|
|
3
|
+
|
|
4
|
+
# 20261101
|
|
5
|
+
# 0.1.0
|
|
6
|
+
|
|
7
|
+
# Description: Sorts an array of strings by the numbers in them rather than by their characters, so that 2 comes before 10.
|
|
8
|
+
|
|
9
|
+
# Changes:
|
|
10
|
+
# 1. + Thoran namespace.
|
|
11
|
+
|
|
12
|
+
require_relative '../../String/NaturalComparison/natural_comparison'
|
|
13
|
+
|
|
14
|
+
module Thoran
|
|
15
|
+
module Array
|
|
16
|
+
module NaturalSort
|
|
17
|
+
|
|
18
|
+
def natural_sort(case_insensitive = nil)
|
|
19
|
+
sort{|s1, s2| s1.natural_comparison(s2, case_insensitive)}
|
|
20
|
+
end
|
|
21
|
+
alias_method :natsort, :natural_sort
|
|
22
|
+
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
Array.send(:include, Thoran::Array::NaturalSort)
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# Thoran/String/NaturalComparison/natural_comparison.rb
|
|
2
|
+
# Thoran::String::NaturalComparison#natural_comparison
|
|
3
|
+
|
|
4
|
+
# 20261101
|
|
5
|
+
# 0.1.0
|
|
6
|
+
|
|
7
|
+
# Description: Compares two strings by the numbers in them rather than by their characters, so that 2 comes before 10.
|
|
8
|
+
|
|
9
|
+
# Changes:
|
|
10
|
+
# 1. + Thoran namespace.
|
|
11
|
+
|
|
12
|
+
module Thoran
|
|
13
|
+
module String
|
|
14
|
+
module NaturalComparison
|
|
15
|
+
|
|
16
|
+
def natural_comparison(s, case_insensitive = nil)
|
|
17
|
+
s1, s2 = (case_insensitive ? self.downcase : self), (case_insensitive ? s.downcase : s)
|
|
18
|
+
m1, m2 = s1.match(/\d+/), s2.match(/\d+/)
|
|
19
|
+
if m1.nil? || m2.nil? # then compare as per normal since one or more of the strings doesn't have numbers.
|
|
20
|
+
s1 <=> s2
|
|
21
|
+
elsif m1.pre_match == m2.pre_match # then compare the remainder of the string, since the pre_matches are the same.
|
|
22
|
+
if m1[0] == m2[0]
|
|
23
|
+
m1.post_match.natural_comparison(m2.post_match)
|
|
24
|
+
else
|
|
25
|
+
m1[0].to_i <=> m2[0].to_i
|
|
26
|
+
end
|
|
27
|
+
else # compare the pre_matches, since even though there are numbers the pre_matches are different anyway.
|
|
28
|
+
m1.pre_match <=> m2.pre_match
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
alias_method :natcmp, :natural_comparison
|
|
32
|
+
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
String.send(:include, Thoran::String::NaturalComparison)
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
# test/DataGovAu/ABR/Extract_test.rb
|
|
2
|
+
|
|
3
|
+
require_relative '../../helper'
|
|
4
|
+
|
|
5
|
+
describe DataGovAu::ABR::Extract do
|
|
6
|
+
describe "reading out of the zips" do
|
|
7
|
+
it "gives up the records of a zipped file" do
|
|
8
|
+
Dir.mktmpdir do |directory|
|
|
9
|
+
release = release_holding(directory, Date.new(2026, 10, 28))
|
|
10
|
+
_(DataGovAu::ABR::Extract.new(release).each_record.to_a.length).must_equal 9
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
it "yields each file as its own parser" do
|
|
15
|
+
Dir.mktmpdir do |directory|
|
|
16
|
+
release = release_holding(directory, Date.new(2026, 10, 28), {
|
|
17
|
+
'public_split_1_10.zip' => ['20261028_Public01.xml', '20261028_Public02.xml'],
|
|
18
|
+
})
|
|
19
|
+
reached = []
|
|
20
|
+
DataGovAu::ABR::Extract.new(release).each_file{|member, parser| reached << [member, parser.each_record{}.records_parsed]}
|
|
21
|
+
_(reached).must_equal [['20261028_Public01.xml', 9], ['20261028_Public02.xml', 9]]
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
it "reads across both zips of a release" do
|
|
26
|
+
Dir.mktmpdir do |directory|
|
|
27
|
+
release = release_holding(directory, Date.new(2026, 10, 28), {
|
|
28
|
+
'public_split_1_10.zip' => ['20261028_Public01.xml'],
|
|
29
|
+
'public_split_11_20.zip' => ['20261028_Public11.xml'],
|
|
30
|
+
})
|
|
31
|
+
_(DataGovAu::ABR::Extract.new(release).each_record.to_a.length).must_equal 18
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# The records are one stream sorted by ABN and the zips cut across it, so public_split_11_20 sorts before public_split_1_10 while holding the later half. Taking the order from the zips' own names would read the halves back to front.
|
|
37
|
+
describe "the order it reads in" do
|
|
38
|
+
it "takes its order from the sequence numbers the files carry, not from the zips' names" do
|
|
39
|
+
Dir.mktmpdir do |directory|
|
|
40
|
+
release = release_holding(directory, Date.new(2026, 10, 28), {
|
|
41
|
+
'public_split_11_20.zip' => ['20261028_Public11.xml', '20261028_Public20.xml'],
|
|
42
|
+
'public_split_1_10.zip' => ['20261028_Public01.xml', '20261028_Public10.xml'],
|
|
43
|
+
})
|
|
44
|
+
names = DataGovAu::ABR::Extract.new(release).members.collect{|_path, name| name}
|
|
45
|
+
_(names).must_equal [
|
|
46
|
+
'20261028_Public01.xml',
|
|
47
|
+
'20261028_Public10.xml',
|
|
48
|
+
'20261028_Public11.xml',
|
|
49
|
+
'20261028_Public20.xml',
|
|
50
|
+
]
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
# The naming has varied once already, the files having been yyyymmddPublicNN.xml before. Were the padding dropped, the characters alone would put file 2 after file 19 and the records would stop being one ascending run without anything in them saying so.
|
|
55
|
+
it "takes it from the numbers rather than the padding" do
|
|
56
|
+
Dir.mktmpdir do |directory|
|
|
57
|
+
release = release_holding(directory, Date.new(2026, 10, 28), {
|
|
58
|
+
'public_split_11_20.zip' => ['20261028_Public11.xml', '20261028_Public2.xml'],
|
|
59
|
+
'public_split_1_10.zip' => ['20261028_Public1.xml', '20261028_Public10.xml'],
|
|
60
|
+
})
|
|
61
|
+
names = DataGovAu::ABR::Extract.new(release).members.collect{|_path, name| name}
|
|
62
|
+
_(names).must_equal [
|
|
63
|
+
'20261028_Public1.xml',
|
|
64
|
+
'20261028_Public2.xml',
|
|
65
|
+
'20261028_Public10.xml',
|
|
66
|
+
'20261028_Public11.xml',
|
|
67
|
+
]
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
describe "a release with nothing in it" do
|
|
73
|
+
it "stops rather than reporting an empty extract" do
|
|
74
|
+
Dir.mktmpdir do |directory|
|
|
75
|
+
release = DataGovAu::ABR::Release.new(config_in(directory), Date.new(2026, 10, 28))
|
|
76
|
+
release.create_directory
|
|
77
|
+
_(->{DataGovAu::ABR::Extract.new(release).each_file{}}).must_raise DataGovAu::ABR::NothingToParse
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
describe "without a block" do
|
|
83
|
+
it "gives back an enumerator" do
|
|
84
|
+
Dir.mktmpdir do |directory|
|
|
85
|
+
release = release_holding(directory, Date.new(2026, 10, 28))
|
|
86
|
+
_(DataGovAu::ABR::Extract.new(release).each_record).must_be_kind_of Enumerator
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
end
|
|
@@ -15,6 +15,16 @@ describe DataGovAu::ABR::Fetch do
|
|
|
15
15
|
end
|
|
16
16
|
end
|
|
17
17
|
|
|
18
|
+
# A release is named from the first of these, so where they fall matters: by their characters alone, Part 10 would come between Part 1 and Part 2.
|
|
19
|
+
it "orders the halves by the numbers in their names, not by their characters" do
|
|
20
|
+
Dir.mktmpdir do |directory|
|
|
21
|
+
resources = default_resources + [extract_resource('ABN Bulk Extract Part 10', 'public_split_91_100.zip', '2026-10-27T21:39:23', 40)]
|
|
22
|
+
stub_catalogue({'success' => true, 'result' => package(resources: resources)})
|
|
23
|
+
names = DataGovAu::ABR::Fetch.new(config_in(directory)).extract_resources.collect(&:name)
|
|
24
|
+
_(names).must_equal ['ABN Bulk Extract Part 1', 'ABN Bulk Extract Part 2 ', 'ABN Bulk Extract Part 10']
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
18
28
|
it "takes the schema and readme as supporting resources" do
|
|
19
29
|
Dir.mktmpdir do |directory|
|
|
20
30
|
formats = DataGovAu::ABR::Fetch.new(config_in(directory)).supporting_resources.collect(&:format)
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
# test/DataGovAu/ABR/Parser_test.rb
|
|
2
|
+
|
|
3
|
+
require_relative '../../helper'
|
|
4
|
+
|
|
5
|
+
describe DataGovAu::ABR::Parser do
|
|
6
|
+
describe "what the file says of itself" do
|
|
7
|
+
it "reports the sequence number, the record count and the extract time" do
|
|
8
|
+
parser = File.open(fixture_path('20261020Public01.xml'), 'rb'){|file| DataGovAu::ABR::Parser.new(file).each_record{}}
|
|
9
|
+
_(parser.file_sequence_number).must_equal 1
|
|
10
|
+
_(parser.record_count).must_equal 9
|
|
11
|
+
_(parser.extract_time).must_equal '2026-10-20T03:17:42'
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
it "reports the error the file names, none where it was written out whole" do
|
|
15
|
+
parser = File.open(fixture_path('20261020Public01.xml'), 'rb'){|file| DataGovAu::ABR::Parser.new(file).each_record{}}
|
|
16
|
+
_(parser.error).must_equal 'none'
|
|
17
|
+
_(parser.error_free?).must_equal true
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
# A file which gave up fewer records than it promised has been truncated, and is worth knowing about rather than passing as a smaller week.
|
|
21
|
+
it "counts itself whole where it gave up as many records as it promised" do
|
|
22
|
+
parser = File.open(fixture_path('20261020Public01.xml'), 'rb'){|file| DataGovAu::ABR::Parser.new(file).each_record{}}
|
|
23
|
+
_(parser.records_parsed).must_equal 9
|
|
24
|
+
_(parser.whole?).must_equal true
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
it "counts itself short where the file was cut off" do
|
|
28
|
+
Dir.mktmpdir do |directory|
|
|
29
|
+
path = File.join(directory, 'cut.xml')
|
|
30
|
+
whole = File.read(fixture_path('20261020Public01.xml'))
|
|
31
|
+
File.write(path, whole[0, whole.rindex('<ABR ')] + '</Transfer>')
|
|
32
|
+
parser = File.open(path, 'rb'){|file| DataGovAu::ABR::Parser.new(file).each_record{}}
|
|
33
|
+
_(parser.records_parsed).must_equal 8
|
|
34
|
+
_(parser.record_count).must_equal 9
|
|
35
|
+
_(parser.whole?).must_equal false
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
it "counts itself short where the file reports an error, every record given up or not" do
|
|
40
|
+
Dir.mktmpdir do |directory|
|
|
41
|
+
path = File.join(directory, 'erred.xml')
|
|
42
|
+
File.write(path, File.read(fixture_path('20261020Public01.xml')).sub('<Transfer error="none">', '<Transfer error="partial">'))
|
|
43
|
+
parser = File.open(path, 'rb'){|file| DataGovAu::ABR::Parser.new(file).each_record{}}
|
|
44
|
+
_(parser.records_parsed).must_equal 9
|
|
45
|
+
_(parser.error).must_equal 'partial'
|
|
46
|
+
_(parser.whole?).must_equal false
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
it "counts itself short where the file names no error at all" do
|
|
51
|
+
Dir.mktmpdir do |directory|
|
|
52
|
+
path = File.join(directory, 'unnamed.xml')
|
|
53
|
+
File.write(path, File.read(fixture_path('20261020Public01.xml')).sub('<Transfer error="none">', '<Transfer>'))
|
|
54
|
+
parser = File.open(path, 'rb'){|file| DataGovAu::ABR::Parser.new(file).each_record{}}
|
|
55
|
+
_(parser.error).must_be_nil
|
|
56
|
+
_(parser.whole?).must_equal false
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
describe "the record it gives up" do
|
|
62
|
+
it "gives up every record in the file" do
|
|
63
|
+
_(fixture_records.length).must_equal 9
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
it "takes the ABN, its status and the date that status took effect" do
|
|
67
|
+
record = fixture_record('11111111111')
|
|
68
|
+
_(record[:abn_status]).must_equal 'ACT'
|
|
69
|
+
_(record[:abn_status_from_date]).must_equal '20261012'
|
|
70
|
+
_(record[:record_last_updated_date]).must_equal '20261013'
|
|
71
|
+
_(record[:replaced]).must_equal 'N'
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
it "takes the entity type as both code and text" do
|
|
75
|
+
record = fixture_record('55555555555')
|
|
76
|
+
_(record[:entity_type_code]).must_equal 'DTT'
|
|
77
|
+
_(record[:entity_type_text]).must_equal 'Discretionary Trading Trust'
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
it "takes the state and postcode of the main business location" do
|
|
81
|
+
record = fixture_record('44444444444')
|
|
82
|
+
_(record[:state]).must_equal 'NSW'
|
|
83
|
+
_(record[:postcode]).must_equal '2000'
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
it "takes the ASIC number along with the type it is given under" do
|
|
87
|
+
record = fixture_record('33333333333')
|
|
88
|
+
_(record[:asic_number]).must_equal '123456789'
|
|
89
|
+
_(record[:asic_number_type]).must_equal 'ACN'
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
it "takes a cancelled ABN as readily as a live one" do
|
|
93
|
+
_(fixture_record('66666666666')[:abn_status]).must_equal 'CAN'
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
# Every record the extract holds carries a GST element, those not registered among them, so its status says which of the three a record is rather than whether the element was there.
|
|
98
|
+
describe "GST" do
|
|
99
|
+
it "takes an active registration with the date it began" do
|
|
100
|
+
record = fixture_record('33333333333')
|
|
101
|
+
_(record[:gst_status]).must_equal 'ACT'
|
|
102
|
+
_(record[:gst_status_from_date]).must_equal '20261015'
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
it "takes a cancelled registration" do
|
|
106
|
+
_(fixture_record('66666666666')[:gst_status]).must_equal 'CAN'
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
it "takes no registration as the status it is given, NON" do
|
|
110
|
+
record = fixture_record('99999999999')
|
|
111
|
+
_(record[:gst_status]).must_equal 'NON'
|
|
112
|
+
_(record[:gst_status_from_date]).must_equal '19000101'
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
# The schema allows the element to be left off, which is not the same as a status of NON, so the two are not run together.
|
|
116
|
+
it "leaves the status unset where the element is absent" do
|
|
117
|
+
_(fixture_record('11111111111')[:gst_status]).must_be_nil
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
describe "the names it collects" do
|
|
122
|
+
it "takes a company's own name as a name of type MN" do
|
|
123
|
+
_(fixture_record('33333333333')[:names]).must_equal [{type: 'MN', text: 'SMITH PLUMBING PTY LTD'}]
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
# Joining the parts is a decision for whoever asks, so they are kept as they come.
|
|
127
|
+
it "takes an individual's name in its parts" do
|
|
128
|
+
_(fixture_record('22222222222')[:names].first).must_equal(
|
|
129
|
+
{type: 'LGL', title: 'MS', given_names: ['ANNE', 'MARIE'], family_name: 'NGUYEN'}
|
|
130
|
+
)
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
it "takes a family name standing on its own" do
|
|
134
|
+
_(fixture_record('99999999999')[:names]).must_equal [{type: 'LGL', family_name: 'TEOFILO'}]
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
it "takes business, trading and other names alongside the entity's own" do
|
|
138
|
+
types = fixture_record('88888888888')[:names].collect{|name| name[:type]}
|
|
139
|
+
_(types).must_equal ['MN', 'BN', 'TRD', 'OTN']
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
# The extract is full of ampersands, and a name carrying one encoded is worth nothing if it is read back encoded.
|
|
143
|
+
it "gives back a name with its entities decoded" do
|
|
144
|
+
_(fixture_record('88888888888')[:names].first[:text]).must_equal 'GEELONG COMMUNITY WORKS & TRAINING LIMITED'
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
it "keeps an apostrophe as it stands" do
|
|
148
|
+
trading = fixture_record('88888888888')[:names].detect{|name| name[:type] == 'TRD'}
|
|
149
|
+
_(trading[:text]).must_equal "GCW's Training"
|
|
150
|
+
end
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
# An entity's own endorsement and each named fund it runs come as DGR elements of the same name, the first carrying a status and no name and the second a name and no status. Running them together would lose which is which.
|
|
154
|
+
describe "deductible gift recipient entries" do
|
|
155
|
+
it "keeps the entity's own endorsement and each named fund apart" do
|
|
156
|
+
_(fixture_record('88888888888')[:dgr]).must_equal [
|
|
157
|
+
{from_date: '20190101', status: 'ACT', name: nil},
|
|
158
|
+
{from_date: '20200401', status: nil, name: 'GEELONG COMMUNITY WORKS PUBLIC FUND'},
|
|
159
|
+
]
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
it "gives no entries where there are none" do
|
|
163
|
+
_(fixture_record('11111111111')[:dgr]).must_equal []
|
|
164
|
+
end
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
# An element present and empty is not an element absent, and the extract has both: a blank state against no ASIC number at all.
|
|
168
|
+
describe "what is there and empty against what is not there" do
|
|
169
|
+
it "keeps a blank state and postcode as the blanks they are" do
|
|
170
|
+
record = fixture_record('99999999999')
|
|
171
|
+
_(record[:state]).must_equal ''
|
|
172
|
+
_(record[:postcode]).must_equal ''
|
|
173
|
+
end
|
|
174
|
+
|
|
175
|
+
it "leaves what the record does not carry unset" do
|
|
176
|
+
record = fixture_record('11111111111')
|
|
177
|
+
_(record[:asic_number]).must_be_nil
|
|
178
|
+
_(record[:asic_number_type]).must_be_nil
|
|
179
|
+
end
|
|
180
|
+
end
|
|
181
|
+
|
|
182
|
+
describe "the shape it gives up" do
|
|
183
|
+
# The storage stage writes a row per record, so every record carrying the same keys matters more than the keys being few.
|
|
184
|
+
it "gives every record the same keys" do
|
|
185
|
+
_(fixture_records.collect(&:keys).uniq.length).must_equal 1
|
|
186
|
+
end
|
|
187
|
+
|
|
188
|
+
it "gives back an enumerator where no block is given" do
|
|
189
|
+
File.open(fixture_path('20261020Public01.xml'), 'rb') do |file|
|
|
190
|
+
_(DataGovAu::ABR::Parser.new(file).each_record).must_be_kind_of Enumerator
|
|
191
|
+
end
|
|
192
|
+
end
|
|
193
|
+
end
|
|
194
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# test/Thoran/Array/NaturalSort/natural_sort_test.rb
|
|
2
|
+
|
|
3
|
+
require_relative '../../../helper'
|
|
4
|
+
|
|
5
|
+
describe Thoran::Array::NaturalSort do
|
|
6
|
+
it "puts the extract's halves in the order their numbers give" do
|
|
7
|
+
_(%w{public_split_11_20.zip public_split_1_10.zip}.natural_sort).must_equal %w{
|
|
8
|
+
public_split_1_10.zip
|
|
9
|
+
public_split_11_20.zip
|
|
10
|
+
}
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
it "orders twenty unpadded names as their numbers do" do
|
|
14
|
+
names = (1..20).to_a.shuffle.collect{|number| "20261028_Public#{number}.xml"}
|
|
15
|
+
_(names.natural_sort).must_equal (1..20).collect{|number| "20261028_Public#{number}.xml"}
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
it "answers to natsort" do
|
|
19
|
+
_(%w{file10 file2}.natsort).must_equal %w{file2 file10}
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# test/Thoran/String/NaturalComparison/natural_comparison_test.rb
|
|
2
|
+
|
|
3
|
+
require_relative '../../../helper'
|
|
4
|
+
|
|
5
|
+
describe Thoran::String::NaturalComparison do
|
|
6
|
+
it "compares strings without numbers as strings do" do
|
|
7
|
+
_('abc'.natural_comparison('abc')).must_equal 0
|
|
8
|
+
_('abb'.natural_comparison('abc')).must_equal(-1)
|
|
9
|
+
_('abc'.natural_comparison('abb')).must_equal 1
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
it "compares the numbers in them as numbers" do
|
|
13
|
+
_('file2'.natural_comparison('file10')).must_equal(-1)
|
|
14
|
+
_('file10'.natural_comparison('file2')).must_equal 1
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it "goes on to what follows a number where the numbers are equal" do
|
|
18
|
+
_('file1a'.natural_comparison('file1b')).must_equal(-1)
|
|
19
|
+
_('file1a2'.natural_comparison('file1a10')).must_equal(-1)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it "reads a padded number as the number it is" do
|
|
23
|
+
_('Public01'.natural_comparison('Public1')).must_equal 0
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# Each call folds case before matching, so the recursion is handed strings already folded.
|
|
27
|
+
it "folds case where asked, through the recursion as well" do
|
|
28
|
+
_('FILE1A'.natural_comparison('file1a', true)).must_equal 0
|
|
29
|
+
_('FILE1Z'.natural_comparison('file1a', true)).must_equal 1
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
it "answers to natcmp" do
|
|
33
|
+
_('file2'.natcmp('file10')).must_equal(-1)
|
|
34
|
+
end
|
|
35
|
+
end
|
|
@@ -35,4 +35,98 @@ describe "exe/data_gov_au" do
|
|
|
35
35
|
end
|
|
36
36
|
end
|
|
37
37
|
end
|
|
38
|
+
|
|
39
|
+
describe "parsing" do
|
|
40
|
+
def release_under(home, text = File.read(fixture_path('20261020Public01.xml')))
|
|
41
|
+
release = DataGovAu::ABR::Release.new(config_in(File.join(home, '.local', 'share', 'data_gov_au')), Date.new(2026, 10, 20))
|
|
42
|
+
release.create_directory
|
|
43
|
+
Zip::File.open(File.join(release.directory, 'public_split_1_10.zip'), create: true){|zip| zip.get_output_stream('20261020Public01.xml'){|io| io.write(text)}}
|
|
44
|
+
release
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
it "reports each file against the count it carries, and the whole" do
|
|
48
|
+
Dir.mktmpdir do |home|
|
|
49
|
+
release_under(home)
|
|
50
|
+
output, _, status = run_under(home, '-p')
|
|
51
|
+
_(status.exitstatus).must_equal 0
|
|
52
|
+
_(output).must_include '20261020Public01.xml 9 of 9'
|
|
53
|
+
_(output).must_match(/total: 9 records in \d+ s/)
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
it "stops naming a file which reports an error" do
|
|
58
|
+
Dir.mktmpdir do |home|
|
|
59
|
+
release_under(home, File.read(fixture_path('20261020Public01.xml')).sub('error="none"', 'error="partial"'))
|
|
60
|
+
output, error, status = run_under(home, '-p')
|
|
61
|
+
_(status.exitstatus).must_equal 1
|
|
62
|
+
_(output).must_include '9 of 9 error: partial'
|
|
63
|
+
_(error).must_include 'or an error reported, in 20261020Public01.xml'
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
it "says so where a file names no error at all" do
|
|
68
|
+
Dir.mktmpdir do |home|
|
|
69
|
+
release_under(home, File.read(fixture_path('20261020Public01.xml')).sub(' error="none"', ''))
|
|
70
|
+
output, _, status = run_under(home, '-p')
|
|
71
|
+
_(status.exitstatus).must_equal 1
|
|
72
|
+
_(output).must_include '9 of 9 error: not given'
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
# Parsing with nothing held fails naming the releases directory, and so shows where the settings put it without going to the catalogue.
|
|
78
|
+
describe "the data directory" do
|
|
79
|
+
def releases_under(directory)
|
|
80
|
+
File.join(directory, 'abr', 'releases')
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
it "is beneath XDG_DATA_HOME where nothing else names one" do
|
|
84
|
+
Dir.mktmpdir do |home|
|
|
85
|
+
_, error, status = run_under(home, '-p', data_home: File.join(home, 'share'))
|
|
86
|
+
_(status.exitstatus).must_equal 1
|
|
87
|
+
_(error).must_include releases_under(File.join(home, 'share', 'data_gov_au'))
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
it "is beneath ~/.local/share where XDG_DATA_HOME is unset" do
|
|
92
|
+
Dir.mktmpdir do |home|
|
|
93
|
+
_(run_under(home, '-p')[1]).must_include releases_under(File.join(home, '.local', 'share', 'data_gov_au'))
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
it "is the config file's over the default" do
|
|
98
|
+
Dir.mktmpdir do |home|
|
|
99
|
+
write_config(home, "data_directory: #{home}/stored\n")
|
|
100
|
+
_(run_under(home, '-p')[1]).must_include releases_under(File.join(home, 'stored'))
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
it "is the switch's over the config file" do
|
|
105
|
+
Dir.mktmpdir do |home|
|
|
106
|
+
write_config(home, "data_directory: #{home}/stored\n")
|
|
107
|
+
_(run_under(home, '-p', '-d', File.join(home, 'switched'))[1]).must_include releases_under(File.join(home, 'switched'))
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
it "stays the default where the config file leaves it blank" do
|
|
112
|
+
Dir.mktmpdir do |home|
|
|
113
|
+
write_config(home, "data_directory:\n")
|
|
114
|
+
_(run_under(home, '-p')[1]).must_include releases_under(File.join(home, '.local', 'share', 'data_gov_au'))
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
it "stays the default where the config file is empty" do
|
|
119
|
+
Dir.mktmpdir do |home|
|
|
120
|
+
write_config(home, '')
|
|
121
|
+
_(run_under(home, '-p')[1]).must_include releases_under(File.join(home, '.local', 'share', 'data_gov_au'))
|
|
122
|
+
end
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
it "is the config file's where the file also holds a setting the library does not take" do
|
|
126
|
+
Dir.mktmpdir do |home|
|
|
127
|
+
write_config(home, "keep_releases: 6\ndata_directory: #{home}/stored\n")
|
|
128
|
+
_(run_under(home, '-p')[1]).must_include releases_under(File.join(home, 'stored'))
|
|
129
|
+
end
|
|
130
|
+
end
|
|
131
|
+
end
|
|
38
132
|
end
|