mirror of
https://github.com/openSUSE/osc.git
synced 2025-11-25 06:06:30 +01:00
Fix ElementTree imports for Python 3.9
Importing `cElementTree` has been deprecated since Python 3.3 - importing `ElementTree` automatically uses the fastest implementation available - and is finally removed in Python 3.9. Importing cElementTree directly (not as part of xml) is an even older relic, it's for Ye Time Before ElementTree Was Added To Python and it was instead an external module...which was before Python 2.5. We still need to work with Python 2.7 for now, so we use a try/ except to handle both 2.7 and 3.9 cases. Also, let's not repeat this import 12 times in one file for some reason. Signed-off-by: Adam Williamson <awilliam@redhat.com>
This commit is contained in:
@@ -1,3 +1,11 @@
|
||||
try:
|
||||
# Works up to Python 3.8, needed for Python < 3.3 (inc 2.7)
|
||||
from xml.etree import cElementTree as ET
|
||||
except ImportError:
|
||||
# will import a fast implementation from 3.3 onwards, needed
|
||||
# for 3.9+
|
||||
from xml.etree import ElementTree as ET
|
||||
|
||||
import osc.core
|
||||
import osc.oscerr
|
||||
import os
|
||||
@@ -252,7 +260,6 @@ class TestRequest(OscTestCase):
|
||||
|
||||
def test_action_from_xml1(self):
|
||||
"""create action from xml"""
|
||||
from xml.etree import cElementTree as ET
|
||||
xml = """<action type="add_role">
|
||||
<target package="bar" project="foo" />
|
||||
<person name="user" role="reader" />
|
||||
@@ -270,7 +277,6 @@ class TestRequest(OscTestCase):
|
||||
|
||||
def test_action_from_xml2(self):
|
||||
"""create action from xml"""
|
||||
from xml.etree import cElementTree as ET
|
||||
xml = """<action type="submit">
|
||||
<source package="bar" project="foo" />
|
||||
<target package="bar" project="foobar" />
|
||||
@@ -292,7 +298,6 @@ class TestRequest(OscTestCase):
|
||||
|
||||
def test_action_from_xml3(self):
|
||||
"""create action from xml (with acceptinfo element)"""
|
||||
from xml.etree import cElementTree as ET
|
||||
xml = """<action type="submit">
|
||||
<source package="bar" project="testprj" />
|
||||
<target package="baz" project="foobar" />
|
||||
@@ -316,13 +321,11 @@ class TestRequest(OscTestCase):
|
||||
|
||||
def test_action_from_xml_unknown_type(self):
|
||||
"""try to create action from xml with unknown type"""
|
||||
from xml.etree import cElementTree as ET
|
||||
xml = '<action type="foo"><source package="bar" project="foo" /></action>'
|
||||
self.assertRaises(osc.oscerr.WrongArgs, osc.core.Action.from_xml, ET.fromstring(xml))
|
||||
|
||||
def test_read_request1(self):
|
||||
"""read in a request"""
|
||||
from xml.etree import cElementTree as ET
|
||||
xml = open(os.path.join(self._get_fixtures_dir(), 'test_read_request1.xml'), 'r').read().strip()
|
||||
r = osc.core.Request()
|
||||
r.read(ET.fromstring(xml))
|
||||
@@ -354,7 +357,6 @@ class TestRequest(OscTestCase):
|
||||
|
||||
def test_read_request2(self):
|
||||
"""read in a request (with reviews)"""
|
||||
from xml.etree import cElementTree as ET
|
||||
xml = open(os.path.join(self._get_fixtures_dir(), 'test_read_request2.xml'), 'r').read().strip()
|
||||
r = osc.core.Request()
|
||||
r.read(ET.fromstring(xml))
|
||||
@@ -393,7 +395,6 @@ class TestRequest(OscTestCase):
|
||||
|
||||
def test_read_request3(self):
|
||||
"""read in a request (with an "empty" comment+description)"""
|
||||
from xml.etree import cElementTree as ET
|
||||
xml = """<request creator="xyz" id="2">
|
||||
<action type="set_bugowner">
|
||||
<target project="foo" />
|
||||
@@ -430,7 +431,6 @@ class TestRequest(OscTestCase):
|
||||
|
||||
def test_request_list_view1(self):
|
||||
"""test the list_view method"""
|
||||
from xml.etree import cElementTree as ET
|
||||
xml = open(os.path.join(self._get_fixtures_dir(), 'test_request_list_view1.xml'), 'r').read().strip()
|
||||
exp = """\
|
||||
62 State:new By:Admin When:2010-12-29T14:57:25
|
||||
@@ -448,7 +448,6 @@ class TestRequest(OscTestCase):
|
||||
|
||||
def test_request_list_view2(self):
|
||||
"""test the list_view method (with history elements and description)"""
|
||||
from xml.etree import cElementTree as ET
|
||||
xml = open(os.path.join(self._get_fixtures_dir(), 'test_request_list_view2.xml'), 'r').read().strip()
|
||||
r = osc.core.Request()
|
||||
r.read(ET.fromstring(xml))
|
||||
@@ -462,7 +461,6 @@ class TestRequest(OscTestCase):
|
||||
self.assertEqual(exp, r.list_view())
|
||||
|
||||
def test_request_str1(self):
|
||||
from xml.etree import cElementTree as ET
|
||||
"""test the __str__ method"""
|
||||
xml = open(os.path.join(self._get_fixtures_dir(), 'test_request_str1.xml'), 'r').read().strip()
|
||||
r = osc.core.Request()
|
||||
@@ -496,7 +494,6 @@ History: 2010-12-12T00:00:00 creator revoked
|
||||
|
||||
def test_request_str2(self):
|
||||
"""test the __str__ method"""
|
||||
from xml.etree import cElementTree as ET
|
||||
xml = """\
|
||||
<request creator="creator" id="98765">
|
||||
<action type="change_devel">
|
||||
@@ -527,7 +524,6 @@ Comment: <no comment>"""
|
||||
|
||||
def test_legacy_request(self):
|
||||
"""load old-style submitrequest"""
|
||||
from xml.etree import cElementTree as ET
|
||||
xml = """\
|
||||
<request creator="olduser" id="1234" type="submit">
|
||||
<submit>
|
||||
@@ -563,7 +559,6 @@ Comment: <no comment>"""
|
||||
|
||||
def test_get_actions(self):
|
||||
"""test get_actions method"""
|
||||
from xml.etree import cElementTree as ET
|
||||
xml = open(os.path.join(self._get_fixtures_dir(), 'test_request_list_view1.xml'), 'r').read().strip()
|
||||
r = osc.core.Request()
|
||||
r.read(ET.fromstring(xml))
|
||||
|
||||
Reference in New Issue
Block a user