# Path: toscaparser/common/exception.py
# class InvalidTOSCAVersionPropertyException(TOSCAException):
#     msg_fmt = _('Value of TOSCA version property "%(what)s" is invalid.')
# 
# Path: toscaparser/tests/base.py
# class TestCase(testscenarios.TestWithScenarios, testtools.TestCase):
# 
#     """Test case base class for all unit tests."""
# 
#     def setUp(self):
#         """Run before each test method to initialize test environment."""
# 
#         super(TestCase, self).setUp()
#         test_timeout = os.environ.get('OS_TEST_TIMEOUT', 0)
#         try:
#             test_timeout = int(test_timeout)
#         except ValueError:
#             # If timeout value is invalid do not set a timeout.
#             test_timeout = 0
#         if test_timeout > 0:
#             self.useFixture(fixtures.Timeout(test_timeout, gentle=True))
# 
#         self.useFixture(fixtures.NestedTempfile())
#         self.useFixture(fixtures.TempHomeDir())
# 
#         if os.environ.get('OS_STDOUT_CAPTURE') in _TRUE_VALUES:
#             stdout = self.useFixture(fixtures.StringStream('stdout')).stream
#             self.useFixture(fixtures.MonkeyPatch('sys.stdout', stdout))
#         if os.environ.get('OS_STDERR_CAPTURE') in _TRUE_VALUES:
#             stderr = self.useFixture(fixtures.StringStream('stderr')).stream
#             self.useFixture(fixtures.MonkeyPatch('sys.stderr', stderr))
# 
#         self.log_fixture = self.useFixture(fixtures.FakeLogger())
# 
#     def _load_template(self, filename):
#         """Load a Tosca template from tests data folder.
# 
#         :param filename: Tosca template file name to load.
#         :return: ToscaTemplate
#         """
#         return ToscaTemplate(os.path.join(
#             os.path.dirname(os.path.abspath(__file__)),
#             'data',
#             filename))
# 
# Path: toscaparser/utils/gettextutils.py
# def _(msg):
#     # type: (object) -> object
#     return _t.gettext(msg)
# 
# Path: toscaparser/utils/validateutils.py
# class TOSCAVersionProperty(object):
# 
#     VERSION_RE = re.compile(r'^(?P<major_version>([0-9][0-9]*))'
#                             r'(\.(?P<minor_version>([0-9][0-9]*)))?'
#                             r'(\.(?P<fix_version>([0-9][0-9]*)))?'
#                             r'(\.(?P<qualifier>([0-9A-Za-z]+)))?'
#                             r'(\-(?P<build_version>[0-9])*)?$')
# 
#     def __init__(self, version):
#         self.version = str(version)
#         match = self.VERSION_RE.match(self.version)
#         if not match:
#             ExceptionCollector.appendException(
#                 InvalidTOSCAVersionPropertyException(what=(self.version)))
#             return
#         ver = match.groupdict()
#         if self.version in ['0', '0.0', '0.0.0']:
#             log.warning('Version assumed as not provided')
#             self.version = None
#         self.minor_version = ver['minor_version']
#         self.major_version = ver['major_version']
#         self.fix_version = ver['fix_version']
#         self.qualifier = self._validate_qualifier(ver['qualifier'])
#         self.build_version = self._validate_build(ver['build_version'])
#         self._validate_major_version(self.major_version)
# 
#     def _validate_major_version(self, value):
#         """Validate major version
# 
#         Checks if only major version is provided and assumes
#         minor version as 0.
#         Eg: If version = 18, then it returns version = '18.0'
#         """
# 
#         if self.minor_version is None and self.build_version is None and \
#                 value != '0':
#             log.warning('Minor version assumed "0".')
#             self.version = '.'.join([value, '0'])
#         return value
# 
#     def _validate_qualifier(self, value):
#         """Validate qualifier
# 
#            TOSCA version is invalid if a qualifier is present without the
#            fix version or with all of major, minor and fix version 0s.
# 
#            For example, the following versions are invalid
#               18.0.abc
#               0.0.0.abc
#         """
#         if (self.fix_version is None and value) or \
#             (self.minor_version == self.major_version ==
#              self.fix_version == '0' and value):
#             ExceptionCollector.appendException(
#                 InvalidTOSCAVersionPropertyException(what=(self.version)))
#         return value
# 
#     def _validate_build(self, value):
#         """Validate build version
# 
#            TOSCA version is invalid if build version is present without the
#            qualifier.
#            Eg: version = 18.0.0-1 is invalid.
#         """
#         if not self.qualifier and value:
#             ExceptionCollector.appendException(
#                 InvalidTOSCAVersionPropertyException(what=(self.version)))
#         return value
# 
#     def get_version(self):
#         return self.version


from toscaparser.common.exception import (
    InvalidTOSCAVersionPropertyException)
from toscaparser.tests.base import TestCase
from toscaparser.utils.gettextutils import _
from toscaparser.utils.validateutils import TOSCAVersionProperty

        version = 0
        expected_output = None
        output = TOSCAVersionProperty(version).get_version()
        self.assertEqual(output, expected_output)

        version = 00
        expected_output = None
        output = TOSCAVersionProperty(version).get_version()
        self.assertEqual(output, expected_output)

        version = 0.0
        expected_output = None
        output = TOSCAVersionProperty(version).get_version()
        self.assertEqual(output, expected_output)

        version = 00.00
        expected_output = None
        output = TOSCAVersionProperty(version).get_version()
        self.assertEqual(output, expected_output)

        version = '0.0.0'
        expected_output = None
        output = TOSCAVersionProperty(version).get_version()
        self.assertEqual(output, expected_output)

    def test_tosca_version_property_invalid_major_version(self):

        version = 'x'
        exp_msg = _('Value of TOSCA version property "x" is invalid.')

# Path: toscaparser/common/exception.py
# class InvalidTOSCAVersionPropertyException(TOSCAException):
#     msg_fmt = _('Value of TOSCA version property "%(what)s" is invalid.')
# 
# Path: toscaparser/tests/base.py
# class TestCase(testscenarios.TestWithScenarios, testtools.TestCase):
# 
#     """Test case base class for all unit tests."""
# 
#     def setUp(self):
#         """Run before each test method to initialize test environment."""
# 
#         super(TestCase, self).setUp()
#         test_timeout = os.environ.get('OS_TEST_TIMEOUT', 0)
#         try:
#             test_timeout = int(test_timeout)
#         except ValueError:
#             # If timeout value is invalid do not set a timeout.
#             test_timeout = 0
#         if test_timeout > 0:
#             self.useFixture(fixtures.Timeout(test_timeout, gentle=True))
# 
#         self.useFixture(fixtures.NestedTempfile())
#         self.useFixture(fixtures.TempHomeDir())
# 
#         if os.environ.get('OS_STDOUT_CAPTURE') in _TRUE_VALUES:
#             stdout = self.useFixture(fixtures.StringStream('stdout')).stream
#             self.useFixture(fixtures.MonkeyPatch('sys.stdout', stdout))
#         if os.environ.get('OS_STDERR_CAPTURE') in _TRUE_VALUES:
#             stderr = self.useFixture(fixtures.StringStream('stderr')).stream
#             self.useFixture(fixtures.MonkeyPatch('sys.stderr', stderr))
# 
#         self.log_fixture = self.useFixture(fixtures.FakeLogger())
# 
#     def _load_template(self, filename):
#         """Load a Tosca template from tests data folder.
# 
#         :param filename: Tosca template file name to load.
#         :return: ToscaTemplate
#         """
#         return ToscaTemplate(os.path.join(
#             os.path.dirname(os.path.abspath(__file__)),
#             'data',
#             filename))
# 
# Path: toscaparser/utils/gettextutils.py
# def _(msg):
#     # type: (object) -> object
#     return _t.gettext(msg)
# 
# Path: toscaparser/utils/validateutils.py
# class TOSCAVersionProperty(object):
# 
#     VERSION_RE = re.compile(r'^(?P<major_version>([0-9][0-9]*))'
#                             r'(\.(?P<minor_version>([0-9][0-9]*)))?'
#                             r'(\.(?P<fix_version>([0-9][0-9]*)))?'
#                             r'(\.(?P<qualifier>([0-9A-Za-z]+)))?'
#                             r'(\-(?P<build_version>[0-9])*)?$')
# 
#     def __init__(self, version):
#         self.version = str(version)
#         match = self.VERSION_RE.match(self.version)
#         if not match:
#             ExceptionCollector.appendException(
#                 InvalidTOSCAVersionPropertyException(what=(self.version)))
#             return
#         ver = match.groupdict()
#         if self.version in ['0', '0.0', '0.0.0']:
#             log.warning('Version assumed as not provided')
#             self.version = None
#         self.minor_version = ver['minor_version']
#         self.major_version = ver['major_version']
#         self.fix_version = ver['fix_version']
#         self.qualifier = self._validate_qualifier(ver['qualifier'])
#         self.build_version = self._validate_build(ver['build_version'])
#         self._validate_major_version(self.major_version)
# 
#     def _validate_major_version(self, value):
#         """Validate major version
# 
#         Checks if only major version is provided and assumes
#         minor version as 0.
#         Eg: If version = 18, then it returns version = '18.0'
#         """
# 
#         if self.minor_version is None and self.build_version is None and \
#                 value != '0':
#             log.warning('Minor version assumed "0".')
#             self.version = '.'.join([value, '0'])
#         return value
# 
#     def _validate_qualifier(self, value):
#         """Validate qualifier
# 
#            TOSCA version is invalid if a qualifier is present without the
#            fix version or with all of major, minor and fix version 0s.
# 
#            For example, the following versions are invalid
#               18.0.abc
#               0.0.0.abc
#         """
#         if (self.fix_version is None and value) or \
#             (self.minor_version == self.major_version ==
#              self.fix_version == '0' and value):
#             ExceptionCollector.appendException(
#                 InvalidTOSCAVersionPropertyException(what=(self.version)))
#         return value
# 
#     def _validate_build(self, value):
#         """Validate build version
# 
#            TOSCA version is invalid if build version is present without the
#            qualifier.
#            Eg: version = 18.0.0-1 is invalid.
#         """
#         if not self.qualifier and value:
#             ExceptionCollector.appendException(
#                 InvalidTOSCAVersionPropertyException(what=(self.version)))
#         return value
# 
#     def get_version(self):
#         return self.version


# Path: toscaparser/tests/test_validate_tosca_version.py
from toscaparser.common.exception import (
    InvalidTOSCAVersionPropertyException)
from toscaparser.tests.base import TestCase
from toscaparser.utils.gettextutils import _
from toscaparser.utils.validateutils import TOSCAVersionProperty


        version = 0
        expected_output = None
        output = TOSCAVersionProperty(version).get_version()
        self.assertEqual(output, expected_output)

        version = 00
        expected_output = None
        output = TOSCAVersionProperty(version).get_version()
        self.assertEqual(output, expected_output)

        version = 0.0
        expected_output = None
        output = TOSCAVersionProperty(version).get_version()
        self.assertEqual(output, expected_output)

        version = 00.00
        expected_output = None
        output = TOSCAVersionProperty(version).get_version()
        self.assertEqual(output, expected_output)

        version = '0.0.0'
        expected_output = None
        output = TOSCAVersionProperty(version).get_version()
        self.assertEqual(output, expected_output)

    def test_tosca_version_property_invalid_major_version(self):

        version = 'x'
        exp_msg = _('Value of TOSCA version property "x" is invalid.')

        err = self.assertRaises(InvalidTOSCAVersionPropertyException,