Blob Blame History Raw
From c245ca30f248367e07d5d831195b12c93a1e3137 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?V=C3=ADt=20Ondruch?= <vondruch@redhat.com>
Date: Mon, 4 Jul 2016 13:36:30 +0200
Subject: [PATCH] Skip the test if test data download fails.

---
 activesupport/test/multibyte_conformance_test.rb            |  2 --
 .../test/multibyte_grapheme_break_conformance_test.rb       | 13 +++++++------
 .../test/multibyte_normalization_conformance_test.rb        |  9 +++++----
 activesupport/test/multibyte_test_helpers.rb                |  4 ++++
 4 files changed, 16 insertions(+), 12 deletions(-)

diff --git a/activesupport/test/multibyte_conformance_test.rb b/activesupport/test/multibyte_conformance_test.rb
index 709c63a..c10133a 100644
--- a/activesupport/test/multibyte_conformance_test.rb
+++ b/activesupport/test/multibyte_conformance_test.rb
@@ -8,9 +8,7 @@
 class MultibyteConformanceTest < ActiveSupport::TestCase
   include MultibyteTestHelpers
 
-  UNIDATA_URL = "http://www.unicode.org/Public/#{ActiveSupport::Multibyte::Unicode::UNICODE_VERSION}/ucd"
   UNIDATA_FILE = '/NormalizationTest.txt'
-  CACHE_DIR = "#{Dir.tmpdir}/cache/unicode_conformance"
   FileUtils.mkdir_p(CACHE_DIR)
   RUN_P = begin
             Downloader.download(UNIDATA_URL + UNIDATA_FILE, CACHE_DIR + UNIDATA_FILE)
diff --git a/activesupport/test/multibyte_grapheme_break_conformance_test.rb b/activesupport/test/multibyte_grapheme_break_conformance_test.rb
index 45e1976..61943b1 100644
--- a/activesupport/test/multibyte_grapheme_break_conformance_test.rb
+++ b/activesupport/test/multibyte_grapheme_break_conformance_test.rb
@@ -10,13 +10,14 @@
 class MultibyteGraphemeBreakConformanceTest < ActiveSupport::TestCase
   include MultibyteTestHelpers
 
-  TEST_DATA_URL = "http://www.unicode.org/Public/#{ActiveSupport::Multibyte::Unicode::UNICODE_VERSION}/ucd/auxiliary"
-  TEST_DATA_FILE = '/GraphemeBreakTest.txt'
-  CACHE_DIR = "#{Dir.tmpdir}/cache/unicode_conformance"
+  UNIDATA_FILE = '/auxiliary/GraphemeBreakTest.txt'
+  RUN_P = begin
+            Downloader.download(UNIDATA_URL + UNIDATA_FILE, CACHE_DIR + UNIDATA_FILE)
+          rescue
+          end
 
   def setup
-    FileUtils.mkdir_p(CACHE_DIR)
-    Downloader.download(TEST_DATA_URL + TEST_DATA_FILE, CACHE_DIR + TEST_DATA_FILE)
+    skip "Unable to download test data" unless RUN_P
   end
 
   def test_breaks
@@ -31,7 +32,7 @@ def test_breaks
     def each_line_of_break_tests(&block)
       lines = 0
       max_test_lines = 0 # Don't limit below 21, because that's the header of the testfile
-      File.open(File.join(CACHE_DIR, TEST_DATA_FILE), 'r') do | f |
+      File.open(File.join(CACHE_DIR, UNIDATA_FILE), 'r') do | f |
         until f.eof? || (max_test_lines > 21 and lines > max_test_lines)
           lines += 1
           line = f.gets.chomp!
diff --git a/activesupport/test/multibyte_normalization_conformance_test.rb b/activesupport/test/multibyte_normalization_conformance_test.rb
index ad2e651..77ed0ce 100644
--- a/activesupport/test/multibyte_normalization_conformance_test.rb
+++ b/activesupport/test/multibyte_normalization_conformance_test.rb
@@ -10,14 +10,15 @@
 class MultibyteNormalizationConformanceTest < ActiveSupport::TestCase
   include MultibyteTestHelpers
 
-  UNIDATA_URL = "http://www.unicode.org/Public/#{ActiveSupport::Multibyte::Unicode::UNICODE_VERSION}/ucd"
   UNIDATA_FILE = '/NormalizationTest.txt'
-  CACHE_DIR = "#{Dir.tmpdir}/cache/unicode_conformance"
+  RUN_P = begin
+            Downloader.download(UNIDATA_URL + UNIDATA_FILE, CACHE_DIR + UNIDATA_FILE)
+          rescue
+          end
 
   def setup
-    FileUtils.mkdir_p(CACHE_DIR)
-    Downloader.download(UNIDATA_URL + UNIDATA_FILE, CACHE_DIR + UNIDATA_FILE)
     @proxy = ActiveSupport::Multibyte::Chars
+    skip "Unable to download test data" unless RUN_P
   end
 
   def test_normalizations_C
diff --git a/activesupport/test/multibyte_test_helpers.rb b/activesupport/test/multibyte_test_helpers.rb
index 709586e..0ada8bc 100644
--- a/activesupport/test/multibyte_test_helpers.rb
+++ b/activesupport/test/multibyte_test_helpers.rb
@@ -17,6 +17,10 @@ def self.download(from, to)
     end
   end
 
+  UNIDATA_URL = "http://www.unicode.org/Public/#{ActiveSupport::Multibyte::Unicode::UNICODE_VERSION}/ucd"
+  CACHE_DIR = "#{Dir.tmpdir}/cache/unicode_conformance"
+  FileUtils.mkdir_p(CACHE_DIR)
+
   UNICODE_STRING = 'こにちわ'.freeze
   ASCII_STRING = 'ohayo'.freeze
   BYTE_STRING = "\270\236\010\210\245".force_encoding("ASCII-8BIT").freeze
-- 
2.9.0