Skip to content

Commit

Permalink
[rubygems/rubygems] util/rubocop -A --only Style/NumericLiterals
Browse files Browse the repository at this point in the history
  • Loading branch information
hsbt committed Mar 17, 2023
1 parent 712d6e6 commit d2cebb4
Show file tree
Hide file tree
Showing 12 changed files with 46 additions and 46 deletions.
6 changes: 3 additions & 3 deletions lib/rubygems/package.rb
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ def add_files(tar) # :nodoc:

tar.add_file_simple file, stat.mode, stat.size do |dst_io|
File.open file, "rb" do |src_io|
dst_io.write src_io.read 16384 until src_io.eof?
dst_io.write src_io.read 16_384 until src_io.eof?
end
end
end
Expand Down Expand Up @@ -362,7 +362,7 @@ def digest(entry) # :nodoc:
algorithms.each do |algorithm|
digester = Gem::Security.create_digest(algorithm)

digester << entry.read(16384) until entry.eof?
digester << entry.read(16_384) until entry.eof?

entry.rewind

Expand Down Expand Up @@ -701,7 +701,7 @@ def verify_files(gem)

def verify_gz(entry) # :nodoc:
Zlib::GzipReader.wrap entry do |gzio|
gzio.read 16384 until gzio.eof? # gzip checksum verification
gzio.read 16_384 until gzio.eof? # gzip checksum verification
end
rescue Zlib::GzipFile::Error => e
raise Gem::Package::FormatError.new(e.message, entry.full_name)
Expand Down
2 changes: 1 addition & 1 deletion lib/rubygems/s3_uri_signer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def initialize(uri)

##
# Signs S3 URI using query-params according to the reference: https://docs.aws.amazon.com/AmazonS3/latest/API/sigv4-query-string-auth.html
def sign(expiration = 86400)
def sign(expiration = 86_400)
s3_config = fetch_s3_config

current_time = Time.now.utc
Expand Down
2 changes: 1 addition & 1 deletion lib/rubygems/security.rb
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ class Exception < Gem::Exception; end
##
# One day in seconds

ONE_DAY = 86400
ONE_DAY = 86_400

##
# One year in seconds
Expand Down
2 changes: 1 addition & 1 deletion test/rubygems/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -934,7 +934,7 @@ def util_make_gems(prerelease = false)
@a1 = quick_gem "a", "1" do |s|
s.files = %w[lib/code.rb]
s.require_paths = %w[lib]
s.date = Gem::Specification::TODAY - 86400
s.date = Gem::Specification::TODAY - 86_400
s.homepage = "http://a.example.com"
s.email = %w[example@example.com example2@example.com]
s.authors = %w[Example Example2]
Expand Down
8 changes: 4 additions & 4 deletions test/rubygems/test_gem.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1053,15 +1053,15 @@ def test_self_env_requirement
end

def test_self_ruby_version_with_non_mri_implementations
util_set_RUBY_VERSION "2.5.0", 0, 60928, "jruby 9.2.0.0 (2.5.0) 2018-05-24 81156a8 OpenJDK 64-Bit Server VM 25.171-b11 on 1.8.0_171-8u171-b11-0ubuntu0.16.04.1-b11 [linux-x86_64]"
util_set_RUBY_VERSION "2.5.0", 0, 60_928, "jruby 9.2.0.0 (2.5.0) 2018-05-24 81156a8 OpenJDK 64-Bit Server VM 25.171-b11 on 1.8.0_171-8u171-b11-0ubuntu0.16.04.1-b11 [linux-x86_64]"

assert_equal Gem::Version.new("2.5.0"), Gem.ruby_version
ensure
util_restore_RUBY_VERSION
end

def test_self_ruby_version_with_svn_prerelease
util_set_RUBY_VERSION "2.6.0", -1, 63539, "ruby 2.6.0preview2 (2018-05-31 trunk 63539) [x86_64-linux]"
util_set_RUBY_VERSION "2.6.0", -1, 63_539, "ruby 2.6.0preview2 (2018-05-31 trunk 63539) [x86_64-linux]"

assert_equal Gem::Version.new("2.6.0.preview2"), Gem.ruby_version
ensure
Expand All @@ -1077,15 +1077,15 @@ def test_self_ruby_version_with_git_prerelease
end

def test_self_ruby_version_with_non_mri_implementations_with_mri_prerelase_compatibility
util_set_RUBY_VERSION "2.6.0", -1, 63539, "weirdjruby 9.2.0.0 (2.6.0preview2) 2018-05-24 81156a8 OpenJDK 64-Bit Server VM 25.171-b11 on 1.8.0_171-8u171-b11-0ubuntu0.16.04.1-b11 [linux-x86_64]", "weirdjruby", "9.2.0.0"
util_set_RUBY_VERSION "2.6.0", -1, 63_539, "weirdjruby 9.2.0.0 (2.6.0preview2) 2018-05-24 81156a8 OpenJDK 64-Bit Server VM 25.171-b11 on 1.8.0_171-8u171-b11-0ubuntu0.16.04.1-b11 [linux-x86_64]", "weirdjruby", "9.2.0.0"

assert_equal Gem::Version.new("2.6.0.preview2"), Gem.ruby_version
ensure
util_restore_RUBY_VERSION
end

def test_self_ruby_version_with_svn_trunk
util_set_RUBY_VERSION "1.9.2", -1, 23493, "ruby 1.9.2dev (2009-05-20 trunk 23493) [x86_64-linux]"
util_set_RUBY_VERSION "1.9.2", -1, 23_493, "ruby 1.9.2dev (2009-05-20 trunk 23493) [x86_64-linux]"

assert_equal Gem::Version.new("1.9.2.dev"), Gem.ruby_version
ensure
Expand Down
2 changes: 1 addition & 1 deletion test/rubygems/test_gem_commands_stale_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def test_execute_sorts

filename = File.join(foo_bar.full_gem_path, file)
FileUtils.mkdir_p File.dirname filename
FileUtils.touch(filename, :mtime => Time.now - 86400)
FileUtils.touch(filename, :mtime => Time.now - 86_400)
end

use_ui @stub_ui do
Expand Down
2 changes: 1 addition & 1 deletion test/rubygems/test_gem_indexer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def setup
util_make_gems

@d2_0 = util_spec "d", "2.0" do |s|
s.date = Gem::Specification::TODAY - 86400 * 3
s.date = Gem::Specification::TODAY - 86_400 * 3
end
util_build_gem @d2_0

Expand Down
4 changes: 2 additions & 2 deletions test/rubygems/test_gem_package.rb
Original file line number Diff line number Diff line change
Expand Up @@ -643,8 +643,8 @@ def test_extract_symlink_parent_doesnt_delete_user_dir
pend "TMPDIR seems too long to add it as symlink into tar" if destination_user_dir.size > 90

tgz_io = util_tar_gz do |tar|
tar.add_symlink "link", destination_user_dir, 16877
tar.add_symlink "link/dir", ".", 16877
tar.add_symlink "link", destination_user_dir, 16_877
tar.add_symlink "link/dir", ".", 16_877
end

expected_exceptions = win_platform? ? [Gem::Package::SymlinkError, Errno::EACCES] : [Gem::Package::SymlinkError]
Expand Down
14 changes: 7 additions & 7 deletions test/rubygems/test_gem_package_tar_header.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ def setup
:name => "x",
:mode => 0644,
:uid => 1000,
:gid => 10000,
:gid => 10_000,
:size => 100,
:mtime => 12345,
:mtime => 12_345,
:typeflag => "0",
:linkname => "link",
:uname => "user",
Expand All @@ -39,12 +39,12 @@ def test_initialize
assert_equal "", @tar_header.checksum, "checksum"
assert_equal 1, @tar_header.devmajor, "devmajor"
assert_equal 2, @tar_header.devminor, "devminor"
assert_equal 10000, @tar_header.gid, "gid"
assert_equal 10_000, @tar_header.gid, "gid"
assert_equal "group", @tar_header.gname, "gname"
assert_equal "link", @tar_header.linkname, "linkname"
assert_equal "ustar", @tar_header.magic, "magic"
assert_equal 0644, @tar_header.mode, "mode"
assert_equal 12345, @tar_header.mtime, "mtime"
assert_equal 12_345, @tar_header.mtime, "mtime"
assert_equal "x", @tar_header.name, "name"
assert_equal "y", @tar_header.prefix, "prefix"
assert_equal 100, @tar_header.size, "size"
Expand Down Expand Up @@ -195,13 +195,13 @@ def test_big_uid_gid

tar_header = Gem::Package::TarHeader.from stream

assert_equal 1991400094, tar_header.uid
assert_equal 1991400094, tar_header.gid
assert_equal 1_991_400_094, tar_header.uid
assert_equal 1_991_400_094, tar_header.gid

assert_equal "GeoIP2-City_20190528/", tar_header.name
assert_equal 0755, tar_header.mode
assert_equal 0, tar_header.size
assert_equal 1559064640, tar_header.mtime
assert_equal 1_559_064_640, tar_header.mtime
assert_equal 6932, tar_header.checksum
end

Expand Down
26 changes: 13 additions & 13 deletions test/rubygems/test_gem_package_tar_writer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def teardown
end

def test_add_file
Time.stub :now, Time.at(1458518157) do
Time.stub :now, Time.at(1_458_518_157) do
@tar_writer.add_file "x", 0644 do |f|
f.write "a" * 10
end
Expand All @@ -41,7 +41,7 @@ def test_add_file

def test_add_file_source_date_epoch
ENV["SOURCE_DATE_EPOCH"] = "123456789"
Time.stub :now, Time.at(1458518157) do
Time.stub :now, Time.at(1_458_518_157) do
@tar_writer.mkdir "foo", 0644

assert_headers_equal tar_dir_header("foo", "", 0644, Time.at(ENV["SOURCE_DATE_EPOCH"].to_i).utc),
Expand All @@ -50,7 +50,7 @@ def test_add_file_source_date_epoch
end

def test_add_symlink
Time.stub :now, Time.at(1458518157) do
Time.stub :now, Time.at(1_458_518_157) do
@tar_writer.add_symlink "x", "y", 0644

assert_headers_equal(tar_symlink_header("x", "", 0644, Time.now, "y"),
Expand All @@ -61,7 +61,7 @@ def test_add_symlink

def test_add_symlink_source_date_epoch
ENV["SOURCE_DATE_EPOCH"] = "123456789"
Time.stub :now, Time.at(1458518157) do
Time.stub :now, Time.at(1_458_518_157) do
@tar_writer.add_symlink "x", "y", 0644

assert_headers_equal(tar_symlink_header("x", "", 0644, Time.at(ENV["SOURCE_DATE_EPOCH"].to_i).utc, "y"),
Expand All @@ -72,7 +72,7 @@ def test_add_symlink_source_date_epoch
def test_add_file_digest
digest_algorithms = OpenSSL::Digest::SHA1.new, OpenSSL::Digest::SHA512.new

Time.stub :now, Time.at(1458518157) do
Time.stub :now, Time.at(1_458_518_157) do
digests = @tar_writer.add_file_digest "x", 0644, digest_algorithms do |io|
io.write "a" * 10
end
Expand All @@ -95,7 +95,7 @@ def test_add_file_digest
def test_add_file_digest_multiple
digest_algorithms = [OpenSSL::Digest::SHA1.new, OpenSSL::Digest::SHA512.new]

Time.stub :now, Time.at(1458518157) do
Time.stub :now, Time.at(1_458_518_157) do
digests = @tar_writer.add_file_digest "x", 0644, digest_algorithms do |io|
io.write "a" * 10
end
Expand All @@ -120,7 +120,7 @@ def test_add_file_signer

signer = Gem::Security::Signer.new PRIVATE_KEY, [PUBLIC_CERT]

Time.stub :now, Time.at(1458518157) do
Time.stub :now, Time.at(1_458_518_157) do
@tar_writer.add_file_signed "x", 0644, signer do |io|
io.write "a" * 10
end
Expand Down Expand Up @@ -148,7 +148,7 @@ def test_add_file_signer
def test_add_file_signer_empty
signer = Gem::Security::Signer.new nil, nil

Time.stub :now, Time.at(1458518157) do
Time.stub :now, Time.at(1_458_518_157) do
@tar_writer.add_file_signed "x", 0644, signer do |io|
io.write "a" * 10
end
Expand All @@ -162,7 +162,7 @@ def test_add_file_signer_empty
end

def test_add_file_simple
Time.stub :now, Time.at(1458518157) do
Time.stub :now, Time.at(1_458_518_157) do
@tar_writer.add_file_simple "x", 0644, 10 do |io|
io.write "a" * 10
end
Expand All @@ -177,7 +177,7 @@ def test_add_file_simple

def test_add_file_simple_source_date_epoch
ENV["SOURCE_DATE_EPOCH"] = "123456789"
Time.stub :now, Time.at(1458518157) do
Time.stub :now, Time.at(1_458_518_157) do
@tar_writer.add_file_simple "x", 0644, 10 do |io|
io.write "a" * 10
end
Expand All @@ -188,7 +188,7 @@ def test_add_file_simple_source_date_epoch
end

def test_add_file_simple_padding
Time.stub :now, Time.at(1458518157) do
Time.stub :now, Time.at(1_458_518_157) do
@tar_writer.add_file_simple "x", 0, 100

assert_headers_equal tar_file_header("x", "", 0, 100, Time.now),
Expand Down Expand Up @@ -246,7 +246,7 @@ def test_close
end

def test_mkdir
Time.stub :now, Time.at(1458518157) do
Time.stub :now, Time.at(1_458_518_157) do
@tar_writer.mkdir "foo", 0644

assert_headers_equal tar_dir_header("foo", "", 0644, Time.now),
Expand All @@ -258,7 +258,7 @@ def test_mkdir

def test_mkdir_source_date_epoch
ENV["SOURCE_DATE_EPOCH"] = "123456789"
Time.stub :now, Time.at(1458518157) do
Time.stub :now, Time.at(1_458_518_157) do
@tar_writer.mkdir "foo", 0644

assert_headers_equal tar_dir_header("foo", "", 0644, Time.at(ENV["SOURCE_DATE_EPOCH"].to_i).utc),
Expand Down
20 changes: 10 additions & 10 deletions test/rubygems/test_gem_remote_fetcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,7 @@ def test_fetch_s3_config_creds
"my-bucket" => { :id => "testuser", :secret => "testpass" },
}
url = "s3://my-bucket/gems/specs.4.8.gz"
Time.stub :now, Time.at(1561353581) do
Time.stub :now, Time.at(1_561_353_581) do
assert_fetch_s3 url, "20f974027db2f3cd6193565327a7c73457a138efb1a63ea248d185ce6827d41b"
end
ensure
Expand All @@ -760,7 +760,7 @@ def test_fetch_s3_config_creds_with_region
"my-bucket" => { :id => "testuser", :secret => "testpass", :region => "us-west-2" },
}
url = "s3://my-bucket/gems/specs.4.8.gz"
Time.stub :now, Time.at(1561353581) do
Time.stub :now, Time.at(1_561_353_581) do
assert_fetch_s3 url, "4afc3010757f1fd143e769f1d1dabd406476a4fc7c120e9884fd02acbb8f26c9", nil, "us-west-2"
end
ensure
Expand All @@ -772,7 +772,7 @@ def test_fetch_s3_config_creds_with_token
"my-bucket" => { :id => "testuser", :secret => "testpass", :security_token => "testtoken" },
}
url = "s3://my-bucket/gems/specs.4.8.gz"
Time.stub :now, Time.at(1561353581) do
Time.stub :now, Time.at(1_561_353_581) do
assert_fetch_s3 url, "935160a427ef97e7630f799232b8f208c4a4e49aad07d0540572a2ad5fe9f93c", "testtoken"
end
ensure
Expand All @@ -787,7 +787,7 @@ def test_fetch_s3_env_creds
"my-bucket" => { :provider => "env" },
}
url = "s3://my-bucket/gems/specs.4.8.gz"
Time.stub :now, Time.at(1561353581) do
Time.stub :now, Time.at(1_561_353_581) do
assert_fetch_s3 url, "20f974027db2f3cd6193565327a7c73457a138efb1a63ea248d185ce6827d41b"
end
ensure
Expand All @@ -803,7 +803,7 @@ def test_fetch_s3_env_creds_with_region
"my-bucket" => { :provider => "env", :region => "us-west-2" },
}
url = "s3://my-bucket/gems/specs.4.8.gz"
Time.stub :now, Time.at(1561353581) do
Time.stub :now, Time.at(1_561_353_581) do
assert_fetch_s3 url, "4afc3010757f1fd143e769f1d1dabd406476a4fc7c120e9884fd02acbb8f26c9", nil, "us-west-2"
end
ensure
Expand All @@ -819,7 +819,7 @@ def test_fetch_s3_env_creds_with_token
"my-bucket" => { :provider => "env" },
}
url = "s3://my-bucket/gems/specs.4.8.gz"
Time.stub :now, Time.at(1561353581) do
Time.stub :now, Time.at(1_561_353_581) do
assert_fetch_s3 url, "935160a427ef97e7630f799232b8f208c4a4e49aad07d0540572a2ad5fe9f93c", "testtoken"
end
ensure
Expand All @@ -829,7 +829,7 @@ def test_fetch_s3_env_creds_with_token

def test_fetch_s3_url_creds
url = "s3://testuser:testpass@my-bucket/gems/specs.4.8.gz"
Time.stub :now, Time.at(1561353581) do
Time.stub :now, Time.at(1_561_353_581) do
assert_fetch_s3 url, "20f974027db2f3cd6193565327a7c73457a138efb1a63ea248d185ce6827d41b"
end
end
Expand All @@ -840,7 +840,7 @@ def test_fetch_s3_instance_profile_creds
}

url = "s3://my-bucket/gems/specs.4.8.gz"
Time.stub :now, Time.at(1561353581) do
Time.stub :now, Time.at(1_561_353_581) do
assert_fetch_s3 url, "20f974027db2f3cd6193565327a7c73457a138efb1a63ea248d185ce6827d41b", nil, "us-east-1",
'{"AccessKeyId": "testuser", "SecretAccessKey": "testpass"}'
end
Expand All @@ -854,7 +854,7 @@ def test_fetch_s3_instance_profile_creds_with_region
}

url = "s3://my-bucket/gems/specs.4.8.gz"
Time.stub :now, Time.at(1561353581) do
Time.stub :now, Time.at(1_561_353_581) do
assert_fetch_s3 url, "4afc3010757f1fd143e769f1d1dabd406476a4fc7c120e9884fd02acbb8f26c9", nil, "us-west-2",
'{"AccessKeyId": "testuser", "SecretAccessKey": "testpass"}'
end
Expand All @@ -868,7 +868,7 @@ def test_fetch_s3_instance_profile_creds_with_token
}

url = "s3://my-bucket/gems/specs.4.8.gz"
Time.stub :now, Time.at(1561353581) do
Time.stub :now, Time.at(1_561_353_581) do
assert_fetch_s3 url, "935160a427ef97e7630f799232b8f208c4a4e49aad07d0540572a2ad5fe9f93c", "testtoken", "us-east-1",
'{"AccessKeyId": "testuser", "SecretAccessKey": "testpass", "Token": "testtoken"}'
end
Expand Down
4 changes: 2 additions & 2 deletions test/rubygems/test_gem_update_suggestion.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ def test_update_suggestion

def test_eglible_for_update
with_eglible_environment(cmd: @cmd) do
Time.stub :now, 123456789 do
Time.stub :now, 123_456_789 do
assert @cmd.eglible_for_update?
assert_equal Gem.configuration.last_update_check, 123456789
assert_equal Gem.configuration.last_update_check, 123_456_789

# test last check is written to config file
assert File.read(Gem.configuration.state_file_name).match("123456789")
Expand Down

0 comments on commit d2cebb4

Please sign in to comment.