mead 0.0.5

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.
@@ -0,0 +1,111 @@
1
+ require 'helper'
2
+
3
+ class TestMeadUA023_006B < Test::Unit::TestCase
4
+
5
+ context "a mead from ua023_006 buildings" do
6
+ setup do
7
+ @mead = 'ua023_006-003-bx0001-008-001'
8
+ end
9
+
10
+ context "parsing a mead from ua023_006" do
11
+ setup do
12
+ @result = Mead::Identifier.new(@mead, File.open('test/ead/ua023_006.xml')) #this is where processing
13
+ end
14
+
15
+ should "produce expected output of eadid" do
16
+ assert_equal @result.eadid, 'ua023_006'
17
+ end
18
+
19
+ should "produce the expected series" do
20
+ assert_equal @result.series, '3'
21
+ end
22
+
23
+ should "produce the expected container" do
24
+ expected = {:type=> 'box', :number => '1'}
25
+ assert_equal expected, @result.container
26
+ end
27
+
28
+ should "produce the expected folder" do
29
+ assert_equal @result.folder, {:type => 'folder', :number => '8'}
30
+ end
31
+
32
+ should "produce the expected sequence" do
33
+ assert_equal @result.sequence, '1'
34
+ end
35
+ end
36
+
37
+ context "extracting metadata from a mead" do
38
+ setup do
39
+ @result = Mead::Identifier.new(@mead, File.open('test/ead/ua023_006.xml'))
40
+ @extractor = Mead::Extractor.new(@result)
41
+ end
42
+
43
+ should "be able to create an extractor" do
44
+ assert_equal @extractor.class, Mead::Extractor
45
+ end
46
+
47
+ should "convert a string to a mead object" do
48
+ assert_equal @extractor.mead.class, Mead::Identifier
49
+ end
50
+
51
+ context "should give back the metadata" do
52
+ setup do
53
+ @result = @extractor.extract
54
+ end
55
+
56
+ should "extract the item's unittitle" do
57
+ assert_equal 'Food Science Building and Phytotron', @extractor.stack[0][:unittitle]
58
+ end
59
+
60
+ should "extract the item's unitdate" do
61
+ assert_nil @extractor.stack[0][:unitdate]
62
+ end
63
+
64
+ should "extract the item unitid" do
65
+ assert_nil @extractor.stack[0][:unitid]
66
+ end
67
+
68
+ should "extract the item level" do
69
+ assert_equal 'file', @extractor.stack[0][:level]
70
+ end
71
+
72
+ should "extract the parent unittitle" do
73
+ assert_equal "Buildings", @extractor.stack[1][:unittitle]
74
+ end
75
+
76
+ should "extract the parent unitdate" do
77
+ assert_equal "1968, 1970, undated", @extractor.stack[1][:unitdate]
78
+ end
79
+
80
+ should "extract the parent unitid" do
81
+ assert_nil @extractor.stack[1][:unitid]
82
+ end
83
+
84
+ should "extract the parent level" do
85
+ assert_equal 'series', @extractor.stack[1][:level]
86
+ end
87
+
88
+ should "extract a series' series number" do
89
+ assert_equal 3, @extractor.stack[1][:series_number]
90
+ end
91
+
92
+ # should "only extract up to the series level" do
93
+ # assert_equal [
94
+ # {:unittitle=>"Food Science Building and Phytotron", :unitdate=>nil,
95
+ # :level => 'file', :unitid => nil, :item_location => 'Box 1, Folder 8'},
96
+ # {:unittitle=>"Buildings", :unitdate=>"1968, 1970, undated",
97
+ # :level => 'series', :unitid => nil,
98
+ # :series_number => 3
99
+ # }
100
+ # ], @extractor.stack
101
+ # end
102
+
103
+ end
104
+
105
+ end
106
+
107
+
108
+
109
+ end
110
+
111
+ end
@@ -0,0 +1,112 @@
1
+ require 'helper'
2
+
3
+ class TestMeadUA023_006 < Test::Unit::TestCase
4
+
5
+ context "a mead from ua023_006 faculty and staff" do
6
+ setup do
7
+ @mead = 'ua023_006-002-bx0001-007-001'
8
+ end
9
+
10
+ context "parsing a mead from ua023_006" do
11
+ setup do
12
+ @result = Mead::Identifier.new(@mead, File.open('test/ead/ua023_006.xml')) #this is where processing
13
+ end
14
+
15
+ should "produce expected output of eadid" do
16
+ assert_equal @result.eadid, 'ua023_006'
17
+ end
18
+
19
+ should "produce the expected series" do
20
+ assert_equal @result.series, '2'
21
+ end
22
+
23
+ should "produce the expected container" do
24
+ expected = {:type=> 'box', :number => '1'}
25
+ assert_equal expected, @result.container
26
+ end
27
+
28
+ should "produce the expected folder" do
29
+ assert_equal @result.folder, {:type=> 'folder', :number => '7'}
30
+ end
31
+
32
+ should "produce the expected sequence" do
33
+ assert_equal @result.sequence, '1'
34
+ end
35
+ end
36
+
37
+ context "extracting metadata from a mead" do
38
+ setup do
39
+ @result = Mead::Identifier.new(@mead, File.open('test/ead/ua023_006.xml'))
40
+ @extractor = Mead::Extractor.new(@result)
41
+ @file = File.open('test/ead/ua023_006.xml')
42
+ end
43
+
44
+ should "be able to create an extractor" do
45
+ assert_equal @extractor.class, Mead::Extractor
46
+ end
47
+
48
+ should "convert a string to a mead object" do
49
+ assert_equal @extractor.mead.class, Mead::Identifier
50
+ end
51
+
52
+ context "should give back the metadata" do
53
+ setup do
54
+ @result = @extractor.extract
55
+ end
56
+
57
+ should "extract the item's unittitle" do
58
+ assert_equal 'Faculty and Staff', @extractor.stack[0][:unittitle]
59
+ end
60
+
61
+ should "extract the item's unitdate" do
62
+ assert_nil @extractor.stack[0][:unitdate]
63
+ end
64
+
65
+ should "extract the item unitid" do
66
+ assert_nil @extractor.stack[0][:unitid]
67
+ end
68
+
69
+ should "extract the item level" do
70
+ assert_equal 'file', @extractor.stack[0][:level]
71
+ end
72
+
73
+ should "extract the parent unittitle" do
74
+ assert_equal "Faculty and Staff", @extractor.stack[1][:unittitle]
75
+ end
76
+
77
+ should "extract the parent unitdate" do
78
+ assert_equal "circa 1900-1988", @extractor.stack[1][:unitdate]
79
+ end
80
+
81
+ should "extract the parent unitid" do
82
+ assert_nil @extractor.stack[1][:unitid]
83
+ end
84
+
85
+ should "extract the parent level" do
86
+ assert_equal 'series', @extractor.stack[1][:level]
87
+ end
88
+
89
+ should "extract a series' series number" do
90
+ assert_equal 2, @extractor.stack[1][:series_number]
91
+ end
92
+
93
+ # should "only extract up to the series level" do
94
+ # assert_equal [
95
+ # {:unittitle=>"Faculty and Staff", :unitdate=>nil, :level => 'file',
96
+ # :unitid => nil, :item_location => 'Box 1, Folder 7'},
97
+ # {:unittitle=>"Faculty and Staff", :unitdate=>"circa 1900-1988",
98
+ # :level => 'series', :unitid => nil,
99
+ # :series_number => 2
100
+ # }
101
+ # ], @extractor.stack
102
+ # end
103
+
104
+ end
105
+
106
+ end
107
+
108
+
109
+
110
+ end
111
+
112
+ end
@@ -0,0 +1,112 @@
1
+ require 'helper'
2
+
3
+ class TestMeadUA110_041 < Test::Unit::TestCase
4
+
5
+ context "a mead from ua110_041" do
6
+ setup do
7
+ @mead = 'ua110_041-001-fr0001_1-000-001'
8
+ end
9
+
10
+ context "parsing a mead from ua110_041" do
11
+ setup do
12
+ @result = Mead::Identifier.new(@mead, File.open('test/ead/ua110_041.xml')) #this is where processing
13
+ end
14
+
15
+ should "produce expected output of eadid" do
16
+ assert_equal @result.eadid, 'ua110_041'
17
+ end
18
+
19
+ should "produce the expected series" do
20
+ assert_equal @result.series, '1'
21
+ end
22
+
23
+ should "produce the expected container" do
24
+ expected = {:type=> 'folder', :number => '1.1'}
25
+ assert_equal expected, @result.container
26
+ end
27
+
28
+ should "produce the expected folder" do
29
+ assert_nil @result.folder
30
+ end
31
+
32
+ should "produce the expected sequence" do
33
+ assert_equal @result.sequence, '1'
34
+ end
35
+ end
36
+
37
+ context "extracting metadata from a mead" do
38
+ setup do
39
+ @result = Mead::Identifier.new(@mead, File.open('test/ead/ua110_041.xml'))
40
+ @extractor = Mead::Extractor.new(@result)
41
+ end
42
+
43
+ should "be able to create an extractor" do
44
+ assert_equal @extractor.class, Mead::Extractor
45
+ end
46
+
47
+ should "convert a string to a mead object" do
48
+ assert_equal @extractor.mead.class, Mead::Identifier
49
+ end
50
+
51
+ context "should give back the metadata" do
52
+ setup do
53
+ @result = @extractor.extract
54
+ end
55
+
56
+ should "extract the item's unittitle" do
57
+ assert_equal 'North Carolina, Wake County, Raleigh: Dix Hill [Dorothea Dix Hospital] Drawings', @extractor.stack[0][:unittitle]
58
+ end
59
+
60
+ should "extract the item's unitdate" do
61
+ assert_nil @extractor.stack[0][:unitdate]
62
+ end
63
+
64
+ should "extract the item unitid" do
65
+ assert_nil @extractor.stack[0][:unitid]
66
+ end
67
+
68
+ should "extract the item level" do
69
+ assert_equal 'file', @extractor.stack[0][:level]
70
+ end
71
+
72
+ should "extract the parent unittitle" do
73
+ assert_equal "UA 110.041 Series 1: Projects", @extractor.stack[1][:unittitle]
74
+ end
75
+
76
+ should "extract the parent unitdate" do
77
+ assert_equal "1951-1976", @extractor.stack[1][:unitdate]
78
+ end
79
+
80
+ should "extract the parent unitid" do
81
+ assert_nil @extractor.stack[1][:unitid]
82
+ end
83
+
84
+ should "extract the parent level" do
85
+ assert_equal 'series', @extractor.stack[1][:level]
86
+ end
87
+
88
+ should "extract a series' series number" do
89
+ assert_equal 1, @extractor.stack[1][:series_number]
90
+ end
91
+
92
+ # should "only extract up to the series level" do
93
+ # assert_equal [
94
+ # {:unittitle=>"North Carolina, Wake County, Raleigh: Dix Hill [Dorothea Dix Hospital] Drawings",
95
+ # :unitdate=>nil, :level => 'file', :unitid => nil,
96
+ # :item_location => 'Folder 1.1'},
97
+ # {:unittitle=>"UA 110.041 Series 1: Projects", :unitdate=>"1951-1976",
98
+ # :level => 'series', :unitid => nil,
99
+ # :series_number => 1
100
+ # }
101
+ # ], @extractor.stack
102
+ # end
103
+
104
+ end
105
+
106
+ end
107
+
108
+
109
+
110
+ end
111
+
112
+ end
@@ -0,0 +1,81 @@
1
+ require 'helper'
2
+
3
+ class TestMeadValidations < Test::Unit::TestCase
4
+ require 'pp'
5
+ def inspect_validation(mead)
6
+ pp mead
7
+ mead.valid?
8
+ pp mead.errors
9
+ end
10
+
11
+ context "validating meads" do
12
+ setup do
13
+ @loc_ua023_031 = File.open('test/ead/ua023_031.xml')
14
+ @loc_mc00240 = File.open('test/ead/mc00240.xml')
15
+ end
16
+
17
+ should "show ua023_031-001-cb0003-005-001 to be a valid mead" do
18
+ mead = Mead::Identifier.new('ua023_031-001-cb0003-005-001', @loc_ua023_031)
19
+ assert mead.valid?
20
+ end
21
+
22
+ should "show ua023_031-001-cb0013-019A-001 to be a valid mead" do
23
+ mead = Mead::Identifier.new('ua023_031-001-cb0013-019A-001', @loc_ua023_031)
24
+ assert mead.valid?
25
+ end
26
+
27
+ should "show ua023_031-001-cb0013-019A-001_0002 to be a valid mead" do
28
+ mead = Mead::Identifier.new('ua023_031-001-cb0013-019A-001', @loc_ua023_031)
29
+ assert mead.valid?
30
+ end
31
+
32
+ should "show ua023-031-01-cb003-05-01 to not be a well-formed mead" do
33
+ mead = Mead::Identifier.new('ua023-031-01-cb003-05-01', @loc_ua023_031)
34
+ assert_equal false, mead.valid?
35
+ end
36
+
37
+ should "show ua023_031-002-cb0006-031-001 to be well-formed but invalid because of series" do
38
+ mead = Mead::Identifier.new('ua023_031-002-cb0006-031-001', @loc_ua023_031)
39
+ assert_equal false, mead.valid?
40
+ end
41
+
42
+ should "show ua023_031-002-cb0006-031-001 to be well-formed" do
43
+ mead = Mead::Identifier.new('ua023_031-002-cb0006-031-001', @loc_ua023_031)
44
+ assert mead.valid_format?
45
+ end
46
+
47
+ should "show ua023_031-001-cb0156-031-001 to be well-formed but invalid" do
48
+ mead = Mead::Identifier.new('ua023_031-002-cb0126-031-001', @loc_ua023_031)
49
+ assert_equal false, mead.valid?
50
+ end
51
+
52
+ # should a blank "folder" here be 001 rather than 000?
53
+ should "show mc00240-001-ff0052-000-001 to be a valid mead" do
54
+ mead = Mead::Identifier.new('mc00240-001-ff0052-000-001', @loc_mc00240)
55
+ assert mead.valid?
56
+ end
57
+ should "show mc00240-001-ff0052-000-001_0002 to be a valid mead with a page" do
58
+ mead = Mead::Identifier.new('mc00240-001-ff0052-000-001_0002', @loc_mc00240)
59
+ #inspect_validation(mead)
60
+ assert mead.valid?
61
+ end
62
+
63
+ should "use the cached metadata in the Mead::Identifier instead of making a new extraction request" do
64
+ mead = Mead::Identifier.new('mc00240-001-ff0052-000-001_0002', @loc_mc00240).extract
65
+ assert mead.valid?
66
+ end
67
+
68
+ should "show mc00240-002-bx0061-fr77_23,1-001 to be a well-formed mead" do
69
+ mead = Mead::Identifier.new('mc00240-002-bx0061-fr77~23_1-001', @loc_mc00240).extract
70
+ assert mead.valid?
71
+ end
72
+
73
+ should 'show mc00240-003-bx0068-fr002-001 to be a valid mead' do
74
+ mead = Mead::Identifier.new('mc00240-003-bx0068-fr002-001', @loc_mc00240).extract
75
+ assert mead.valid?
76
+ end
77
+
78
+ end
79
+
80
+ end
81
+
data/watchr.rb ADDED
@@ -0,0 +1,71 @@
1
+ #watch( 'test/test_.*\.rb' ) {|md| system("rake test") }
2
+ #watch( 'lib/(.*)\.rb' ) {|md| system("rake test") }
3
+
4
+
5
+ def notify(message)
6
+ return if message.nil?
7
+ notify_send = `which notify-send`.chomp
8
+ title = "MEAD Watchr Test Results"
9
+ image = message.include?('0 failures, 0 errors') ? '~/.autotest_images/pass.png' : '~/.autotest_images/fail.png'
10
+ msg = message.slice(/(\d+)\stests,\s(\d+)\sassertions,\s(\d+)\sfailures,\s(\d+)\serrors/)
11
+ system %Q{#{notify_send} '#{title}' '#{msg}' -i #{image} -t 2000 &}
12
+ end
13
+
14
+ def run(cmd)
15
+ puts(cmd)
16
+ `#{cmd}`
17
+ end
18
+
19
+
20
+ def run_test_file(file)
21
+ system('clear')
22
+ puts file
23
+ result = run(%Q(ruby -I"lib:test" -rubygems #{file}))
24
+ notify get_final_result(result)
25
+ puts result
26
+ end
27
+
28
+ def related_test_files(path)
29
+ Dir['test/*.rb'].select { |file| file =~ /test_#{File.basename(path).split(".").first}.rb/ }
30
+ end
31
+
32
+ def get_final_result(result)
33
+ result.split("\n").select{|line| line.include?('failures, ')}.first rescue nil
34
+ end
35
+
36
+ def run_all_tests
37
+ system('clear')
38
+ result = `rake test`
39
+ notify get_final_result(result)#result.split("\n").last rescue nil
40
+ puts result
41
+ end
42
+
43
+ def run_validation_tests
44
+ system('clear')
45
+ result = `rake test:units TEST=test/test_validations.rb`
46
+ notify result.split("\n").last rescue nil
47
+ puts result
48
+ end
49
+
50
+
51
+ watch('test/helper\.rb') { run_all_tests }
52
+ watch('test/test_.*\.rb') { run_all_tests }
53
+ watch('lib/.*/.*\.rb') { run_all_tests }
54
+ watch('test/ead/*.xml'){run_all_tests}
55
+
56
+ Signal.trap('QUIT') { run_all_tests } # Ctrl-\
57
+
58
+ # Ctrl-C
59
+ Signal.trap 'INT' do
60
+ if @interrupted then
61
+ @wants_to_quit = true
62
+ abort("\n")
63
+ else
64
+ puts "Interrupt a second time to quit"
65
+ @interrupted = true
66
+ Kernel.sleep 1.5
67
+ # raise Interrupt, nil # let the run loop catch it
68
+ run_all_tests
69
+ end
70
+ end
71
+