Update tests for Python 2.6

Signed-off-by: Ondrej Nosek <onosek@redhat.com>
This commit is contained in:
Ondrej Nosek 2018-03-29 16:34:52 +02:00
parent f3b5a66614
commit 1f0739831c
7 changed files with 35 additions and 21 deletions

View File

@ -17,7 +17,6 @@ from __future__ import print_function
import os import os
import copy import copy
import lxml.etree import lxml.etree
from functools import total_ordering
def get_variants_dtd(logger=None): def get_variants_dtd(logger=None):
@ -207,7 +206,6 @@ class VariantsXmlParser(object):
return result return result
@total_ordering
class Variant(object): class Variant(object):
def __init__(self, id, name, type, arches, groups, environments=None, def __init__(self, id, name, type, arches, groups, environments=None,
buildinstallpackages=None, is_empty=False, parent=None, buildinstallpackages=None, is_empty=False, parent=None,
@ -257,6 +255,15 @@ class Variant(object):
ORDERING = {'variant': 0, 'addon': 1, 'layered-product': 1, 'optional': 2} ORDERING = {'variant': 0, 'addon': 1, 'layered-product': 1, 'optional': 2}
return (ORDERING[self.type], self.uid) < (ORDERING[other.type], other.uid) return (ORDERING[self.type], self.uid) < (ORDERING[other.type], other.uid)
def __le__(self, other):
return self < other or self == other
def __gt__(self, other):
return not (self <= other)
def __ge__(self, other):
return not (self < other)
def __hash__(self): def __hash__(self):
return hash((self.type, self.uid)) return hash((self.type, self.uid))

View File

@ -1,5 +1,8 @@
import mock import mock
import unittest try:
import unittest2 as unittest
except ImportError:
import unittest
import six import six
from tests.helpers import load_bin from tests.helpers import load_bin

View File

@ -37,15 +37,15 @@ class CompsWrapperTest(unittest.TestCase):
def test_get_groups(self): def test_get_groups(self):
comps = CompsWrapper(COMPS_FILE) comps = CompsWrapper(COMPS_FILE)
self.assertItemsEqual( self.assertEqual(
comps.get_comps_groups(), sorted(comps.get_comps_groups()),
['core', 'standard', 'text-internet', 'firefox', 'resilient-storage', 'basic-desktop']) sorted(['core', 'standard', 'text-internet', 'firefox', 'resilient-storage', 'basic-desktop']))
def test_get_packages(self): def test_get_packages(self):
comps = CompsWrapper(COMPS_FILE) comps = CompsWrapper(COMPS_FILE)
self.assertItemsEqual( self.assertEqual(
comps.get_packages('text-internet'), sorted(comps.get_packages('text-internet')),
{'dummy-elinks', 'dummy-tftp'}) sorted(['dummy-elinks', 'dummy-tftp']))
def test_get_packages_for_non_existing_group(self): def test_get_packages_for_non_existing_group(self):
comps = CompsWrapper(COMPS_FILE) comps = CompsWrapper(COMPS_FILE)

View File

@ -1,9 +1,13 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
try:
import unittest2 as unittest
except ImportError:
import unittest
import mock import mock
import os import os
import sys import sys
import unittest
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..")) sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))

View File

@ -3,7 +3,7 @@
import mock import mock
import os import os
import sys import sys
import unittest import unittest2 as unittest
import itertools import itertools
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..")) sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
@ -36,11 +36,11 @@ class TestIsoUtils(unittest.TestCase):
def test_get_implanted_md5_incorrect(self, mock_run): def test_get_implanted_md5_incorrect(self, mock_run):
mock_run.return_value = (0, INCORRECT_OUTPUT) mock_run.return_value = (0, INCORRECT_OUTPUT)
logger = mock.Mock() logger = mock.Mock()
self.assertIsNone(iso.get_implanted_md5('dummy.iso', logger=logger)) self.assertEqual(iso.get_implanted_md5('dummy.iso', logger=logger), None)
self.assertEqual(mock_run.call_args_list, self.assertEqual(mock_run.call_args_list,
[mock.call(['/usr/bin/checkisomd5', '--md5sumonly', 'dummy.iso'], [mock.call(['/usr/bin/checkisomd5', '--md5sumonly', 'dummy.iso'],
universal_newlines=True)]) universal_newlines=True)])
self.assertGreater(len(logger.mock_calls), 0) self.assertTrue(len(logger.mock_calls) > 0)
@mock.patch('pungi.util.run_unmount_cmd') @mock.patch('pungi.util.run_unmount_cmd')
@mock.patch('pungi.wrappers.iso.run') @mock.patch('pungi.wrappers.iso.run')

View File

@ -92,7 +92,7 @@ class TestNotifier(unittest.TestCase):
n.send('cmd', **self.data) n.send('cmd', **self.data)
makedirs.assert_called_once_with('/logs/notifications') makedirs.assert_called_once_with('/logs/notifications')
self.assertItemsEqual(run.call_args_list, [self._call('run-notify', 'cmd')]) self.assertEqual(run.call_args_list, [self._call('run-notify', 'cmd')])
@mock.patch('pungi.util.translate_path') @mock.patch('pungi.util.translate_path')
@mock.patch('kobo.shortcuts.run') @mock.patch('kobo.shortcuts.run')
@ -104,10 +104,10 @@ class TestNotifier(unittest.TestCase):
n.compose = self.compose n.compose = self.compose
n.send('cmd', **self.data) n.send('cmd', **self.data)
self.assertItemsEqual( self.assertEqual(
run.call_args_list, sorted(run.call_args_list),
[self._call('run-notify', 'cmd'), sorted([self._call('run-notify', 'cmd'),
self._call('ping-user', 'cmd')]) self._call('ping-user', 'cmd')]))
@mock.patch('kobo.shortcuts.run') @mock.patch('kobo.shortcuts.run')
def test_translates_path(self, run, makedirs): def test_translates_path(self, run, makedirs):
@ -120,7 +120,7 @@ class TestNotifier(unittest.TestCase):
n.compose = self.compose n.compose = self.compose
n.send('cmd', **self.data) n.send('cmd', **self.data)
self.assertItemsEqual( self.assertEqual(
run.call_args_list, run.call_args_list,
[self._call('run-notify', 'cmd', location='http://example.com/compose/a/b')]) [self._call('run-notify', 'cmd', location='http://example.com/compose/a/b')])
@ -140,7 +140,7 @@ class TestNotifier(unittest.TestCase):
n.compose = self.compose n.compose = self.compose
n.send('cmd', **self.data) n.send('cmd', **self.data)
self.assertItemsEqual(run.call_args_list, [self._call('run-notify', 'cmd')]) self.assertEqual(run.call_args_list, [self._call('run-notify', 'cmd')])
self.assertTrue(self.compose.log_warning.called) self.assertTrue(self.compose.log_warning.called)

View File

@ -4,7 +4,7 @@
import mock import mock
import os import os
import sys import sys
import unittest import unittest2 as unittest
import json import json
import re import re