[SCM] ci-tooling packaging branch, master, updated. 400c57e610976df4d5684bf88dca9dca4a78c758

Harald Sitter apachelogger-guest at moszumanska.debian.org
Tue May 5 08:16:22 UTC 2015


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

The following commit has been merged in the master branch:
commit 400c57e610976df4d5684bf88dca9dca4a78c758
Author: Harald Sitter <sitter at kde.org>
Date:   Tue May 5 10:16:17 2015 +0200

    make sure to test time for coverage purposes
    
    also to make sure it actually is time.now rather than anything else
---
 lib/ci/build_version.rb       |  4 +++-
 test/test_ci_build_version.rb | 39 ++++++++++++++++++++++++++++++++++++---
 2 files changed, 39 insertions(+), 4 deletions(-)

diff --git a/lib/ci/build_version.rb b/lib/ci/build_version.rb
index fac4ae1..7a02d9f 100644
--- a/lib/ci/build_version.rb
+++ b/lib/ci/build_version.rb
@@ -6,6 +6,8 @@ module CI
   # Wraps a debian changelog to construct a build specific version based on the
   # version used in the changelog.
   class BuildVersion
+    TIME_FORMAT = '%Y%m%d.%H%M'
+
     # Version (including epoch)
     attr_reader :base
     # Version (excluding epoch)
@@ -31,7 +33,7 @@ module CI
 
     # Helper to get the time string for use in the version
     def time
-      DateTime.now.strftime('%Y%m%d.%H%M')
+      DateTime.now.strftime(TIME_FORMAT)
     end
 
     # Removes non digits from base version string.
diff --git a/test/test_ci_build_version.rb b/test/test_ci_build_version.rb
index 08cb32a..4967480 100644
--- a/test/test_ci_build_version.rb
+++ b/test/test_ci_build_version.rb
@@ -4,16 +4,29 @@ require_relative 'lib/testcase'
 
 # Test ci/build_version
 class CIBuildVersionTest < TestCase
+  REF_TIME = '20150505.0505'
+
   def setup
     OS.instance_variable_set(:@hash, VERSION_ID: '15.04', ID: 'ubuntu')
-    CI::BuildVersion.send(:alias_method, :__time_orig, :time)
-    CI::BuildVersion.send(:define_method, :time) { '20150505.0505' }
+    alias_time
   end
 
   def teardown
+    OS.reset
+    unalias_time
+  end
+
+  def alias_time
+    CI::BuildVersion.send(:alias_method, :__time_orig, :time)
+    CI::BuildVersion.send(:define_method, :time) { REF_TIME }
+    @time_aliased = true
+  end
+
+  def unalias_time
+    return unless @time_aliased
     CI::BuildVersion.send(:undef_method, :time)
     CI::BuildVersion.send(:alias_method, :time, :__time_orig)
-    OS.reset
+    @time_aliased = false
   end
 
   def test_all
@@ -24,6 +37,7 @@ class CIBuildVersionTest < TestCase
     # Suffix must be comprised of a date and a distribution identifier such
     # that uploads created at the same time for different targets do not
     # conflict one another.
+    assert_equal(v.send(:time), REF_TIME)
     parts = suffix.split('+')
     assert_empty(parts[0])
     assert_equal("git#{v.time}", parts[1])
@@ -37,6 +51,25 @@ class CIBuildVersionTest < TestCase
     assert_equal(v.full, v.to_s)
   end
 
+  def test_time
+    unalias_time
+    c = Changelog.new(data)
+    v = CI::BuildVersion.new(c)
+    # Make sure time is within a one minute delta between what version returns
+    # and what datetime.now returns. For the purpose of this excercise the
+    # timezone needs to get stripped, so simply run our refernece time through
+    # the same string mangling as the actual verson.time
+    time_format = v.class::TIME_FORMAT
+    time1 = DateTime.strptime(DateTime.now.strftime(time_format), time_format)
+    time2 = DateTime.strptime(v.send(:time), time_format)
+    datetime_diff = (time2 - time1).to_f
+    # One minute rational as float i.e. Rational(1/1440)
+    minute_rational_f = 0.0006944444444444445
+    assert_in_delta(0.0, datetime_diff.to_f, minute_rational_f,
+                    "The time delta between version's time and actual time is" \
+                    ' too large.')
+  end
+
   def test_bad_version
     c = Changelog.new(data)
     assert_raise RuntimeError do

-- 
ci-tooling packaging



More information about the pkg-kde-commits mailing list