code
stringlengths 26
124k
| docstring
stringlengths 23
125k
| func_name
stringlengths 1
98
| language
stringclasses 1
value | repo
stringlengths 5
53
| path
stringlengths 7
151
| url
stringlengths 50
211
| license
stringclasses 7
values |
---|---|---|---|---|---|---|---|
def command_presentation
msg = []
msg << command_header
msg << "Usage:"
msg << usage_presentation
if opts = options_presentation
msg << "Options:\n#{opts}"
end
if subcommands = subcommands_presentation
msg << "Subcommands:\n#{subcommands_presentation}"
end
msg.join("\n\n")
end
|
Public: Builds a string representation of the whole command
Returns the string representation of the whole command
|
command_presentation
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/mercenary-0.3.6/lib/mercenary/presenter.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/mercenary-0.3.6/lib/mercenary/presenter.rb
|
Apache-2.0
|
def method_missing(meth, *args, &block)
if meth.to_s =~ /^print_(.+)$/
send("#{$1.downcase}_presentation")
else
super # You *must* call super if you don't handle the method,
# otherwise you'll mess up Ruby's method lookup.
end
end
|
Public: Turn a print_* into a *_presentation or freak out
meth - the method being called
args - an array of arguments passed to the missing method
block - the block passed to the missing method
Returns the value of whatever function is called
|
method_missing
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/mercenary-0.3.6/lib/mercenary/presenter.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/mercenary-0.3.6/lib/mercenary/presenter.rb
|
Apache-2.0
|
def initialize(name)
@config = {}
super(name)
end
|
Public: Creates a new Program
name - the name of the program
Returns nothing
|
initialize
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/mercenary-0.3.6/lib/mercenary/program.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/mercenary-0.3.6/lib/mercenary/program.rb
|
Apache-2.0
|
def go(argv)
logger.debug("Using args passed in: #{argv.inspect}")
cmd = nil
@optparse = OptionParser.new do |opts|
cmd = super(argv, opts, @config)
end
begin
@optparse.parse!(argv)
rescue OptionParser::InvalidOption => e
logger.error "Whoops, we can't understand your command."
logger.error "#{e.message}"
logger.error "Run your command again with the --help switch to see available options."
abort
end
logger.debug("Parsed config: #{@config.inspect}")
begin
cmd.execute(argv, @config)
rescue => e
if cmd.trace
raise e
else
logger.error e.message
abort
end
end
end
|
Public: Run the program
argv - an array of string args (usually ARGV)
Returns nothing
|
go
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/mercenary-0.3.6/lib/mercenary/program.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/mercenary-0.3.6/lib/mercenary/program.rb
|
Apache-2.0
|
def run
raise NotImplementedError, "subclass responsibility"
end
|
#
Runs a single method. Needs to return self.
|
run
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest.rb
|
Apache-2.0
|
def passed?
raise NotImplementedError, "subclass responsibility"
end
|
#
Did this run pass?
Note: skipped runs are not considered passing, but they don't
cause the process to exit non-zero.
|
passed?
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest.rb
|
Apache-2.0
|
def result_code
raise NotImplementedError, "subclass responsibility"
end
|
#
Returns a single character string to print based on the result
of the run. One of <tt>"."</tt>, <tt>"F"</tt>,
<tt>"E"</tt> or <tt>"S"</tt>.
|
result_code
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest.rb
|
Apache-2.0
|
def skipped?
raise NotImplementedError, "subclass responsibility"
end
|
#
Was this run skipped? See #passed? for more information.
|
skipped?
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest.rb
|
Apache-2.0
|
def passed?
not self.failure
end
|
#
Did this run pass?
Note: skipped runs are not considered passing, but they don't
cause the process to exit non-zero.
|
passed?
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest.rb
|
Apache-2.0
|
def location
loc = " [#{self.failure.location}]" unless passed? or error?
"#{self.class_name}##{self.name}#{loc}"
end
|
#
The location identifier of this test. Depends on a method
existing called class_name.
|
location
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest.rb
|
Apache-2.0
|
def result_code
self.failure and self.failure.result_code or "."
end
|
#
Returns ".", "F", or "E" based on the result of the run.
|
result_code
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest.rb
|
Apache-2.0
|
def location
last_before_assertion = ""
self.backtrace.reverse_each do |s|
break if s =~ /in .(assert|refute|flunk|pass|fail|raise|must|wont)/
last_before_assertion = s
end
last_before_assertion.sub(/:in .*$/, "")
end
|
#
Where was this run before an assertion was raised?
|
location
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest.rb
|
Apache-2.0
|
def filter bt
return ["No backtrace"] unless bt
return bt.dup if $DEBUG || ENV["MT_DEBUG"]
new_bt = bt.take_while { |line| line !~ MT_RE }
new_bt = bt.select { |line| line !~ MT_RE } if new_bt.empty?
new_bt = bt.dup if new_bt.empty?
new_bt
end
|
#
Filter +bt+ to something useful. Returns the whole thing if
$DEBUG (ruby) or $MT_DEBUG (env).
|
filter
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest.rb
|
Apache-2.0
|
def diff exp, act
result = nil
expect, butwas = things_to_diff(exp, act)
return "Expected: #{mu_pp exp}\n Actual: #{mu_pp act}" unless
expect
Tempfile.open("expect") do |a|
a.puts expect
a.flush
Tempfile.open("butwas") do |b|
b.puts butwas
b.flush
result = `#{Minitest::Assertions.diff} #{a.path} #{b.path}`
result.sub!(/^\-\-\- .+/, "--- expected")
result.sub!(/^\+\+\+ .+/, "+++ actual")
if result.empty? then
klass = exp.class
result = [
"No visible difference in the #{klass}#inspect output.\n",
"You should look at the implementation of #== on ",
"#{klass} or its members.\n",
expect,
].join
end
end
end
result
end
|
#
Returns a diff between +exp+ and +act+. If there is no known
diff command or if it doesn't make sense to diff the output
(single line, short output), then it simply returns a basic
comparison between the two.
See +things_to_diff+ for more info.
|
diff
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/assertions.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/assertions.rb
|
Apache-2.0
|
def things_to_diff exp, act
expect = mu_pp_for_diff exp
butwas = mu_pp_for_diff act
e1, e2 = expect.include?("\n"), expect.include?("\\n")
b1, b2 = butwas.include?("\n"), butwas.include?("\\n")
need_to_diff =
(e1 ^ e2 ||
b1 ^ b2 ||
expect.size > 30 ||
butwas.size > 30 ||
expect == butwas) &&
Minitest::Assertions.diff
need_to_diff && [expect, butwas]
end
|
#
Returns things to diff [expect, butwas], or [nil, nil] if nothing to diff.
Criterion:
1. Strings include newlines or escaped newlines, but not both.
2. or: String lengths are > 30 characters.
3. or: Strings are equal to each other (but maybe different encodings?).
4. and: we found a diff executable.
|
things_to_diff
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/assertions.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/assertions.rb
|
Apache-2.0
|
def mu_pp obj
s = obj.inspect
if defined? Encoding then
s = s.encode Encoding.default_external
if String === obj && (obj.encoding != Encoding.default_external ||
!obj.valid_encoding?) then
enc = "# encoding: #{obj.encoding}"
val = "# valid: #{obj.valid_encoding?}"
s = "#{enc}\n#{val}\n#{s}"
end
end
s
end
|
#
This returns a human-readable version of +obj+. By default
#inspect is called. You can override this to use #pretty_inspect
if you want.
See Minitest::Test.make_my_diffs_pretty!
|
mu_pp
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/assertions.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/assertions.rb
|
Apache-2.0
|
def mu_pp_for_diff obj
str = mu_pp obj
# both '\n' & '\\n' (_after_ mu_pp (aka inspect))
single = !!str.match(/(?<!\\|^)\\n/)
double = !!str.match(/(?<=\\|^)\\n/)
process =
if single ^ double then
if single then
lambda { |s| s == "\\n" ? "\n" : s } # unescape
else
lambda { |s| s == "\\\\n" ? "\\n\n" : s } # unescape a bit, add nls
end
else
:itself # leave it alone
end
str.
gsub(/\\?\\n/, &process).
gsub(/:0x[a-fA-F0-9]{4,}/m, ":0xXXXXXX") # anonymize hex values
end
|
#
This returns a diff-able more human-readable version of +obj+.
This differs from the regular mu_pp because it expands escaped
newlines and makes hex-values (like object_ids) generic. This
uses mu_pp to do the first pass and then cleans it up.
|
mu_pp_for_diff
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/assertions.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/assertions.rb
|
Apache-2.0
|
def assert_equal exp, act, msg = nil
msg = message(msg, E) { diff exp, act }
result = assert exp == act, msg
if nil == exp then
if Minitest::VERSION =~ /^6/ then
refute_nil exp, "Use assert_nil if expecting nil."
else
where = Minitest.filter_backtrace(caller).first
where = where.split(/:in /, 2).first # clean up noise
warn "DEPRECATED: Use assert_nil if expecting nil from #{where}. This will fail in Minitest 6."
end
end
result
end
|
#
Fails unless <tt>exp == act</tt> printing the difference between
the two, if possible.
If there is no visible difference but the assertion fails, you
should suspect that your #== is buggy, or your inspect output is
missing crucial details. For nicer structural diffing, set
Minitest::Test.make_my_diffs_pretty!
For floats use assert_in_delta.
See also: Minitest::Assertions.diff
|
assert_equal
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/assertions.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/assertions.rb
|
Apache-2.0
|
def assert_in_delta exp, act, delta = 0.001, msg = nil
n = (exp - act).abs
msg = message(msg) {
"Expected |#{exp} - #{act}| (#{n}) to be <= #{delta}"
}
assert delta >= n, msg
end
|
#
For comparing Floats. Fails unless +exp+ and +act+ are within +delta+
of each other.
assert_in_delta Math::PI, (22.0 / 7.0), 0.01
|
assert_in_delta
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/assertions.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/assertions.rb
|
Apache-2.0
|
def assert_in_epsilon exp, act, epsilon = 0.001, msg = nil
assert_in_delta exp, act, [exp.abs, act.abs].min * epsilon, msg
end
|
#
For comparing Floats. Fails unless +exp+ and +act+ have a relative
error less than +epsilon+.
|
assert_in_epsilon
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/assertions.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/assertions.rb
|
Apache-2.0
|
def assert_instance_of cls, obj, msg = nil
msg = message(msg) {
"Expected #{mu_pp(obj)} to be an instance of #{cls}, not #{obj.class}"
}
assert obj.instance_of?(cls), msg
end
|
#
Fails unless +obj+ is an instance of +cls+.
|
assert_instance_of
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/assertions.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/assertions.rb
|
Apache-2.0
|
def assert_kind_of cls, obj, msg = nil
msg = message(msg) {
"Expected #{mu_pp(obj)} to be a kind of #{cls}, not #{obj.class}" }
assert obj.kind_of?(cls), msg
end
|
#
Fails unless +obj+ is a kind of +cls+.
|
assert_kind_of
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/assertions.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/assertions.rb
|
Apache-2.0
|
def assert_match matcher, obj, msg = nil
msg = message(msg) { "Expected #{mu_pp matcher} to match #{mu_pp obj}" }
assert_respond_to matcher, :"=~"
matcher = Regexp.new Regexp.escape matcher if String === matcher
assert matcher =~ obj, msg
Regexp.last_match
end
|
#
Fails unless +matcher+ <tt>=~</tt> +obj+.
|
assert_match
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/assertions.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/assertions.rb
|
Apache-2.0
|
def assert_operator o1, op, o2 = UNDEFINED, msg = nil
return assert_predicate o1, op, msg if UNDEFINED == o2
msg = message(msg) { "Expected #{mu_pp(o1)} to be #{op} #{mu_pp(o2)}" }
assert o1.__send__(op, o2), msg
end
|
#
For testing with binary operators. Eg:
assert_operator 5, :<=, 4
|
assert_operator
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/assertions.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/assertions.rb
|
Apache-2.0
|
def assert_output stdout = nil, stderr = nil
flunk "assert_output requires a block to capture output." unless
block_given?
out, err = capture_io do
yield
end
err_msg = Regexp === stderr ? :assert_match : :assert_equal if stderr
out_msg = Regexp === stdout ? :assert_match : :assert_equal if stdout
y = send err_msg, stderr, err, "In stderr" if err_msg
x = send out_msg, stdout, out, "In stdout" if out_msg
(!stdout || x) && (!stderr || y)
rescue Assertion
raise
rescue => e
raise UnexpectedError, e
end
|
#
Fails if stdout or stderr do not output the expected results.
Pass in nil if you don't care about that streams output. Pass in
"" if you require it to be silent. Pass in a regexp if you want
to pattern match.
assert_output(/hey/) { method_with_output }
NOTE: this uses #capture_io, not #capture_subprocess_io.
See also: #assert_silent
|
assert_output
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/assertions.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/assertions.rb
|
Apache-2.0
|
def assert_pattern
raise NotImplementedError, "only available in Ruby 3.0+" unless RUBY_VERSION >= "3.0"
flunk "assert_pattern requires a block to capture errors." unless block_given?
begin # TODO: remove after ruby 2.6 dropped
yield
pass
rescue NoMatchingPatternError => e
flunk e.message
end
end
|
#
For testing with pattern matching (only supported with Ruby 3.0 and later)
# pass
assert_pattern { [1,2,3] => [Integer, Integer, Integer] }
# fail "length mismatch (given 3, expected 1)"
assert_pattern { [1,2,3] => [Integer] }
The bare <tt>=></tt> pattern will raise a NoMatchingPatternError on failure, which would
normally be counted as a test error. This assertion rescues NoMatchingPatternError and
generates a test failure. Any other exception will be raised as normal and generate a test
error.
|
assert_pattern
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/assertions.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/assertions.rb
|
Apache-2.0
|
def assert_predicate o1, op, msg = nil
msg = message(msg) { "Expected #{mu_pp(o1)} to be #{op}" }
assert o1.__send__(op), msg
end
|
#
For testing with predicates. Eg:
assert_predicate str, :empty?
This is really meant for specs and is front-ended by assert_operator:
str.must_be :empty?
|
assert_predicate
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/assertions.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/assertions.rb
|
Apache-2.0
|
def assert_raises *exp
flunk "assert_raises requires a block to capture errors." unless
block_given?
msg = "#{exp.pop}.\n" if String === exp.last
exp << StandardError if exp.empty?
begin
yield
rescue *exp => e
pass # count assertion
return e
rescue Minitest::Assertion # incl Skip & UnexpectedError
# don't count assertion
raise
rescue SignalException, SystemExit
raise
rescue Exception => e
flunk proc {
exception_details(e, "#{msg}#{mu_pp(exp)} exception expected, not")
}
end
exp = exp.first if exp.size == 1
flunk "#{msg}#{mu_pp(exp)} expected but nothing was raised."
end
|
#
Fails unless the block raises one of +exp+. Returns the
exception matched so you can check the message, attributes, etc.
+exp+ takes an optional message on the end to help explain
failures and defaults to StandardError if no exception class is
passed. Eg:
assert_raises(CustomError) { method_with_custom_error }
With custom error message:
assert_raises(CustomError, 'This should have raised CustomError') { method_with_custom_error }
Using the returned object:
error = assert_raises(CustomError) do
raise CustomError, 'This is really bad'
end
assert_equal 'This is really bad', error.message
|
assert_raises
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/assertions.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/assertions.rb
|
Apache-2.0
|
def assert_respond_to obj, meth, msg = nil
msg = message(msg) {
"Expected #{mu_pp(obj)} (#{obj.class}) to respond to ##{meth}"
}
assert obj.respond_to?(meth), msg
end
|
#
Fails unless +obj+ responds to +meth+.
|
assert_respond_to
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/assertions.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/assertions.rb
|
Apache-2.0
|
def assert_same exp, act, msg = nil
msg = message(msg) {
data = [mu_pp(act), act.object_id, mu_pp(exp), exp.object_id]
"Expected %s (oid=%d) to be the same as %s (oid=%d)" % data
}
assert exp.equal?(act), msg
end
|
#
Fails unless +exp+ and +act+ are #equal?
|
assert_same
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/assertions.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/assertions.rb
|
Apache-2.0
|
def assert_send send_ary, m = nil
where = Minitest.filter_backtrace(caller).first
where = where.split(/:in /, 2).first # clean up noise
warn "DEPRECATED: assert_send. From #{where}"
recv, msg, *args = send_ary
m = message(m) {
"Expected #{mu_pp(recv)}.#{msg}(*#{mu_pp(args)}) to return true" }
assert recv.__send__(msg, *args), m
end
|
#
+send_ary+ is a receiver, message and arguments.
Fails unless the call returns a true value
|
assert_send
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/assertions.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/assertions.rb
|
Apache-2.0
|
def assert_silent
assert_output "", "" do
yield
end
end
|
#
Fails if the block outputs anything to stderr or stdout.
See also: #assert_output
|
assert_silent
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/assertions.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/assertions.rb
|
Apache-2.0
|
def assert_throws sym, msg = nil
default = "Expected #{mu_pp(sym)} to have been thrown"
caught = true
value = catch(sym) do
begin
yield
rescue ThreadError => e # wtf?!? 1.8 + threads == suck
default += ", not \:#{e.message[/uncaught throw \`(\w+?)\'/, 1]}"
rescue ArgumentError => e # 1.9 exception
raise e unless e.message.include?("uncaught throw")
default += ", not #{e.message.split(/ /).last}"
rescue NameError => e # 1.8 exception
raise e unless e.name == sym
default += ", not #{e.name.inspect}"
end
caught = false
end
assert caught, message(msg) { default }
value
rescue Assertion
raise
rescue => e
raise UnexpectedError, e
end
|
#
Fails unless the block throws +sym+
|
assert_throws
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/assertions.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/assertions.rb
|
Apache-2.0
|
def capture_io
_synchronize do
begin
captured_stdout, captured_stderr = StringIO.new, StringIO.new
orig_stdout, orig_stderr = $stdout, $stderr
$stdout, $stderr = captured_stdout, captured_stderr
yield
return captured_stdout.string, captured_stderr.string
ensure
$stdout = orig_stdout
$stderr = orig_stderr
end
end
end
|
#
Captures $stdout and $stderr into strings:
out, err = capture_io do
puts "Some info"
warn "You did a bad thing"
end
assert_match %r%info%, out
assert_match %r%bad%, err
NOTE: For efficiency, this method uses StringIO and does not
capture IO for subprocesses. Use #capture_subprocess_io for
that.
|
capture_io
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/assertions.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/assertions.rb
|
Apache-2.0
|
def capture_subprocess_io
_synchronize do
begin
require "tempfile"
captured_stdout, captured_stderr = Tempfile.new("out"), Tempfile.new("err")
orig_stdout, orig_stderr = $stdout.dup, $stderr.dup
$stdout.reopen captured_stdout
$stderr.reopen captured_stderr
yield
$stdout.rewind
$stderr.rewind
return captured_stdout.read, captured_stderr.read
ensure
$stdout.reopen orig_stdout
$stderr.reopen orig_stderr
orig_stdout.close
orig_stderr.close
captured_stdout.close!
captured_stderr.close!
end
end
end
|
#
Captures $stdout and $stderr into strings, using Tempfile to
ensure that subprocess IO is captured as well.
out, err = capture_subprocess_io do
system "echo Some info"
system "echo You did a bad thing 1>&2"
end
assert_match %r%info%, out
assert_match %r%bad%, err
NOTE: This method is approximately 10x slower than #capture_io so
only use it when you need to test the output of a subprocess.
|
capture_subprocess_io
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/assertions.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/assertions.rb
|
Apache-2.0
|
def fail_after y,m,d,msg
flunk msg if Time.now > Time.local(y, m, d)
end
|
#
Fails after a given date (in the local time zone). This allows
you to put time-bombs in your tests if you need to keep
something around until a later date lest you forget about it.
|
fail_after
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/assertions.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/assertions.rb
|
Apache-2.0
|
def message msg = nil, ending = nil, &default
proc {
msg = msg.call.chomp(".") if Proc === msg
custom_message = "#{msg}.\n" unless msg.nil? or msg.to_s.empty?
"#{custom_message}#{default.call}#{ending || "."}"
}
end
|
#
Returns a proc that will output +msg+ along with the default message.
|
message
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/assertions.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/assertions.rb
|
Apache-2.0
|
def refute_equal exp, act, msg = nil
msg = message(msg) {
"Expected #{mu_pp(act)} to not be equal to #{mu_pp(exp)}"
}
refute exp == act, msg
end
|
#
Fails if <tt>exp == act</tt>.
For floats use refute_in_delta.
|
refute_equal
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/assertions.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/assertions.rb
|
Apache-2.0
|
def refute_in_delta exp, act, delta = 0.001, msg = nil
n = (exp - act).abs
msg = message(msg) {
"Expected |#{exp} - #{act}| (#{n}) to not be <= #{delta}"
}
refute delta >= n, msg
end
|
#
For comparing Floats. Fails if +exp+ is within +delta+ of +act+.
refute_in_delta Math::PI, (22.0 / 7.0)
|
refute_in_delta
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/assertions.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/assertions.rb
|
Apache-2.0
|
def refute_in_epsilon a, b, epsilon = 0.001, msg = nil
refute_in_delta a, b, a * epsilon, msg
end
|
#
For comparing Floats. Fails if +exp+ and +act+ have a relative error
less than +epsilon+.
|
refute_in_epsilon
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/assertions.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/assertions.rb
|
Apache-2.0
|
def refute_instance_of cls, obj, msg = nil
msg = message(msg) {
"Expected #{mu_pp(obj)} to not be an instance of #{cls}"
}
refute obj.instance_of?(cls), msg
end
|
#
Fails if +obj+ is an instance of +cls+.
|
refute_instance_of
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/assertions.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/assertions.rb
|
Apache-2.0
|
def refute_kind_of cls, obj, msg = nil
msg = message(msg) { "Expected #{mu_pp(obj)} to not be a kind of #{cls}" }
refute obj.kind_of?(cls), msg
end
|
#
Fails if +obj+ is a kind of +cls+.
|
refute_kind_of
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/assertions.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/assertions.rb
|
Apache-2.0
|
def refute_match matcher, obj, msg = nil
msg = message(msg) { "Expected #{mu_pp matcher} to not match #{mu_pp obj}" }
assert_respond_to matcher, :"=~"
matcher = Regexp.new Regexp.escape matcher if String === matcher
refute matcher =~ obj, msg
end
|
#
Fails if +matcher+ <tt>=~</tt> +obj+.
|
refute_match
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/assertions.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/assertions.rb
|
Apache-2.0
|
def refute_pattern
raise NotImplementedError, "only available in Ruby 3.0+" unless RUBY_VERSION >= "3.0"
flunk "refute_pattern requires a block to capture errors." unless block_given?
begin
yield
flunk("NoMatchingPatternError expected, but nothing was raised.")
rescue NoMatchingPatternError
pass
end
end
|
#
For testing with pattern matching (only supported with Ruby 3.0 and later)
# pass
refute_pattern { [1,2,3] => [String] }
# fail "NoMatchingPatternError expected, but nothing was raised."
refute_pattern { [1,2,3] => [Integer, Integer, Integer] }
This assertion expects a NoMatchingPatternError exception, and will fail if none is raised. Any
other exceptions will be raised as normal and generate a test error.
|
refute_pattern
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/assertions.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/assertions.rb
|
Apache-2.0
|
def refute_operator o1, op, o2 = UNDEFINED, msg = nil
return refute_predicate o1, op, msg if UNDEFINED == o2
msg = message(msg) { "Expected #{mu_pp(o1)} to not be #{op} #{mu_pp(o2)}" }
refute o1.__send__(op, o2), msg
end
|
#
Fails if +o1+ is not +op+ +o2+. Eg:
refute_operator 1, :>, 2 #=> pass
refute_operator 1, :<, 2 #=> fail
|
refute_operator
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/assertions.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/assertions.rb
|
Apache-2.0
|
def refute_predicate o1, op, msg = nil
msg = message(msg) { "Expected #{mu_pp(o1)} to not be #{op}" }
refute o1.__send__(op), msg
end
|
#
For testing with predicates.
refute_predicate str, :empty?
This is really meant for specs and is front-ended by refute_operator:
str.wont_be :empty?
|
refute_predicate
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/assertions.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/assertions.rb
|
Apache-2.0
|
def refute_respond_to obj, meth, msg = nil
msg = message(msg) { "Expected #{mu_pp(obj)} to not respond to #{meth}" }
refute obj.respond_to?(meth), msg
end
|
#
Fails if +obj+ responds to the message +meth+.
|
refute_respond_to
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/assertions.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/assertions.rb
|
Apache-2.0
|
def refute_same exp, act, msg = nil
msg = message(msg) {
data = [mu_pp(act), act.object_id, mu_pp(exp), exp.object_id]
"Expected %s (oid=%d) to not be the same as %s (oid=%d)" % data
}
refute exp.equal?(act), msg
end
|
#
Fails if +exp+ is the same (by object identity) as +act+.
|
refute_same
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/assertions.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/assertions.rb
|
Apache-2.0
|
def skip msg = nil, bt = caller
msg ||= "Skipped, no message given"
@skip = true
raise Minitest::Skip, msg, bt
end
|
#
Skips the current run. If run in verbose-mode, the skipped run
gets listed at the end of the run but doesn't cause a failure
exit code.
|
skip
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/assertions.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/assertions.rb
|
Apache-2.0
|
def skip_until y,m,d,msg
skip msg if Time.now < Time.local(y, m, d)
where = caller.first.rpartition(':in').reject(&:empty?).first
warn "Stale skip_until %p at %s" % [msg, where]
end
|
#
Skips the current run until a given date (in the local time
zone). This allows you to put some fixes on hold until a later
date, but still holds you accountable and prevents you from
forgetting it.
|
skip_until
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/assertions.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/assertions.rb
|
Apache-2.0
|
def skipped?
defined?(@skip) and @skip
end
|
#
Was this testcase skipped? Meant for #teardown.
|
skipped?
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/assertions.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/assertions.rb
|
Apache-2.0
|
def assert_performance validation, &work
range = self.class.bench_range
io.print "#{self.name}"
times = []
range.each do |x|
GC.start
t0 = Minitest.clock_time
instance_exec(x, &work)
t = Minitest.clock_time - t0
io.print "\t%9.6f" % t
times << t
end
io.puts
validation[range, times]
end
|
#
Runs the given +work+, gathering the times of each run. Range
and times are then passed to a given +validation+ proc. Outputs
the benchmark name and times in tab-separated format, making it
easy to paste into a spreadsheet for graphing or further
analysis.
Ranges are specified by ::bench_range.
Eg:
def bench_algorithm
validation = proc { |x, y| ... }
assert_performance validation do |n|
@obj.algorithm(n)
end
end
|
assert_performance
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/benchmark.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/benchmark.rb
|
Apache-2.0
|
def assert_performance_constant threshold = 0.99, &work
validation = proc do |range, times|
a, b, rr = fit_linear range, times
assert_in_delta 0, b, 1 - threshold
[a, b, rr]
end
assert_performance validation, &work
end
|
#
Runs the given +work+ and asserts that the times gathered fit to
match a constant rate (eg, linear slope == 0) within a given
+threshold+. Note: because we're testing for a slope of 0, R^2
is not a good determining factor for the fit, so the threshold
is applied against the slope itself. As such, you probably want
to tighten it from the default.
See https://www.graphpad.com/guides/prism/8/curve-fitting/reg_intepretingnonlinr2.htm
for more details.
Fit is calculated by #fit_linear.
Ranges are specified by ::bench_range.
Eg:
def bench_algorithm
assert_performance_constant 0.9999 do |n|
@obj.algorithm(n)
end
end
|
assert_performance_constant
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/benchmark.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/benchmark.rb
|
Apache-2.0
|
def assert_performance_exponential threshold = 0.99, &work
assert_performance validation_for_fit(:exponential, threshold), &work
end
|
#
Runs the given +work+ and asserts that the times gathered fit to
match a exponential curve within a given error +threshold+.
Fit is calculated by #fit_exponential.
Ranges are specified by ::bench_range.
Eg:
def bench_algorithm
assert_performance_exponential 0.9999 do |n|
@obj.algorithm(n)
end
end
|
assert_performance_exponential
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/benchmark.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/benchmark.rb
|
Apache-2.0
|
def assert_performance_logarithmic threshold = 0.99, &work
assert_performance validation_for_fit(:logarithmic, threshold), &work
end
|
#
Runs the given +work+ and asserts that the times gathered fit to
match a logarithmic curve within a given error +threshold+.
Fit is calculated by #fit_logarithmic.
Ranges are specified by ::bench_range.
Eg:
def bench_algorithm
assert_performance_logarithmic 0.9999 do |n|
@obj.algorithm(n)
end
end
|
assert_performance_logarithmic
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/benchmark.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/benchmark.rb
|
Apache-2.0
|
def assert_performance_linear threshold = 0.99, &work
assert_performance validation_for_fit(:linear, threshold), &work
end
|
#
Runs the given +work+ and asserts that the times gathered fit to
match a straight line within a given error +threshold+.
Fit is calculated by #fit_linear.
Ranges are specified by ::bench_range.
Eg:
def bench_algorithm
assert_performance_linear 0.9999 do |n|
@obj.algorithm(n)
end
end
|
assert_performance_linear
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/benchmark.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/benchmark.rb
|
Apache-2.0
|
def assert_performance_power threshold = 0.99, &work
assert_performance validation_for_fit(:power, threshold), &work
end
|
#
Runs the given +work+ and asserts that the times gathered curve
fit to match a power curve within a given error +threshold+.
Fit is calculated by #fit_power.
Ranges are specified by ::bench_range.
Eg:
def bench_algorithm
assert_performance_power 0.9999 do |x|
@obj.algorithm
end
end
|
assert_performance_power
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/benchmark.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/benchmark.rb
|
Apache-2.0
|
def fit_error xys
y_bar = sigma(xys) { |_, y| y } / xys.size.to_f
ss_tot = sigma(xys) { |_, y| (y - y_bar) ** 2 }
ss_err = sigma(xys) { |x, y| (yield(x) - y) ** 2 }
1 - (ss_err / ss_tot)
end
|
#
Takes an array of x/y pairs and calculates the general R^2 value.
See: https://en.wikipedia.org/wiki/Coefficient_of_determination
|
fit_error
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/benchmark.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/benchmark.rb
|
Apache-2.0
|
def fit_exponential xs, ys
n = xs.size
xys = xs.zip(ys)
sxlny = sigma(xys) { |x, y| x * Math.log(y) }
slny = sigma(xys) { |_, y| Math.log(y) }
sx2 = sigma(xys) { |x, _| x * x }
sx = sigma xs
c = n * sx2 - sx ** 2
a = (slny * sx2 - sx * sxlny) / c
b = ( n * sxlny - sx * slny ) / c
return Math.exp(a), b, fit_error(xys) { |x| Math.exp(a + b * x) }
end
|
#
To fit a functional form: y = ae^(bx).
Takes x and y values and returns [a, b, r^2].
See: https://mathworld.wolfram.com/LeastSquaresFittingExponential.html
|
fit_exponential
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/benchmark.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/benchmark.rb
|
Apache-2.0
|
def fit_logarithmic xs, ys
n = xs.size
xys = xs.zip(ys)
slnx2 = sigma(xys) { |x, _| Math.log(x) ** 2 }
slnx = sigma(xys) { |x, _| Math.log(x) }
sylnx = sigma(xys) { |x, y| y * Math.log(x) }
sy = sigma(xys) { |_, y| y }
c = n * slnx2 - slnx ** 2
b = ( n * sylnx - sy * slnx ) / c
a = (sy - b * slnx) / n
return a, b, fit_error(xys) { |x| a + b * Math.log(x) }
end
|
#
To fit a functional form: y = a + b*ln(x).
Takes x and y values and returns [a, b, r^2].
See: https://mathworld.wolfram.com/LeastSquaresFittingLogarithmic.html
|
fit_logarithmic
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/benchmark.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/benchmark.rb
|
Apache-2.0
|
def fit_linear xs, ys
n = xs.size
xys = xs.zip(ys)
sx = sigma xs
sy = sigma ys
sx2 = sigma(xs) { |x| x ** 2 }
sxy = sigma(xys) { |x, y| x * y }
c = n * sx2 - sx**2
a = (sy * sx2 - sx * sxy) / c
b = ( n * sxy - sx * sy ) / c
return a, b, fit_error(xys) { |x| a + b * x }
end
|
#
Fits the functional form: a + bx.
Takes x and y values and returns [a, b, r^2].
See: https://mathworld.wolfram.com/LeastSquaresFitting.html
|
fit_linear
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/benchmark.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/benchmark.rb
|
Apache-2.0
|
def fit_power xs, ys
n = xs.size
xys = xs.zip(ys)
slnxlny = sigma(xys) { |x, y| Math.log(x) * Math.log(y) }
slnx = sigma(xs) { |x | Math.log(x) }
slny = sigma(ys) { | y| Math.log(y) }
slnx2 = sigma(xs) { |x | Math.log(x) ** 2 }
b = (n * slnxlny - slnx * slny) / (n * slnx2 - slnx ** 2)
a = (slny - b * slnx) / n
return Math.exp(a), b, fit_error(xys) { |x| (Math.exp(a) * (x ** b)) }
end
|
#
To fit a functional form: y = ax^b.
Takes x and y values and returns [a, b, r^2].
See: https://mathworld.wolfram.com/LeastSquaresFittingPowerLaw.html
|
fit_power
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/benchmark.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/benchmark.rb
|
Apache-2.0
|
def sigma enum, &block
enum = enum.map(&block) if block
enum.inject { |sum, n| sum + n }
end
|
#
Enumerates over +enum+ mapping +block+ if given, returning the
sum of the result. Eg:
sigma([1, 2, 3]) # => 1 + 2 + 3 => 6
sigma([1, 2, 3]) { |n| n ** 2 } # => 1 + 4 + 9 => 14
|
sigma
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/benchmark.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/benchmark.rb
|
Apache-2.0
|
def validation_for_fit msg, threshold
proc do |range, times|
a, b, rr = send "fit_#{msg}", range, times
assert_operator rr, :>=, threshold
[a, b, rr]
end
end
|
#
Returns a proc that calls the specified fit method and asserts
that the error is within a tolerable threshold.
|
validation_for_fit
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/benchmark.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/benchmark.rb
|
Apache-2.0
|
def expect name, retval, args = [], **kwargs, &blk
name = name.to_sym
if block_given?
raise ArgumentError, "args ignored when block given" unless args.empty?
raise ArgumentError, "kwargs ignored when block given" unless kwargs.empty?
@expected_calls[name] << { :retval => retval, :block => blk }
else
raise ArgumentError, "args must be an array" unless Array === args
if ENV["MT_KWARGS_HAC\K"] && (Hash === args.last ||
Hash == args.last) then
if kwargs.empty? then
kwargs = args.pop
else
unless @@KW_WARNED then
from = caller.first
warn "Using MT_KWARGS_HAC\K yet passing kwargs. From #{from}"
@@KW_WARNED = true
end
end
end
@expected_calls[name] <<
{ :retval => retval, :args => args, :kwargs => kwargs }
end
self
end
|
#
Expect that method +name+ is called, optionally with +args+ (and
+kwargs+ or a +blk+), and returns +retval+.
@mock.expect(:meaning_of_life, 42)
@mock.meaning_of_life # => 42
@mock.expect(:do_something_with, true, [some_obj, true])
@mock.do_something_with(some_obj, true) # => true
@mock.expect(:do_something_else, true) do |a1, a2|
a1 == "buggs" && a2 == :bunny
end
+args+ is compared to the expected args using case equality (ie, the
'===' operator), allowing for less specific expectations.
@mock.expect(:uses_any_string, true, [String])
@mock.uses_any_string("foo") # => true
@mock.verify # => true
@mock.expect(:uses_one_string, true, ["foo"])
@mock.uses_one_string("bar") # => raises MockExpectationError
If a method will be called multiple times, specify a new expect for each one.
They will be used in the order you define them.
@mock.expect(:ordinal_increment, 'first')
@mock.expect(:ordinal_increment, 'second')
@mock.ordinal_increment # => 'first'
@mock.ordinal_increment # => 'second'
@mock.ordinal_increment # => raises MockExpectationError "No more expects available for :ordinal_increment"
|
expect
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/mock.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/mock.rb
|
Apache-2.0
|
def verify
@expected_calls.each do |name, expected|
actual = @actual_calls.fetch(name, nil)
raise MockExpectationError, "expected #{__call name, expected[0]}" unless actual
raise MockExpectationError, "expected #{__call name, expected[actual.size]}, got [#{__call name, actual}]" if
actual.size < expected.size
end
true
end
|
#
Verify that all methods were called as expected. Raises
+MockExpectationError+ if the mock object was not called as
expected.
|
verify
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/mock.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/mock.rb
|
Apache-2.0
|
def assert_mock mock
assert mock.verify
end
|
#
Assert that the mock verifies correctly.
|
assert_mock
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/mock.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/mock.rb
|
Apache-2.0
|
def stub name, val_or_callable, *block_args, **block_kwargs, &block
new_name = "__minitest_stub__#{name}"
metaclass = class << self; self; end
if respond_to? name and not methods.map(&:to_s).include? name.to_s then
metaclass.send :define_method, name do |*args, **kwargs|
super(*args, **kwargs)
end
end
metaclass.send :alias_method, new_name, name
if ENV["MT_KWARGS_HAC\K"] then
metaclass.send :define_method, name do |*args, &blk|
if val_or_callable.respond_to? :call then
val_or_callable.call(*args, &blk)
else
blk.call(*block_args, **block_kwargs) if blk
val_or_callable
end
end
else
metaclass.send :define_method, name do |*args, **kwargs, &blk|
if val_or_callable.respond_to? :call then
if kwargs.empty? then # FIX: drop this after 2.7 dead
val_or_callable.call(*args, &blk)
else
val_or_callable.call(*args, **kwargs, &blk)
end
else
if blk then
if block_kwargs.empty? then # FIX: drop this after 2.7 dead
blk.call(*block_args)
else
blk.call(*block_args, **block_kwargs)
end
end
val_or_callable
end
end
end
block[self]
ensure
metaclass.send :undef_method, name
metaclass.send :alias_method, name, new_name
metaclass.send :undef_method, new_name
end
|
#
Add a temporary stubbed method replacing +name+ for the duration
of the +block+. If +val_or_callable+ responds to #call, then it
returns the result of calling it, otherwise returns the value
as-is. If stubbed method yields a block, +block_args+ will be
passed along. Cleans up the stub at the end of the +block+. The
method +name+ must exist before stubbing.
def test_stale_eh
obj_under_test = Something.new
refute obj_under_test.stale?
Time.stub :now, Time.at(0) do
assert obj_under_test.stale?
end
end
--
NOTE: keyword args in callables are NOT checked for correctness
against the existing method. Too many edge cases to be worth it.
|
stub
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/mock.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/mock.rb
|
Apache-2.0
|
def initialize size
@size = size
@queue = Queue.new
@pool = nil
end
|
#
Create a parallel test executor of with +size+ workers.
|
initialize
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/parallel.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/parallel.rb
|
Apache-2.0
|
def shutdown
size.times { @queue << nil }
@pool.each(&:join)
end
|
#
Shuts down the pool of workers by signalling them to quit and
waiting for them all to finish what they're currently working
on.
|
shutdown
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/parallel.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/parallel.rb
|
Apache-2.0
|
def print o
case o
when "." then
io.print pride o
when "E", "F" then
io.print "#{ESC}41m#{ESC}37m#{o}#{NND}"
when "S" then
io.print pride o
else
io.print o
end
end
|
#
Wrap print to colorize the output.
|
print
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/pride_plugin.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/pride_plugin.rb
|
Apache-2.0
|
def pride string
c = @colors[@index % @size]
@index += 1
"#{ESC}38;5;#{c}m#{string}#{NND}"
end
|
#
Make the string even more colorful. Damnit.
|
pride
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/pride_plugin.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/pride_plugin.rb
|
Apache-2.0
|
def describe desc, *additional_desc, &block # :doc:
stack = Minitest::Spec.describe_stack
name = [stack.last, desc, *additional_desc].compact.join("::")
sclas = stack.last || if Class === self && kind_of?(Minitest::Spec::DSL) then
self
else
Minitest::Spec.spec_type desc, *additional_desc
end
cls = sclas.create name, desc
stack.push cls
cls.class_eval(&block)
stack.pop
cls
end
|
#
Describe a series of expectations for a given target +desc+.
Defines a test class subclassing from either Minitest::Spec or
from the surrounding describe's class. The surrounding class may
subclass Minitest::Spec manually in order to easily share code:
class MySpec < Minitest::Spec
# ... shared code ...
end
class TestStuff < MySpec
it "does stuff" do
# shared code available here
end
describe "inner stuff" do
it "still does stuff" do
# ...and here
end
end
end
For more information on getting started with writing specs, see:
http://www.rubyinside.com/a-minitestspec-tutorial-elegant-spec-style-testing-that-comes-with-ruby-5354.html
For some suggestions on how to improve your specs, try:
https://betterspecs.org
but do note that several items there are debatable or specific to
rspec.
For more information about expectations, see Minitest::Expectations.
|
describe
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/spec.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/spec.rb
|
Apache-2.0
|
def register_spec_type *args, &block
if block then
matcher, klass = block, args.first
else
matcher, klass = *args
end
TYPES.unshift [matcher, klass]
end
|
#
Register a new type of spec that matches the spec's description.
This method can take either a Regexp and a spec class or a spec
class and a block that takes the description and returns true if
it matches.
Eg:
register_spec_type(/Controller$/, Minitest::Spec::Rails)
or:
register_spec_type(Minitest::Spec::RailsModel) do |desc|
desc.superclass == ActiveRecord::Base
end
|
register_spec_type
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/spec.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/spec.rb
|
Apache-2.0
|
def spec_type desc, *additional
TYPES.find { |matcher, _klass|
if matcher.respond_to? :call then
matcher.call desc, *additional
else
matcher === desc.to_s
end
}.last
end
|
#
Figure out the spec class to use based on a spec's description. Eg:
spec_type("BlahController") # => Minitest::Spec::Rails
|
spec_type
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/spec.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/spec.rb
|
Apache-2.0
|
def before _type = nil, &block
define_method :setup do
super()
self.instance_eval(&block)
end
end
|
#
Define a 'before' action. Inherits the way normal methods should.
NOTE: +type+ is ignored and is only there to make porting easier.
Equivalent to Minitest::Test#setup.
|
before
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/spec.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/spec.rb
|
Apache-2.0
|
def after _type = nil, &block
define_method :teardown do
self.instance_eval(&block)
super()
end
end
|
#
Define an 'after' action. Inherits the way normal methods should.
NOTE: +type+ is ignored and is only there to make porting easier.
Equivalent to Minitest::Test#teardown.
|
after
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/spec.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/spec.rb
|
Apache-2.0
|
def it desc = "anonymous", &block
block ||= proc { skip "(no tests defined)" }
@specs ||= 0
@specs += 1
name = "test_%04d_%s" % [ @specs, desc ]
undef_klasses = self.children.reject { |c| c.public_method_defined? name }
define_method name, &block
undef_klasses.each do |undef_klass|
undef_klass.send :undef_method, name
end
name
end
|
#
Define an expectation with name +desc+. Name gets morphed to a
proper test method name. For some freakish reason, people who
write specs don't like class inheritance, so this goes way out of
its way to make sure that expectations aren't inherited.
This is also aliased to #specify and doesn't require a +desc+ arg.
Hint: If you _do_ want inheritance, use minitest/test. You can mix
and match between assertions and expectations as much as you want.
|
it
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/spec.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/spec.rb
|
Apache-2.0
|
def let name, &block
name = name.to_s
pre, post = "let '#{name}' cannot ", ". Please use another name."
methods = Minitest::Spec.instance_methods.map(&:to_s) - %w[subject]
raise ArgumentError, "#{pre}begin with 'test'#{post}" if
name =~ /\Atest/
raise ArgumentError, "#{pre}override a method in Minitest::Spec#{post}" if
methods.include? name
define_method name do
@_memoized ||= {}
@_memoized.fetch(name) { |k| @_memoized[k] = instance_eval(&block) }
end
end
|
#
Essentially, define an accessor for +name+ with +block+.
Why use let instead of def? I honestly don't know.
|
let
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/spec.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/spec.rb
|
Apache-2.0
|
def subject &block
let :subject, &block
end
|
#
Another lazy man's accessor generator. Made even more lazy by
setting the name for you to +subject+.
|
subject
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/spec.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/spec.rb
|
Apache-2.0
|
def _ value = nil, &block
Minitest::Expectation.new block || value, self
end
|
#
Takes a value or a block and returns a value monad that has
all of Expectations methods available to it.
_(1 + 1).must_equal 2
And for blocks:
_ { 1 + "1" }.must_raise TypeError
This method of expectation-based testing is preferable to
straight-expectation methods (on Object) because it stores its
test context, bypassing our hacky use of thread-local variables.
NOTE: At some point, the methods on Object will be deprecated
and then removed.
It is also aliased to #value and #expect for your aesthetic
pleasure:
_(1 + 1).must_equal 2
value(1 + 1).must_equal 2
expect(1 + 1).must_equal 2
|
_
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/spec.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/spec.rb
|
Apache-2.0
|
def run
with_info_handler do
time_it do
capture_exceptions do
SETUP_METHODS.each do |hook|
self.send hook
end
self.send self.name
end
TEARDOWN_METHODS.each do |hook|
capture_exceptions do
self.send hook
end
end
end
end
Result.from self # per contract
end
|
#
Runs a single test with setup/teardown hooks.
|
run
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/test.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/test.rb
|
Apache-2.0
|
def process_env
warn "TESTOPTS is deprecated in Minitest::TestTask. Use A instead" if
ENV["TESTOPTS"]
warn "FILTER is deprecated in Minitest::TestTask. Use A instead" if
ENV["FILTER"]
warn "N is deprecated in Minitest::TestTask. Use MT_CPU instead" if
ENV["N"] && ENV["N"].to_i > 0
lib_extras = (ENV["MT_LIB_EXTRAS"] || "").split File::PATH_SEPARATOR
self.libs[0,0] = lib_extras
extra_args << "-n" << ENV["N"] if ENV["N"]
extra_args << "-e" << ENV["X"] if ENV["X"]
extra_args.concat Shellwords.split(ENV["TESTOPTS"]) if ENV["TESTOPTS"]
extra_args.concat Shellwords.split(ENV["FILTER"]) if ENV["FILTER"]
extra_args.concat Shellwords.split(ENV["A"]) if ENV["A"]
ENV.delete "N" if ENV["N"]
# TODO? RUBY_DEBUG = ENV["RUBY_DEBUG"]
# TODO? ENV["RUBY_FLAGS"]
extra_args.compact!
end
|
#
Extract variables from the environment and convert them to
command line arguments. See #extra_args.
Environment Variables:
MT_LIB_EXTRAS :: Extra libs to dynamically override/inject for custom runs.
N :: Tests to run (string or /regexp/).
X :: Tests to exclude (string or /regexp/).
A :: Any extra arguments. Honors shell quoting.
Deprecated:
TESTOPTS :: For argument passing, use +A+.
N :: For parallel testing, use +MT_CPU+.
FILTER :: Same as +TESTOPTS+.
|
process_env
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/test_task.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/lib/minitest/test_task.rb
|
Apache-2.0
|
def test_assert_raises_skip
@assertion_count = 0
assert_triggered "skipped", Minitest::Skip do
@tc.assert_raises ArgumentError do
begin
raise "blah"
rescue
skip "skipped"
end
end
end
end
|
#
*sigh* This is quite an odd scenario, but it is from real (albeit
ugly) test code in ruby-core:
https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=29259
|
test_assert_raises_skip
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/test/minitest/test_minitest_assertions.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/test/minitest/test_minitest_assertions.rb
|
Apache-2.0
|
def setup
super
Minitest::Test.reset
@tc = Minitest::Test.new "fake tc"
@assertion_count = 1
end
|
Do not parallelize since we're calling stub on class methods
|
setup
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/test/minitest/test_minitest_mock.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/test/minitest/test_minitest_mock.rb
|
Apache-2.0
|
def assert_triggered expected = "blah", klass = Minitest::Assertion
@assertion_count += 1
e = assert_raises(klass) do
yield
end
msg = e.message.sub(/(---Backtrace---).*/m, '\1')
msg.gsub!(/\(oid=[-0-9]+\)/, "(oid=N)")
msg.gsub!(/(\d\.\d{6})\d+/, '\1xxx') # normalize: ruby version, impl, platform
msg.gsub!(/:0x[Xa-fA-F0-9]{4,}[ @].+?>/, ":0xXXXXXX@PATH>")
if expected
@assertion_count += 1
case expected
when String then
assert_equal expected, msg
when Regexp then
@assertion_count += 1
assert_match expected, msg
else
flunk "Unknown: #{expected.inspect}"
end
end
end
|
do not parallelize this suite... it just can"t handle it.
|
assert_triggered
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/test/minitest/test_minitest_spec.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/test/minitest/test_minitest_spec.rb
|
Apache-2.0
|
def assert_defined_methods expected, klass
assert_equal expected, klass.instance_methods(false).sort.map(&:to_s)
end
|
do not call parallelize_me! here because specs use register_spec_type globally
|
assert_defined_methods
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/test/minitest/test_minitest_spec.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/minitest-5.18.0/test/minitest/test_minitest_spec.rb
|
Apache-2.0
|
def try_package_configuration(pc)
unless ENV.key?("NOKOGIRI_TEST_PKG_CONFIG_GEM")
# try MakeMakefile#pkg_config, which uses the system utility `pkg-config`.
return if checking_for("#{pc} using `pkg_config`", LOCAL_PACKAGE_RESPONSE) do
pkg_config(pc)
end
end
# `pkg-config` probably isn't installed, which appears to be the case for lots of freebsd systems.
# let's fall back to the pkg-config gem, which knows how to parse .pc files, and wrap it with the
# same logic as MakeMakefile#pkg_config
begin
require "rubygems"
gem("pkg-config", REQUIRED_PKG_CONFIG_VERSION)
require "pkg-config"
checking_for("#{pc} using pkg-config gem version #{PKGConfig::VERSION}", LOCAL_PACKAGE_RESPONSE) do
if PKGConfig.have_package(pc)
cflags = PKGConfig.cflags(pc)
ldflags = PKGConfig.libs_only_L(pc)
libs = PKGConfig.libs_only_l(pc)
Logging.message("pkg-config gem found package configuration for %s\n", pc)
Logging.message("cflags: %s\nldflags: %s\nlibs: %s\n\n", cflags, ldflags, libs)
[cflags, ldflags, libs]
end
end
rescue LoadError
message("Please install either the `pkg-config` utility or the `pkg-config` rubygem.\n")
end
end
|
wrapper around MakeMakefil#pkg_config and the PKGConfig gem
|
try_package_configuration
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/nokogiri-1.13.10-x86_64-linux/ext/nokogiri/extconf.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/nokogiri-1.13.10-x86_64-linux/ext/nokogiri/extconf.rb
|
Apache-2.0
|
def have_package_configuration(opt: nil, pc: nil, lib:, func:, headers:)
if opt
dir_config(opt)
dir_config("opt")
end
# see if we have enough path info to do this without trying any harder
unless ENV.key?("NOKOGIRI_TEST_PKG_CONFIG")
return true if local_have_library(lib, func, headers)
end
try_package_configuration(pc) if pc
# verify that we can compile and link against the library
local_have_library(lib, func, headers)
end
|
set up mkmf to link against the library if we can find it
|
have_package_configuration
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/nokogiri-1.13.10-x86_64-linux/ext/nokogiri/extconf.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/nokogiri-1.13.10-x86_64-linux/ext/nokogiri/extconf.rb
|
Apache-2.0
|
def parse(thing, url = nil, encoding = nil, options = ParseOptions::DEFAULT_XML, &block)
Document.parse(thing, url, encoding, options, &block)
end
|
##
Parse XML. Convenience method for Nokogiri::XML::Document.parse
|
parse
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/nokogiri-1.13.10-x86_64-linux/lib/nokogiri/xml.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/nokogiri-1.13.10-x86_64-linux/lib/nokogiri/xml.rb
|
Apache-2.0
|
def fragment(string, options = ParseOptions::DEFAULT_XML, &block)
XML::DocumentFragment.parse(string, options, &block)
end
|
###
Parse a fragment from +string+ in to a NodeSet.
|
fragment
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/nokogiri-1.13.10-x86_64-linux/lib/nokogiri/xml.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/nokogiri-1.13.10-x86_64-linux/lib/nokogiri/xml.rb
|
Apache-2.0
|
def parse(string, modules = {})
modules.each do |url, klass|
XSLT.register(url, klass)
end
doc = XML::Document.parse(string, nil, nil, XML::ParseOptions::DEFAULT_XSLT)
if Nokogiri.jruby?
Stylesheet.parse_stylesheet_doc(doc, string)
else
Stylesheet.parse_stylesheet_doc(doc)
end
end
|
##
Parse the stylesheet in +string+, register any +modules+
|
parse
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/nokogiri-1.13.10-x86_64-linux/lib/nokogiri/xslt.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/nokogiri-1.13.10-x86_64-linux/lib/nokogiri/xslt.rb
|
Apache-2.0
|
def initialize(type, value)
@type = type
@value = value
end
|
Create a new Node with +type+ and +value+
|
initialize
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/nokogiri-1.13.10-x86_64-linux/lib/nokogiri/css/node.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/nokogiri-1.13.10-x86_64-linux/lib/nokogiri/css/node.rb
|
Apache-2.0
|
def to_xpath(prefix, visitor)
prefix = "." if ALLOW_COMBINATOR_ON_SELF.include?(type) && value.first.nil?
prefix + visitor.accept(self)
end
|
##
Convert this CSS node to xpath with +prefix+ using +visitor+
|
to_xpath
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/nokogiri-1.13.10-x86_64-linux/lib/nokogiri/css/node.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/nokogiri-1.13.10-x86_64-linux/lib/nokogiri/css/node.rb
|
Apache-2.0
|
def find_by_type(types)
matches = []
matches << self if to_type == types
@value.each do |v|
matches += v.find_by_type(types) if v.respond_to?(:find_by_type)
end
matches
end
|
Find a node by type using +types+
|
find_by_type
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/nokogiri-1.13.10-x86_64-linux/lib/nokogiri/css/node.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/nokogiri-1.13.10-x86_64-linux/lib/nokogiri/css/node.rb
|
Apache-2.0
|
def set_cache(value) # rubocop:disable Naming/AccessorMethodName
Thread.current[CACHE_SWITCH_NAME] = !value
end
|
Set a thread-local boolean to turn cacheing on and off. Truthy values turn the cache on, falsey values turn the cache off.
|
set_cache
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/nokogiri-1.13.10-x86_64-linux/lib/nokogiri/css/parser_extras.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/nokogiri-1.13.10-x86_64-linux/lib/nokogiri/css/parser_extras.rb
|
Apache-2.0
|
def initialize(namespaces = {})
@tokenizer = Tokenizer.new
@namespaces = namespaces
super()
end
|
Create a new CSS parser with respect to +namespaces+
|
initialize
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/nokogiri-1.13.10-x86_64-linux/lib/nokogiri/css/parser_extras.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/nokogiri-1.13.10-x86_64-linux/lib/nokogiri/css/parser_extras.rb
|
Apache-2.0
|
def xpath_for(string, prefix, visitor)
key = cache_key(string, prefix, visitor)
self.class[key] ||= parse(string).map do |ast|
ast.to_xpath(prefix, visitor)
end
end
|
Get the xpath for +string+ using +options+
|
xpath_for
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/nokogiri-1.13.10-x86_64-linux/lib/nokogiri/css/parser_extras.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/nokogiri-1.13.10-x86_64-linux/lib/nokogiri/css/parser_extras.rb
|
Apache-2.0
|
def on_error(error_token_id, error_value, value_stack)
after = value_stack.compact.last
raise SyntaxError, "unexpected '#{error_value}' after '#{after}'"
end
|
On CSS parser error, raise an exception
|
on_error
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/nokogiri-1.13.10-x86_64-linux/lib/nokogiri/css/parser_extras.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/nokogiri-1.13.10-x86_64-linux/lib/nokogiri/css/parser_extras.rb
|
Apache-2.0
|
def method_missing(name, *args, &block)
if args.empty?
list = xpath("#{XPATH_PREFIX}#{name.to_s.sub(/^_/, "")}")
elsif args.first.is_a?(Hash)
hash = args.first
if hash[:css]
list = css("#{name}#{hash[:css]}")
elsif hash[:xpath]
conds = Array(hash[:xpath]).join(" and ")
list = xpath("#{XPATH_PREFIX}#{name}[#{conds}]")
end
else
CSS::Parser.without_cache do
list = xpath(
*CSS.xpath_for("#{name}#{args.first}", prefix: XPATH_PREFIX)
)
end
end
super if list.empty?
list.length == 1 ? list.first : list
end
|
##
look for node with +name+. See Nokogiri.Slop
|
method_missing
|
ruby
|
collabnix/kubelabs
|
.bundles_cache/ruby/2.6.0/gems/nokogiri-1.13.10-x86_64-linux/lib/nokogiri/decorators/slop.rb
|
https://github.com/collabnix/kubelabs/blob/master/.bundles_cache/ruby/2.6.0/gems/nokogiri-1.13.10-x86_64-linux/lib/nokogiri/decorators/slop.rb
|
Apache-2.0
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.