+# Copyright 1998-2013 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+from portage.package.ebuild.fetch import (
+ _get_checksum_failure_max_tries,
+ )
+from portage.tests import TestCase
+
+
+class FetchTestCase(TestCase):
+ """
+ Test fetch and it's helper functions.
+
+ The fetch function, as it stands, is too complicated to test
+ on its own. However, the new helper functions are much more
+ limited and easier to test. Despite these tests, the helper
+ functions are internal implementation details, and their
+ presence and interface may change at any time. Do not use
+ them directly (outside of these tests).
+ """
+
+ def test_get_checksum_failure_max_tries(self):
+ self.assertEqual(
+ _get_checksum_failure_max_tries(settings={}),
+ 5)
+ self.assertEqual(
+ _get_checksum_failure_max_tries(settings={
+ 'PORTAGE_FETCH_CHECKSUM_TRY_MIRRORS': ''}),
+ 5)
+ self.assertEqual(
+ _get_checksum_failure_max_tries(settings={
+ 'PORTAGE_FETCH_CHECKSUM_TRY_MIRRORS': '3'}),
+ 3)
+ self.assertEqual(
+ _get_checksum_failure_max_tries(settings={
+ 'PORTAGE_FETCH_CHECKSUM_TRY_MIRRORS': '-1'}),
+ 5)
+ self.assertEqual(
+ _get_checksum_failure_max_tries(settings={
+ 'PORTAGE_FETCH_CHECKSUM_TRY_MIRRORS': 'oops'}),
+ 5)
+ self.assertEqual(
+ _get_checksum_failure_max_tries(
+ settings={}, default=3),
+ 3)