Port horizon utils tests to Python 3

* Use literal octal number syntax instead of the oct() function. The
  oct() function gives a different result on Python 2 and Python 3
  (Python 3 uses the "0o" prefix, not Python 2).
* format_value() explicitly cast the result to float. It's needed on
  Python 3 to cast a Decimal to float, because round(Decimal) returns a
  Decimal.
* tox.ini: run all horizon.test.tests.utils tests on Python 3.4

Partial-Implements: blueprint porting-python3
Change-Id: Ifd7c0e16ea85b691b81659acb010e9eb6f982d13
This commit is contained in:
Victor Stinner 2015-08-28 17:08:39 +02:00 committed by Timur Sufiev
parent 0f40f7c9c6
commit e16095fe16
3 changed files with 4 additions and 7 deletions

View File

@ -264,7 +264,7 @@ class SecretKeyTests(test.TestCase):
self.assertEqual(secret_key.generate_or_read_from_file(key_file), key)
# Key file only be read/writable by user:
self.assertEqual("0600", oct(os.stat(key_file).st_mode & 0o777))
self.assertEqual(0o600, os.stat(key_file).st_mode & 0o777)
os.chmod(key_file, 0o644)
self.assertRaises(secret_key.FilePermissionError,
secret_key.generate_or_read_from_file, key_file)

View File

@ -147,4 +147,5 @@ def format_value(value):
value = decimal.Decimal(str(value))
if int(value) == value:
return int(value)
return round(value, 1)
# On Python 3, an explicit cast to float is required
return float(round(value, 1))

View File

@ -29,11 +29,7 @@ commands =
horizon.test.tests.tables.DataTableViewTests \
horizon.test.tests.templatetags \
horizon.test.tests.test_file_discovery \
horizon.test.tests.utils.FiltersTests \
horizon.test.tests.utils.GetPageSizeTests \
horizon.test.tests.utils.MemoizedTests \
horizon.test.tests.utils.TimeSinceNeverFilterTests \
horizon.test.tests.utils.ValidatorsTests \
horizon.test.tests.utils \
horizon.test.tests.views
python manage.py test --settings=openstack_dashboard.test.settings \
openstack_dashboard.dashboards.project.access_and_security.api_access.tests \