diff --git a/muranopkgcheck/pkg_loader.py b/muranopkgcheck/pkg_loader.py index db5a2e9..905ae84 100644 --- a/muranopkgcheck/pkg_loader.py +++ b/muranopkgcheck/pkg_loader.py @@ -14,7 +14,6 @@ import abc -import io import os import re import sys @@ -46,7 +45,7 @@ class FileWrapper(object): def yaml(self): if self._yaml is None: - sio = io.StringIO(six.text_type(self.raw())) + sio = six.BytesIO(self.raw()) setattr(sio, 'name', self._name) self._yaml = list(yaml.load_all(sio, yaml_loader.YamlLoader)) diff --git a/muranopkgcheck/tests/functional/test_cases.py b/muranopkgcheck/tests/functional/test_cases.py index b99b1a0..46ce753 100644 --- a/muranopkgcheck/tests/functional/test_cases.py +++ b/muranopkgcheck/tests/functional/test_cases.py @@ -39,11 +39,11 @@ class DictLoader(pkg_loader.BaseLoader): def open_file(self, path, mode='r'): if self.pkg[path]['format'] == 'raw': - sio = io.StringIO(six.text_type(self.pkg[path]['content'])) + sio = io.BytesIO(six.b(self.pkg[path]['content'])) setattr(sio, 'name', path) elif self.pkg[path]['format'] == 'yaml': content = yaml.safe_dump(self.pkg[path]['content']) - sio = io.StringIO(six.text_type(content)) + sio = io.BytesIO(six.b(content)) setattr(sio, 'name', path) else: raise ValueError('Unknown type of content') diff --git a/muranopkgcheck/tests/test_pkg_loader.py b/muranopkgcheck/tests/test_pkg_loader.py index 86292e6..53c638d 100644 --- a/muranopkgcheck/tests/test_pkg_loader.py +++ b/muranopkgcheck/tests/test_pkg_loader.py @@ -31,9 +31,9 @@ class FileWrapperTest(base.TestCase): m_yaml.load_all.side_effect = yaml.load_all fake_pkg = mock.Mock() fake_pkg.open_file.side_effect = \ - lambda f: mock.mock_open(read_data='text')() + lambda f: mock.mock_open(read_data=six.b('text'))() f = pkg_loader.FileWrapper(fake_pkg, 'fake_path') - self.assertEqual('text', f.raw()) + self.assertEqual(six.b('text'), f.raw()) self.assertEqual(['text'], f.yaml()) m_yaml.load_all.assert_called() @@ -43,9 +43,9 @@ class FileWrapperTest(base.TestCase): m_yaml.load_all.assert_not_called() fake_pkg.open_file.side_effect = \ - lambda f: mock.mock_open(read_data='!@#$%')() - f = pkg_loader.FileWrapper(fake_pkg, 'fake_path') - self.assertEqual('!@#$%', f.raw()) + lambda f: mock.mock_open(read_data=six.b('!@#$%'))() + f = pkg_loader.FileWrapper(fake_pkg, six.b('fake_path')) + self.assertEqual(six.b('!@#$%'), f.raw()) self.assertRaises(yaml.error.YAMLError, f.yaml) @@ -219,7 +219,7 @@ class ZipLoaderTest(base.TestCase): m_read): m_read.return_value.yaml.return_value = [{'FullName': 'fake'}] m_exists.return_value = True - m_content = str('fake') if six.PY2 else bytes('fake', 'latin-1') + m_content = six.b('fake') loader = pkg_loader.ZipLoader.try_load(six.BytesIO(m_content)) self.assertIsNotNone(loader) m_try_set_format.assert_called_once_with({'FullName': 'fake'}) diff --git a/muranopkgcheck/validators/base.py b/muranopkgcheck/validators/base.py index 75f4b14..aac525b 100644 --- a/muranopkgcheck/validators/base.py +++ b/muranopkgcheck/validators/base.py @@ -24,6 +24,7 @@ from muranopkgcheck.i18n import _ FQN_REGEX = re.compile('^([a-zA-Z_$][\w$]*\.)*[a-zA-Z_$][\w$]*$') NAME_REGEX = re.compile('^[A-Za-z_][\w]*$') +error.register.E002(description='Yaml Error') error.register.E005(description='YAML multi document is not allowed') error.register.E020(description='Missing required key') error.register.E021(description='Unknown keyword')