scout-gear 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,36 @@
1
+ require File.expand_path(__FILE__).sub(%r(/test/.*), '/test/test_helper.rb')
2
+ require File.expand_path(__FILE__).sub(%r(.*/test/), '').sub(/test_(.*)\.rb/,'\1')
3
+
4
+ class TestOptions < Test::Unit::TestCase
5
+
6
+ def test_positions2hash
7
+ inputs = IndiferentHash.positional2hash([:one, :two, :three], 1, :two => 2, :four => 4)
8
+ assert_equal 1, inputs[:one]
9
+ assert_equal 2, inputs[:two]
10
+ assert_equal nil, inputs[:three]
11
+ assert_equal nil, inputs[:four]
12
+ end
13
+
14
+ def test_process_to_hash
15
+ list = [1,2,3,4]
16
+ assert_equal 4, IndiferentHash.process_to_hash(list){|l| l.collect{|e| e * 2}}[2]
17
+ end
18
+
19
+ def test_hash2string
20
+ hash = {}
21
+ assert_equal hash, IndiferentHash.string2hash(IndiferentHash.hash2string(hash))
22
+
23
+ hash = {:a => 1}
24
+ assert_equal hash, IndiferentHash.string2hash(IndiferentHash.hash2string(hash))
25
+
26
+ hash = {:a => true}
27
+ assert_equal hash, IndiferentHash.string2hash(IndiferentHash.hash2string(hash))
28
+
29
+ hash = {:a => :b}
30
+ assert_equal hash, IndiferentHash.string2hash(IndiferentHash.hash2string(hash))
31
+
32
+ hash = {:a => /test/}
33
+ assert_equal({}, IndiferentHash.string2hash(IndiferentHash.hash2string(hash)))
34
+ end
35
+ end
36
+
@@ -0,0 +1,110 @@
1
+ require File.expand_path(__FILE__).sub(%r(/test/.*), '/test/test_helper.rb')
2
+ require File.expand_path(__FILE__).sub(%r(.*/test/), '').sub(/test_(.*)\.rb/,'\1')
3
+
4
+ class TestProgress < Test::Unit::TestCase
5
+ SLEEP_TIME=0.0001
6
+ def test_bar
7
+ t1 = Thread.new do
8
+ Log::ProgressBar.with_bar(20, :desc => "Bar 1") do |bar|
9
+ 20.times do
10
+ bar.tick
11
+ sleep SLEEP_TIME
12
+ end
13
+ Log.debug "Done progress"
14
+ assert_equal 100, bar.percent
15
+ end
16
+ end
17
+
18
+ t2 = Thread.new do
19
+ Log::ProgressBar.with_bar(20, :desc => "Bar 2") do |bar|
20
+ 20.times do
21
+ bar.tick
22
+ sleep SLEEP_TIME
23
+ end
24
+ Log.debug "Done progress"
25
+ assert_equal 100, bar.percent
26
+ end
27
+ end
28
+ t1.join
29
+ t2.join
30
+ end
31
+
32
+ def test_bar_no_size
33
+ t1 = Thread.new do
34
+ Log::ProgressBar.with_bar(nil, :desc => "Bar 1", :frequency => 0) do |bar|
35
+ 20.times do
36
+ bar.tick
37
+ sleep SLEEP_TIME
38
+ end
39
+ assert bar.history.length > 0
40
+ end
41
+ end
42
+
43
+ t2 = Thread.new do
44
+ Log::ProgressBar.with_bar(nil, :desc => "Bar 2", :frequency => 0) do |bar|
45
+ 20.times do
46
+ bar.tick
47
+ sleep SLEEP_TIME
48
+ end
49
+ assert bar.history.length > 0
50
+ end
51
+ end
52
+ t1.join
53
+ t2.join
54
+ end
55
+
56
+ def test_bar_nested
57
+ Log::ProgressBar.with_bar(20, :desc => "Bar 1") do |bar|
58
+ bar.init
59
+ 20.times do
60
+ Log::ProgressBar.with_bar(5, :desc => "Bar 2") do |bar|
61
+ 5.times do
62
+ bar.tick
63
+ sleep SLEEP_TIME
64
+ end
65
+ end
66
+ bar.tick
67
+ sleep SLEEP_TIME
68
+ end
69
+ end
70
+ end
71
+
72
+ def test_pos
73
+ size = 10000
74
+
75
+ Log::ProgressBar.with_bar(size, :desc => "Bar 1") do |bar|
76
+ bar.init
77
+ nums = []
78
+ 100.times do
79
+ nums << rand(size)
80
+ end
81
+ nums.sort.each do |num|
82
+ bar.pos num
83
+ sleep SLEEP_TIME
84
+ end
85
+ bar.tick
86
+ end
87
+ end
88
+
89
+ def test_file
90
+ size = 10000
91
+
92
+ TmpFile.with_file do |file|
93
+
94
+ Log::ProgressBar.with_bar(size, :desc => "Bar 1", :file => file) do |bar|
95
+ bar.init
96
+ nums = []
97
+ 100.times do
98
+ nums << rand(size)
99
+ end
100
+ nums.sort.each do |num|
101
+ bar.pos num
102
+ sleep SLEEP_TIME
103
+ end
104
+ bar.tick
105
+ end
106
+ end
107
+ end
108
+
109
+ end
110
+
@@ -0,0 +1,34 @@
1
+ require File.expand_path(__FILE__).sub(%r(/test/.*), '/test/test_helper.rb')
2
+ require 'scout/path'
3
+ require File.expand_path(__FILE__).sub(%r(.*/test/), '').sub(/test_(.*)\.rb/,'\1')
4
+ class TestPathFind < Test::Unit::TestCase
5
+ def test_parts
6
+ path = Path.setup("share/data/some_file", 'scout')
7
+ assert_equal "share", path._toplevel
8
+ assert_equal "data/some_file", path._subpath
9
+
10
+ path = Path.setup("data", 'scout')
11
+ assert_equal nil, path._toplevel
12
+ assert_equal "data", path._subpath
13
+ end
14
+
15
+ def test_find_local
16
+ map = File.join('/usr/local', "{TOPLEVEL}", "{PKGDIR}", "{SUBPATH}")
17
+ path = Path.setup("share/data/some_file", 'scout')
18
+ target = "/usr/local/share/scout/data/some_file"
19
+ assert_equal target, Path.follow(path, map)
20
+ end
21
+
22
+ def test_find
23
+ path = Path.setup("share/data/some_file", 'scout')
24
+ assert_equal "/usr/share/scout/data/some_file", path.find(:usr)
25
+ end
26
+
27
+ def test_current
28
+ path = Path.setup("share/data/some_file", 'scout')
29
+ TmpFile.in_dir do |tmpdir|
30
+ assert_equal File.join(tmpdir,"share/data/some_file"), path.find(:current)
31
+ end
32
+ end
33
+ end
34
+
@@ -0,0 +1,26 @@
1
+ require File.expand_path(__FILE__).sub(%r(/test/.*), '/test/test_helper.rb')
2
+ require File.expand_path(__FILE__).sub(%r(.*/test/), '').sub(/test_(.*)\.rb/,'\1')
3
+
4
+ class TestClass < Test::Unit::TestCase
5
+ def test_indiferent_hash
6
+ a = {:a => 1, "b" => 2}
7
+ a.extend IndiferentHash
8
+
9
+ assert_equal 1, a[:a]
10
+ assert_equal 1, a["a"]
11
+ assert_equal 2, a["b"]
12
+ assert_equal 2, a[:b]
13
+ end
14
+
15
+ def test_case_insensitive_hash
16
+ a = {:a => 1, "b" => 2}
17
+ a.extend CaseInsensitiveHash
18
+
19
+ assert_equal 1, a[:a]
20
+ assert_equal 1, a["A"]
21
+ assert_equal 1, a[:A]
22
+ assert_equal 2, a["B"]
23
+ assert_equal 2, a[:b]
24
+ end
25
+ end
26
+
@@ -0,0 +1,32 @@
1
+ require File.expand_path(__FILE__).sub(%r(/test/.*), '/test/test_helper.rb')
2
+ require File.expand_path(__FILE__).sub(%r(.*/test/), '').sub(/test_(.*)\.rb/,'\1')
3
+
4
+ class TestLog < Test::Unit::TestCase
5
+ def test_get_level
6
+ assert_equal 0, Log.get_level(:debug)
7
+ assert_equal 1, Log.get_level(:low)
8
+ assert_equal 1, Log.get_level("LOW")
9
+ assert_equal 1, Log.get_level(1)
10
+ assert_equal 0, Log.get_level(nil)
11
+ end
12
+
13
+ def test_color
14
+ assert Log.color(:green, "green")
15
+ end
16
+
17
+ def test_iif
18
+ TmpFile.with_file do |tmp|
19
+ Log.logfile(tmp)
20
+ iif :foo
21
+ assert File.read(tmp).include? ":foo"
22
+ assert File.read(tmp).include? "INFO"
23
+ end
24
+ end
25
+
26
+ def test_tty_size
27
+ assert Integer === Log.tty_size
28
+ end
29
+
30
+ end
31
+
32
+
@@ -0,0 +1,22 @@
1
+ require File.expand_path(__FILE__).sub(%r(/test/.*), '/test/test_helper.rb')
2
+ require File.expand_path(__FILE__).sub(%r(.*/test/), '').sub(/test_(.*)\.rb/,'\1')
3
+
4
+ class TestMetaExtension < Test::Unit::TestCase
5
+ module ExtensionClass
6
+ extend MetaExtension
7
+
8
+ extension_attr :code
9
+ end
10
+
11
+ def test_setup
12
+ str = "String"
13
+ ExtensionClass.setup(str, :code)
14
+ assert ExtensionClass === str
15
+ assert_equal :code, str.code
16
+
17
+ str2 = "String2"
18
+ str.annotate(str2)
19
+ assert_equal :code, str2.code
20
+ end
21
+ end
22
+
@@ -0,0 +1,36 @@
1
+ require File.expand_path(__FILE__).sub(%r(/test/.*), '/test/test_helper.rb')
2
+ require File.expand_path(__FILE__).sub(%r(.*/test/), '').sub(/test_(.*)\.rb/,'\1')
3
+
4
+ class TestPath < Test::Unit::TestCase
5
+ def test_join
6
+ path = '/tmp'
7
+ path.extend Path
8
+ assert_equal '/tmp/foo', path.join(:foo)
9
+ assert_equal '/tmp/foo/bar', path.join(:bar, :foo)
10
+ end
11
+
12
+ def test_get
13
+ path = '/tmp'
14
+ path.extend Path
15
+ assert_equal '/tmp/foo', path[:foo]
16
+ assert_equal '/tmp/foo/bar', path.foo[:bar]
17
+ assert_equal '/tmp/foo/bar', path[:bar, :foo]
18
+ end
19
+
20
+ def test_slash
21
+ path = '/tmp'
22
+ path.extend Path
23
+ assert_equal '/tmp/foo', path/:foo
24
+ assert_equal '/tmp/foo/bar', path/:foo/:bar
25
+ assert_equal '/tmp/foo/bar', path.foo/:bar
26
+ assert_equal '/tmp/foo/bar', path./(:bar, :foo)
27
+ end
28
+
29
+ def test_setup
30
+ path = 'tmp'
31
+ Path.setup(path)
32
+ assert_equal 'scout', path.pkgdir
33
+ assert path.libdir.end_with?("scout-gear")
34
+ end
35
+ end
36
+
@@ -0,0 +1,53 @@
1
+ require File.expand_path(__FILE__).sub(%r(/test/.*), '/test/test_helper.rb')
2
+ require File.expand_path(__FILE__).sub(%r(.*/test/), '').sub(/test_(.*)\.rb/,'\1')
3
+
4
+ class TestTmpFile < Test::Unit::TestCase
5
+
6
+ def test_tmp_file
7
+ assert(TmpFile.tmp_file("test") =~ /(tmpfiles|tmp)\/test\d+$/)
8
+ end
9
+
10
+ def test_do_tmp_file
11
+ content = "Hello World!"
12
+ TmpFile.with_file(content) do |file|
13
+ assert_equal content, File.open(file).read
14
+ end
15
+ end
16
+
17
+ def test_do_tmp_file_io
18
+ content = "Hello World!"
19
+ TmpFile.with_file(content) do |file1|
20
+ File.open(file1) do |io|
21
+ TmpFile.with_file(io) do |file|
22
+ assert_equal content, File.open(file).read
23
+ end
24
+ end
25
+ end
26
+ end
27
+
28
+ def test_extension
29
+ TmpFile.with_file(nil, true, :extension => 'txt') do |file|
30
+ assert file =~ /\.txt$/
31
+ end
32
+ end
33
+
34
+ def test_tmpdir
35
+ TmpFile.with_file(nil, true, :tmpdir => TmpFile.user_tmp("TMPDIR")) do |file|
36
+ assert file =~ /TMPDIR/
37
+ end
38
+
39
+ TmpFile.tmpdir = TmpFile.user_tmp("TMPDIR")
40
+
41
+ TmpFile.with_file do |file|
42
+ assert file =~ /TMPDIR/
43
+ end
44
+ end
45
+
46
+ def test_in_dir
47
+ TmpFile.in_dir do |dir|
48
+ assert_equal dir, FileUtils.pwd
49
+ end
50
+ end
51
+
52
+ end
53
+
@@ -0,0 +1,27 @@
1
+ require 'simplecov'
2
+
3
+ module SimpleCov::Configuration
4
+ def clean_filters
5
+ @filters = []
6
+ end
7
+ end
8
+
9
+ SimpleCov.configure do
10
+ clean_filters
11
+ load_adapter 'test_frameworks'
12
+ end
13
+
14
+ ENV["COVERAGE"] && SimpleCov.start do
15
+ add_filter "/.rvm/"
16
+ end
17
+ require 'rubygems'
18
+ require 'test/unit'
19
+
20
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
21
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
22
+ #require 'scout/helper/misc/development'
23
+ require 'scout/tmpfile'
24
+ require 'scout/log'
25
+
26
+ class Test::Unit::TestCase
27
+ end
metadata ADDED
@@ -0,0 +1,134 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: scout-gear
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Miguel Vazquez
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2023-03-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rdoc
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.12'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.12'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: juwelier
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 2.1.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 2.1.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: simplecov
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Temporary files, logs, etc.
70
+ email: mikisvaz@gmail.com
71
+ executables:
72
+ - scout
73
+ extensions: []
74
+ extra_rdoc_files:
75
+ - LICENSE.txt
76
+ - README.rdoc
77
+ files:
78
+ - ".document"
79
+ - ".vimproject"
80
+ - LICENSE.txt
81
+ - README.rdoc
82
+ - Rakefile
83
+ - VERSION
84
+ - bin/scout
85
+ - lib/scout-gear.rb
86
+ - lib/scout/exceptions.rb
87
+ - lib/scout/indiferent_hash.rb
88
+ - lib/scout/indiferent_hash/case_insensitive.rb
89
+ - lib/scout/indiferent_hash/options.rb
90
+ - lib/scout/log.rb
91
+ - lib/scout/log/color.rb
92
+ - lib/scout/log/color_class.rb
93
+ - lib/scout/log/fingerprint.rb
94
+ - lib/scout/log/progress.rb
95
+ - lib/scout/log/progress/report.rb
96
+ - lib/scout/log/progress/util.rb
97
+ - lib/scout/meta_extension.rb
98
+ - lib/scout/path.rb
99
+ - lib/scout/path/find.rb
100
+ - lib/scout/tmpfile.rb
101
+ - scout-gear.gemspec
102
+ - test/scout/indiferent_hash/test_options.rb
103
+ - test/scout/log/test_progress.rb
104
+ - test/scout/path/test_find.rb
105
+ - test/scout/test_indiferent_hash.rb
106
+ - test/scout/test_log.rb
107
+ - test/scout/test_meta_extension.rb
108
+ - test/scout/test_path.rb
109
+ - test/scout/test_tmpfile.rb
110
+ - test/test_helper.rb
111
+ homepage: http://github.com/mikisvaz/scout-gear
112
+ licenses:
113
+ - MIT
114
+ metadata: {}
115
+ post_install_message:
116
+ rdoc_options: []
117
+ require_paths:
118
+ - lib
119
+ required_ruby_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ required_rubygems_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ requirements: []
130
+ rubygems_version: 3.2.15
131
+ signing_key:
132
+ specification_version: 4
133
+ summary: basic gear for scouts
134
+ test_files: []