[SCM] ci-tooling packaging branch, master, updated. 760f4a85682d57dd5f3abeccfe0a4f60f2368efc

Harald Sitter apachelogger-guest at moszumanska.debian.org
Mon Mar 23 13:22:36 UTC 2015


Gitweb-URL: http://git.debian.org/?p=pkg-kde/ci-tooling.git;a=commitdiff;h=760f4a8

The following commit has been merged in the master branch:
commit 760f4a85682d57dd5f3abeccfe0a4f60f2368efc
Author: Harald Sitter <sitter at kde.org>
Date:   Mon Mar 23 14:22:32 2015 +0100

    move heavily duplicated setup/teardown to a common testcase class
    
    all tests should inerhit testcase from now on. alas, due to split repos
    pangea would have a hard time with that so it is presently not enforced
    by a test of its own
    
    - test case tries to autodetect __FILE__ of the inheriting test but will
      not manage to do so across two levels of inheritance right now. when
      that happens it throws an error and one can set self.file = __FILE__
      manually. or well, improve on the detection code.
    - testcase uses priority_setup to run its setup always before the
      leafs setup. this is somewhat implicit and ideally would be solved by
      a prepended module since it is currently not needed though this magic
      function is used instead
    - priority_setup also craps out if the file name could nto be determined
    - setup also drops the test into a tmpdir to prevent source pollution
    
    some test cases have crappy class design in what they test and need to
    chdir to the datadir to test the class. this breaks the tmpdiring and is
    slightly unfortunate
---
 test/data/test_cmake_parser/test_disabled_feature |  1 -
 test/lib/testcase.rb                              | 57 +++++++++++++++++++++++
 test/test_apt.rb                                  |  6 +--
 test/test_ci_build_version.rb                     | 21 +--------
 test/test_cmake_parser.rb                         | 27 ++++-------
 test/test_debian_changelog.rb                     | 27 +----------
 test/test_debian_control.rb                       | 23 +--------
 test/test_debian_source.rb                        | 16 ++-----
 test/test_dpkg.rb                                 |  6 +--
 test/test_lp.rb                                   | 45 +++++++++---------
 test/test_lsb.rb                                  |  5 +-
 test/test_projects.rb                             |  4 +-
 test/test_qml_dependency_verifier.rb              | 11 +----
 test/test_qml_module.rb                           |  5 +-
 test/test_retry.rb                                |  5 +-
 test/test_testcase.rb                             | 24 ++++++++++
 test/test_thread_pool.rb                          | 16 +------
 test/test_upstream_scm.rb                         |  5 +-
 18 files changed, 140 insertions(+), 164 deletions(-)

diff --git a/test/data/test_cmake_parser/test_disabled_feature b/test/data/test_cmake_parser/test_disabled_feature
index 99c82fe..d6dee3b 100644
--- a/test/data/test_cmake_parser/test_disabled_feature
+++ b/test/data/test_cmake_parser/test_disabled_feature
@@ -1,4 +1,3 @@
- 
 dh_auto_configure '--buildsystem=kf5' --parallel  
 -- The C compiler identification is GNU 4.9.2
 -- The CXX compiler identification is GNU 4.9.2
diff --git a/test/lib/testcase.rb b/test/lib/testcase.rb
new file mode 100644
index 0000000..a0a485e
--- /dev/null
+++ b/test/lib/testcase.rb
@@ -0,0 +1,57 @@
+require 'test/unit'
+require 'tmpdir'
+
+# Test case base class handling fixtures and chdirring to not pollute the source
+# dir.
+class TestCase < Test::Unit::TestCase
+  ATFILEFAIL = 'Could not determine the basename of the file of the' \
+               ' class inheriting TestCase. Either flatten your inheritance' \
+               ' graph or set the name manually using `self.file = __FILE__`' \
+               ' in class scope.'
+
+  class << self
+    attr_accessor :file
+  end
+
+  def self.autodetect_inherited_file
+    caller_locations.each do |call|
+      next if call.label.include?('inherited')
+      path = call.absolute_path
+      @file = path if path.include?('/test/')
+      break
+    end
+    fail ATFILEFAIL unless @file
+  end
+
+  def self.inherited(subclass)
+    super(subclass)
+    subclass.autodetect_inherited_file
+  end
+
+  def priority_setup
+    fail ATFILEFAIL unless self.class.file
+    script_base_path = File.expand_path(File.dirname(self.class.file))
+    script_name = File.basename(self.class.file, '.rb')
+    @datadir = File.join(script_base_path, 'data', script_name)
+    @previous_pwd = Dir.pwd
+    @tmpdir = Dir.mktmpdir(self.class.to_s)
+    Dir.chdir(@tmpdir)
+  end
+
+  def priority_teardown
+    Dir.chdir(@previous_pwd)
+    FileUtils.rm_rf(@tmpdir)
+  end
+
+  def data(path = nil)
+    index = 0
+    caller = ''
+    until caller.start_with?('test_')
+      caller = caller_locations(index, 1)[0].label
+      index += 1
+    end
+    file = File.join(*[@datadir, caller, path].compact)
+    return file if File.exist?(file)
+    fail "Could not find data file #{file}"
+  end
+end
diff --git a/test/test_apt.rb b/test/test_apt.rb
index 8da852e..83ba0bb 100644
--- a/test/test_apt.rb
+++ b/test/test_apt.rb
@@ -1,11 +1,9 @@
-require 'test/unit'
-
 require_relative '../lib/apt'
-
 require_relative 'lib/assert_system'
+require_relative 'lib/testcase'
 
 # Test Apt
-class AptTest < Test::Unit::TestCase
+class AptTest < TestCase
   prepend AssertSystem
 
   def test_repo
diff --git a/test/test_ci_build_version.rb b/test/test_ci_build_version.rb
index 1286309..449429c 100644
--- a/test/test_ci_build_version.rb
+++ b/test/test_ci_build_version.rb
@@ -1,34 +1,17 @@
-require 'test/unit'
-
 require_relative '../lib/ci/build_version'
 require_relative '../lib/debian/changelog'
+require_relative 'lib/testcase'
 
 # Test ci/build_version
-class CIBuildVersionTest < Test::Unit::TestCase
+class CIBuildVersionTest < TestCase
   def setup
-    script_base_path = File.expand_path(File.dirname(__FILE__))
-    script_name = File.basename(__FILE__, '.rb')
-    @datadir = File.join(script_base_path, 'data', script_name)
-    @previous_pwd = Dir.pwd
-    Dir.chdir(@datadir)
     LSB.instance_variable_set(:@hash, DISTRIB_RELEASE: '15.04')
   end
 
   def teardown
-    Dir.chdir(@previous_pwd)
     LSB.reset
   end
 
-  def data(path = nil)
-    index = 0
-    caller = ''
-    until caller.start_with?('test_')
-      caller = caller_locations(index, 1)[0].label
-      index += 1
-    end
-    File.join(*[@datadir, caller, path].compact)
-  end
-
   def test_all
     c = Changelog.new(data)
     v = CI::BuildVersion.new(c)
diff --git a/test/test_cmake_parser.rb b/test/test_cmake_parser.rb
index 97a97ec..9fe3177 100644
--- a/test/test_cmake_parser.rb
+++ b/test/test_cmake_parser.rb
@@ -1,21 +1,11 @@
-require 'test/unit'
-
 require_relative '../lib/cmake_parser'
+require_relative 'lib/testcase'
 
 # Test CMakeParser
-class CMakeParserTest < Test::Unit::TestCase
-  def setup
-    @datadir = "#{File.expand_path(File.dirname(__FILE__))}/data/#{File.basename(__FILE__, '.rb')}"
-  end
-
+class CMakeParserTest < TestCase
   def data
-    index = 0
-    caller = ''
-    until caller.start_with?('test_')
-      caller = caller_locations(index, 1)[0].label
-      index += 1
-    end
-    File.read("#{@datadir}/#{caller}")
+    path = super
+    File.read(path)
   end
 
   def test_init
@@ -24,21 +14,22 @@ class CMakeParserTest < Test::Unit::TestCase
 
   def test_missing_package
     parser = CMakeParser.new(data)
-    assert_equal(parser.missing, %w(KF5Package))
+    assert_equal(%w(KF5Package), parser.missing)
   end
 
   def test_optional
     parser = CMakeParser.new(data)
-    assert_equal(parser.missing, %w(Qt5TextToSpeech))
+    assert_equal(%w(Qt5TextToSpeech), parser.missing)
   end
 
   def test_warning
     parser = CMakeParser.new(data)
-    assert_equal(parser.warnings, %w())
+    assert_equal(%w(), parser.warnings)
   end
 
   def test_disabled_feature
     parser = CMakeParser.new(data)
-    assert_equal(parser.disabled_features, ['XCB-CURSOR , Required for XCursor support'])
+    assert_equal(['XCB-CURSOR , Required for XCursor support'],
+                 parser.disabled_features)
   end
 end
diff --git a/test/test_debian_changelog.rb b/test/test_debian_changelog.rb
index be2ba0d..8c3d5bb 100644
--- a/test/test_debian_changelog.rb
+++ b/test/test_debian_changelog.rb
@@ -1,31 +1,8 @@
-require 'test/unit'
-
 require_relative '../lib/debian/changelog'
+require_relative 'lib/testcase'
 
 # Test debian/changelog
-class DebianChangelogTest < Test::Unit::TestCase
-  def setup
-    script_base_path = File.expand_path(File.dirname(__FILE__))
-    script_name = File.basename(__FILE__, '.rb')
-    @datadir = File.join(script_base_path, 'data', script_name)
-    @previous_pwd = Dir.pwd
-    Dir.chdir(@datadir)
-  end
-
-  def teardown
-    Dir.chdir(@previous_pwd)
-  end
-
-  def data(path = nil)
-    index = 0
-    caller = ''
-    until caller.start_with?('test_')
-      caller = caller_locations(index, 1)[0].label
-      index += 1
-    end
-    File.join(*[@datadir, caller, path].compact)
-  end
-
+class DebianChangelogTest < TestCase
   def test_parse
     c = Changelog.new(data)
     assert_equal('khelpcenter', c.name)
diff --git a/test/test_debian_control.rb b/test/test_debian_control.rb
index ddeed0d..73b2e81 100644
--- a/test/test_debian_control.rb
+++ b/test/test_debian_control.rb
@@ -1,31 +1,12 @@
-require 'test/unit'
-
 require_relative '../lib/debian/control'
+require_relative 'lib/testcase'
 
 # Test debian/source/format
-class DebianControlFormatTest < Test::Unit::TestCase
+class DebianControlFormatTest < TestCase
   def setup
-    script_base_path = File.expand_path(File.dirname(__FILE__))
-    script_name = File.basename(__FILE__, '.rb')
-    @datadir = File.join(script_base_path, 'data', script_name)
-    @previous_pwd = Dir.pwd
     Dir.chdir(@datadir)
   end
 
-  def teardown
-    Dir.chdir(@previous_pwd)
-  end
-
-  def data(path = nil)
-    index = 0
-    caller = ''
-    until caller.start_with?('test_')
-      caller = caller_locations(index, 1)[0].label
-      index += 1
-    end
-    File.join(*[@datadir, caller, path].compact)
-  end
-
   def test_parse
     assert_nothing_raised do
       c = DebianControl.new
diff --git a/test/test_debian_source.rb b/test/test_debian_source.rb
index 5670fd8..b5ce908 100644
--- a/test/test_debian_source.rb
+++ b/test/test_debian_source.rb
@@ -1,11 +1,11 @@
 require 'fileutils'
-require 'test/unit'
 require 'tmpdir'
 
 require_relative '../lib/debian/source'
+require_relative 'lib/testcase'
 
 # Test debian/source/format
-class DebianSourceFormatTest < Test::Unit::TestCase
+class DebianSourceFormatTest < TestCase
   self.test_order = :defined
 
   def test_init_str
@@ -76,17 +76,7 @@ class DebianSourceFormatTest < Test::Unit::TestCase
 end
 
 # Test debian/source
-class DebianSourceTest < Test::Unit::TestCase
-  def setup
-    @tmpdir = Dir.mktmpdir(self.class.to_s)
-    Dir.chdir(@tmpdir)
-  end
-
-  def teardown
-    Dir.chdir('/')
-    FileUtils.rm_rf(@tmpdir)
-  end
-
+class DebianSourceTest < TestCase
   def test_init
     file = 'debian/source/format'
     FileUtils.mkpath('debian/source')
diff --git a/test/test_dpkg.rb b/test/test_dpkg.rb
index 9150c80..43db6e3 100644
--- a/test/test_dpkg.rb
+++ b/test/test_dpkg.rb
@@ -1,11 +1,9 @@
-require 'test/unit'
-
 require_relative '../lib/dpkg'
-
 require_relative 'lib/assert_backtick'
+require_relative 'lib/testcase'
 
 # Test DPKG
-class DPKGTest < Test::Unit::TestCase
+class DPKGTest < TestCase
   prepend AssertBacktick
 
   def test_architectures
diff --git a/test/test_lp.rb b/test/test_lp.rb
index 8441ab1..120a599 100644
--- a/test/test_lp.rb
+++ b/test/test_lp.rb
@@ -1,6 +1,5 @@
-require "test/unit"
-
-require_relative "../lib/lp"
+require_relative '../lib/lp'
+require_relative 'lib/testcase'
 
 class FakeLaunchpad
     def self.call(env)
@@ -46,7 +45,7 @@ private
     end
 end
 
-class LaunchpadTest < Test::Unit::TestCase
+class LaunchpadTest < TestCase
   def setup
     Launchpad.instance_variable_set(:@conf_path, '/tmp')
   end
@@ -58,7 +57,7 @@ class LaunchpadTest < Test::Unit::TestCase
   # FIXME: need auth test
 end
 
-class LaunchpadRubberTest < Test::Unit::TestCase
+class LaunchpadRubberTest < TestCase
   def setup
     Launchpad.instance_variable_set(:@conf_path, '/tmp')
 
@@ -77,24 +76,24 @@ class LaunchpadRubberTest < Test::Unit::TestCase
     assert_equal(@ppa.self_link, ppa_url)
   end
 
-    # TODO: test from_json
-    # TODO: maybe test get and post directly?
+  # TODO: test from_json
+  # TODO: maybe test get and post directly?
 
-    def test_ppa_source_collection
-        sources = @ppa.getPublishedSources(source_name: "kate")
-        assert_not_nil(sources)
-        # TODO: when run against live this needs to be >=0
-        assert_equal(sources.size, 4)
-        source = sources[0]
-        # Has a bunch of properties
-        assert_not_nil(source)
-        assert_nothing_raised do
-            source.self_link
-            source.pocket
-            source.status
-        end
-        # Can GET a string-only variable. This mustn't make the parser trip.
-        assert_respond_to(source.changelogUrl(), :downcase)
-        puts source.changelogUrl()[0]
+  def test_ppa_source_collection
+    sources = @ppa.getPublishedSources(source_name: "kate")
+    assert_not_nil(sources)
+    # TODO: when run against live this needs to be >=0
+    assert_equal(sources.size, 4)
+    source = sources[0]
+    # Has a bunch of properties
+    assert_not_nil(source)
+    assert_nothing_raised do
+      source.self_link
+      source.pocket
+      source.status
     end
+    # Can GET a string-only variable. This mustn't make the parser trip.
+    assert_respond_to(source.changelogUrl(), :downcase)
+    puts source.changelogUrl()[0]
+  end
 end
diff --git a/test/test_lsb.rb b/test/test_lsb.rb
index af71087..69fad93 100644
--- a/test/test_lsb.rb
+++ b/test/test_lsb.rb
@@ -1,5 +1,3 @@
-require 'test/unit'
-
 require_relative '../lib/lsb'
 
 # Test lsb
@@ -31,5 +29,8 @@ class LSBTest < Test::Unit::TestCase
   def test_consts
     assert_equal('Mebuntu', LSB::DISTRIB_ID)
     assert_equal('codename', LSB::DISTRIB_CODENAME)
+    assert_raise NameError do
+      LSB::FOOOOOOOOOOOOOOO
+    end
   end
 end
diff --git a/test/test_projects.rb b/test/test_projects.rb
index b522504..78dead5 100644
--- a/test/test_projects.rb
+++ b/test/test_projects.rb
@@ -1,8 +1,8 @@
 require 'fileutils'
-require 'test/unit'
 require 'tmpdir'
 
 require_relative '../lib/projects'
+require_relative 'lib/testcase'
 
 # Mixin a prepend to overload the list_all_repos function with something testable.
 module FakeProjectFactory
@@ -15,7 +15,7 @@ class ProjectFactory
   prepend FakeProjectFactory
 end
 
-class ProjectTest < Test::Unit::TestCase
+class ProjectTest < TestCase
   def setup
     script_base_path = File.expand_path(File.dirname(__FILE__))
     script_name = File.basename(__FILE__, '.rb')
diff --git a/test/test_qml_dependency_verifier.rb b/test/test_qml_dependency_verifier.rb
index ac71c99..e95d5f8 100644
--- a/test/test_qml_dependency_verifier.rb
+++ b/test/test_qml_dependency_verifier.rb
@@ -1,13 +1,12 @@
-require 'test/unit'
 require 'vcr'
 
 require_relative '../lib/qml_dependency_verifier'
-
 require_relative 'lib/assert_backtick'
 require_relative 'lib/assert_system'
+require_relative 'lib/testcase'
 
 # Test qml dep verifier
-class QMLDependencyVerifierTest < Test::Unit::TestCase
+class QMLDependencyVerifierTest < TestCase
   prepend AssertBacktick
   prepend AssertSystem
 
@@ -17,24 +16,18 @@ class QMLDependencyVerifierTest < Test::Unit::TestCase
   end
 
   def setup
-    script_base_path = File.expand_path(File.dirname(__FILE__))
-    script_name = File.basename(__FILE__, '.rb')
-    @datadir = File.join(script_base_path, 'data', script_name)
-
     VCR.configure do |config|
       config.cassette_library_dir = @datadir
       config.hook_into :webmock
     end
     VCR.insert_cassette(File.basename(__FILE__, '.rb'))
 
-    @previous_pwd = Dir.pwd
     Dir.chdir(@datadir)
     LSB.instance_variable_set(:@hash, DISTRIB_CODENAME: 'vivid')
   end
 
   def teardown
     VCR.eject_cassette(File.basename(__FILE__, '.rb'))
-    Dir.chdir(@previous_pwd)
     LSB.reset
   end
 
diff --git a/test/test_qml_module.rb b/test/test_qml_module.rb
index 15592b8..baf0ac1 100644
--- a/test/test_qml_module.rb
+++ b/test/test_qml_module.rb
@@ -1,9 +1,8 @@
-require 'test/unit'
-
 require_relative '../lib/qml'
+require_relative 'lib/testcase'
 
 # Test qml module parsing
-class QMLTest < Test::Unit::TestCase
+class QMLTest < TestCase
   def test_empty_line
     assert_nil(QML::Module.parse(''))
   end
diff --git a/test/test_retry.rb b/test/test_retry.rb
index 06ebc3f..72af1c9 100644
--- a/test/test_retry.rb
+++ b/test/test_retry.rb
@@ -1,6 +1,5 @@
-require 'test/unit'
-
 require_relative '../lib/retry'
+require_relative 'lib/testcase'
 
 class RetryHelper
   attr_reader :count
@@ -24,7 +23,7 @@ class RetryHelper
 end
 
 # Test blocking thread pool.
-class RetryTest < Test::Unit::TestCase
+class RetryTest < TestCase
   def test_times
     times = 5
     helper = RetryHelper.new(max_count: times)
diff --git a/test/test_testcase.rb b/test/test_testcase.rb
new file mode 100644
index 0000000..d567c76
--- /dev/null
+++ b/test/test_testcase.rb
@@ -0,0 +1,24 @@
+require_relative 'lib/testcase'
+
+class Prop < TestCase
+end
+
+# Test TestCase class for everything we currently do not actively use as well
+# as failure scenarios.
+class TestTestCase < Test::Unit::TestCase
+  # Prop is configured in order, so tests depend on their definition order.
+  self.test_order = :defined
+
+  def test_file
+    assert_nothing_raised do
+      Prop.send(:file=, 'abc')
+    end
+    assert_equal('abc', Prop.file)
+  end
+
+  def test_data_lookup_fail
+    assert_raise RuntimeError do
+      Prop.new(nil).data
+    end
+  end
+end
diff --git a/test/test_thread_pool.rb b/test/test_thread_pool.rb
index 1252701..6ffe428 100644
--- a/test/test_thread_pool.rb
+++ b/test/test_thread_pool.rb
@@ -1,20 +1,8 @@
-require 'test/unit'
-require 'tmpdir'
-
 require_relative '../lib/thread_pool'
+require_relative 'lib/testcase'
 
 # Test blocking thread pool.
-class BlockingThreadPoolTest < Test::Unit::TestCase
-  def setup
-    @tmpdir = Dir.mktmpdir(self.class.to_s)
-    Dir.chdir(@tmpdir)
-  end
-
-  def teardown
-    Dir.chdir('/')
-    FileUtils.rm_rf(@tmpdir)
-  end
-
+class BlockingThreadPoolTest < TestCase
   def test_thread_pool
     queue = Queue.new
     32.times { |i| queue << i }
diff --git a/test/test_upstream_scm.rb b/test/test_upstream_scm.rb
index e383834..b50d53c 100644
--- a/test/test_upstream_scm.rb
+++ b/test/test_upstream_scm.rb
@@ -1,9 +1,8 @@
-require 'test/unit'
-
 require_relative '../lib/ci/upstream_scm'
+require_relative 'lib/testcase'
 
 # Test ci/upstream_scm
-class UpstreamSCMTest < Test::Unit::TestCase
+class UpstreamSCMTest < TestCase
   self.test_order = :defined
 
   def setup

-- 
ci-tooling packaging



More information about the pkg-kde-commits mailing list