0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

[py2rb] warnings.catch_warnings(record=True)

Last updated at Posted at 2022-02-10

はじめに

移植やってます。
( from python 3.7 to ruby 2.7 )

warnings (Python)

        with warnings.catch_warnings(record=True) as w:
            warnings.simplefilter('always')
            result = aux._check_use_index(fo, None, None)
            self.assertEqual(len(w), 0)

やっていることは、警告を発生させてその回数を確認している様子。

どうすRuby

module Warning
  def self.warn(message, category: nil)
    @count += 1
  end

  def count
    @count
  end

  def reset_count
    @count = 0
  end
end

Warning.reset_count
10.times do |i|
  warn i
end
puts Warning.count

# 10

オープンクラスでやっちゃいました。

メモ

  • Python の warnings を学習した
  • 百里を行く者は九十里を半ばとす
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?