[Asterisk-code-review] testsuite: Use CSafeLoader instead of SafeLoader when possible (testsuite[17])
Friendly Automation
asteriskteam at digium.com
Wed Jan 8 09:09:58 CST 2020
Friendly Automation has submitted this change. ( https://gerrit.asterisk.org/c/testsuite/+/13572 )
Change subject: testsuite: Use CSafeLoader instead of SafeLoader when possible
......................................................................
testsuite: Use CSafeLoader instead of SafeLoader when possible
This speeds up YAML parsing about 8x on my machine. The two YAML file changes
are to fix a parsing error that only seems to occur with CSafeLoader.
Change-Id: I4eb4b17d29e32e1ca7e1d260d7d0e59e4646a18e
---
M lib/python/asterisk/test_config.py
M lib/python/asterisk/test_runner.py
M runtests.py
M tests/hep/rtcp-receiver/test-config.yaml
M tests/hep/rtcp-sender/test-config.yaml
M usage.py
6 files changed, 39 insertions(+), 19 deletions(-)
Approvals:
Joshua Colp: Looks good to me, but someone else must approve
George Joseph: Looks good to me, but someone else must approve
Corey Farrell: Looks good to me, approved
Friendly Automation: Approved for Submit
diff --git a/lib/python/asterisk/test_config.py b/lib/python/asterisk/test_config.py
index 4860cb3..b395e63 100644
--- a/lib/python/asterisk/test_config.py
+++ b/lib/python/asterisk/test_config.py
@@ -16,6 +16,11 @@
import socket
import traceback
+try:
+ from yaml import CSafeLoader as MyLoader
+except ImportError:
+ from yaml import SafeLoader as MyLoader
+
sys.path.append("lib/python")
from . import test_suite_utils
@@ -374,7 +379,7 @@
test_config = "%s/test-config.yaml" % self.test_name
with open(test_config, "r") as config_file:
- self.config = yaml.load(config_file, Loader=yaml.SafeLoader)
+ self.config = yaml.load(config_file, Loader=MyLoader)
if not self.config:
print("ERROR: Failed to load configuration for test '%s'" %
diff --git a/lib/python/asterisk/test_runner.py b/lib/python/asterisk/test_runner.py
index 443b712..588a6bb 100644
--- a/lib/python/asterisk/test_runner.py
+++ b/lib/python/asterisk/test_runner.py
@@ -17,6 +17,11 @@
import os
import yaml
+try:
+ from yaml import CSafeLoader as MyLoader
+except ImportError:
+ from yaml import SafeLoader as MyLoader
+
from twisted.internet import reactor
LOGGER = logging.getLogger('test_runner')
@@ -233,7 +238,7 @@
return test_config
with open(test_config_path) as file_stream:
- test_config = yaml.load(file_stream, Loader=yaml.SafeLoader)
+ test_config = yaml.load(file_stream, Loader=MyLoader)
return test_config
diff --git a/runtests.py b/runtests.py
index fe04213..dac72b0 100755
--- a/runtests.py
+++ b/runtests.py
@@ -24,6 +24,11 @@
import re
try:
+ from yaml import CSafeLoader as MyLoader
+except ImportError:
+ from yaml import SafeLoader as MyLoader
+
+try:
import lxml.etree as ET
except:
# Ensure ET is defined
@@ -772,7 +777,7 @@
print("Unexpected error: %s" % sys.exc_info()[0])
return None
- config = yaml.load(f, Loader=yaml.SafeLoader)
+ config = yaml.load(f, Loader=MyLoader)
f.close()
return config
diff --git a/tests/hep/rtcp-receiver/test-config.yaml b/tests/hep/rtcp-receiver/test-config.yaml
index c4008c3..961ae2a 100644
--- a/tests/hep/rtcp-receiver/test-config.yaml
+++ b/tests/hep/rtcp-receiver/test-config.yaml
@@ -73,7 +73,7 @@
value:
{ ssrc: "\\d.*",
type: 201,
- report_blocks:[ { source_ssrc: "\\d.*",
+ report_blocks: [ { source_ssrc: "\\d.*",
highest_seq_no: "\\d.*",
fraction_lost: 0,
ia_jitter: "\\d.*",
@@ -137,7 +137,7 @@
value:
{ ssrc: "\\d.*",
type: 201,
- report_blocks:[ { source_ssrc: "\\d.*",
+ report_blocks: [ { source_ssrc: "\\d.*",
highest_seq_no: "\\d.*",
fraction_lost: 0,
ia_jitter: "\\d.*",
@@ -180,7 +180,7 @@
value:
{ ssrc: "\\d.*",
type: 201,
- report_blocks:[ { source_ssrc: "\\d.*",
+ report_blocks: [ { source_ssrc: "\\d.*",
highest_seq_no: "\\d.*",
fraction_lost: 0,
ia_jitter: "\\d.*",
diff --git a/tests/hep/rtcp-sender/test-config.yaml b/tests/hep/rtcp-sender/test-config.yaml
index c4e32c6..5083115 100644
--- a/tests/hep/rtcp-sender/test-config.yaml
+++ b/tests/hep/rtcp-sender/test-config.yaml
@@ -76,7 +76,7 @@
ntp_timestamp_usec: "\\d.*",
octets: "\\d.*",
rtp_timestamp: "\\d.*", },
- report_blocks:[ { source_ssrc: "\\d.*",
+ report_blocks: [ { source_ssrc: "\\d.*",
highest_seq_no: "\\d.*",
fraction_lost: 0,
ia_jitter: "\\d.*",
@@ -103,7 +103,7 @@
ntp_timestamp_usec: "\\d.*",
octets: "\\d.*",
rtp_timestamp: "\\d.*", },
- report_blocks:[ { source_ssrc: "\\d.*",
+ report_blocks: [ { source_ssrc: "\\d.*",
highest_seq_no: "\\d.*",
fraction_lost: 0,
ia_jitter: "\\d.*",
@@ -130,7 +130,7 @@
ntp_timestamp_usec: "\\d.*",
octets: "\\d.*",
rtp_timestamp: "\\d.*", },
- report_blocks:[ { source_ssrc: "\\d.*",
+ report_blocks: [ { source_ssrc: "\\d.*",
highest_seq_no: "\\d.*",
fraction_lost: 0,
ia_jitter: "\\d.*",
@@ -157,7 +157,7 @@
ntp_timestamp_usec: "\\d.*",
octets: "\\d.*",
rtp_timestamp: "\\d.*", },
- report_blocks:[ { source_ssrc: "\\d.*",
+ report_blocks: [ { source_ssrc: "\\d.*",
highest_seq_no: "\\d.*",
fraction_lost: 0,
ia_jitter: "\\d.*",
@@ -184,7 +184,7 @@
ntp_timestamp_usec: "\\d.*",
octets: "\\d.*",
rtp_timestamp: "\\d.*", },
- report_blocks:[ { source_ssrc: "\\d.*",
+ report_blocks: [ { source_ssrc: "\\d.*",
highest_seq_no: "\\d.*",
fraction_lost: 0,
ia_jitter: "\\d.*",
@@ -211,7 +211,7 @@
ntp_timestamp_usec: "\\d.*",
octets: "\\d.*",
rtp_timestamp: "\\d.*", },
- report_blocks:[ { source_ssrc: "\\d.*",
+ report_blocks: [ { source_ssrc: "\\d.*",
highest_seq_no: "\\d.*",
fraction_lost: 0,
ia_jitter: "\\d.*",
@@ -249,7 +249,7 @@
ntp_timestamp_usec: "\\d.*",
octets: "\\d.*",
rtp_timestamp: "\\d.*", },
- report_blocks:[ { source_ssrc: "\\d.*",
+ report_blocks: [ { source_ssrc: "\\d.*",
highest_seq_no: "\\d.*",
fraction_lost: 0,
ia_jitter: "\\d.*",
@@ -276,7 +276,7 @@
ntp_timestamp_usec: "\\d.*",
octets: "\\d.*",
rtp_timestamp: "\\d.*", },
- report_blocks:[ { source_ssrc: "\\d.*",
+ report_blocks: [ { source_ssrc: "\\d.*",
highest_seq_no: "\\d.*",
fraction_lost: 0,
ia_jitter: "\\d.*",
@@ -303,7 +303,7 @@
ntp_timestamp_usec: "\\d.*",
octets: "\\d.*",
rtp_timestamp: "\\d.*", },
- report_blocks:[ { source_ssrc: "\\d.*",
+ report_blocks: [ { source_ssrc: "\\d.*",
highest_seq_no: "\\d.*",
fraction_lost: 0,
ia_jitter: "\\d.*",
@@ -330,7 +330,7 @@
ntp_timestamp_usec: "\\d.*",
octets: "\\d.*",
rtp_timestamp: "\\d.*", },
- report_blocks:[ { source_ssrc: "\\d.*",
+ report_blocks: [ { source_ssrc: "\\d.*",
highest_seq_no: "\\d.*",
fraction_lost: 0,
ia_jitter: "\\d.*",
@@ -357,7 +357,7 @@
ntp_timestamp_usec: "\\d.*",
octets: "\\d.*",
rtp_timestamp: "\\d.*", },
- report_blocks:[ { source_ssrc: "\\d.*",
+ report_blocks: [ { source_ssrc: "\\d.*",
highest_seq_no: "\\d.*",
fraction_lost: 0,
ia_jitter: "\\d.*",
@@ -384,7 +384,7 @@
ntp_timestamp_usec: "\\d.*",
octets: "\\d.*",
rtp_timestamp: "\\d.*", },
- report_blocks:[ { source_ssrc: "\\d.*",
+ report_blocks: [ { source_ssrc: "\\d.*",
highest_seq_no: "\\d.*",
fraction_lost: 0,
ia_jitter: "\\d.*",
diff --git a/usage.py b/usage.py
index 5b12bdd..dd6facc 100755
--- a/usage.py
+++ b/usage.py
@@ -11,6 +11,11 @@
import sys
import yaml
+try:
+ from yaml import CSafeLoader as MyLoader
+except ImportError:
+ from yaml import SafeLoader as MyLoader
+
sys.path.append('lib/python')
TESTS_CONFIG = "tests.yaml"
@@ -101,7 +106,7 @@
print("Unexpected error: %s" % sys.exc_info()[0])
return None
- config = yaml.load(f, Loader=yaml.SafeLoader)
+ config = yaml.load(f, Loader=MyLoader)
f.close()
return config
--
To view, visit https://gerrit.asterisk.org/c/testsuite/+/13572
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings
Gerrit-Project: testsuite
Gerrit-Branch: 17
Gerrit-Change-Id: I4eb4b17d29e32e1ca7e1d260d7d0e59e4646a18e
Gerrit-Change-Number: 13572
Gerrit-PatchSet: 1
Gerrit-Owner: Sean Bright <sean.bright at gmail.com>
Gerrit-Reviewer: Corey Farrell <git at cfware.com>
Gerrit-Reviewer: Friendly Automation
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Joshua Colp <jcolp at sangoma.com>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20200108/6ec985eb/attachment-0001.html>
More information about the asterisk-code-review
mailing list