def bootstrap_env(create=True): dir = tempfile.TemporaryDirectory() os.chdir(dir.name) execute('ver', ['init']) return dir
def test_specified_field_invalid_value(self): increase_value = 'asd' for field in Version.VALID_UP_FIELDS: with catch_streams() as streams, \ self.assertRaises(SystemExit): execute('ver', ['up', '--%s' % field, increase_value]) self.assertRegex(streams.err.getvalue(), r'(?ms).*argument value: invalid int value: \'%s\'' % increase_value) streams.err.truncate()
def test_specified_invalid_field(self): other_fields = set(Version.VALID_FIELDS) - set(Version.VALID_UP_FIELDS) other_fields.add('azsx') for field in other_fields: with catch_streams() as streams, \ self.assertRaises(SystemExit): execute('ver', ['up', '--%s' % field]) self.assertRegex(streams.err.getvalue(), r'(?ms).*unrecognized arguments: --%s' % field) streams.err.truncate()
def test_not_initialized(self): version_file = self.root / self.cfg.version_file version_file.unlink() with catch_streams() as streams,\ self.assertRaises(SystemExit): execute('ver', ['up']) self.assertRegex(streams.err.getvalue(), r'(?ms).*Version file .* doesn\'t exists')
def test_specified_increase_value(self): increase_value = 7 version = Version(self.cfg.default_init_version) version_expected = version.up(self.cfg.up_part, increase_value) version_file = self.root / self.cfg.version_file with catch_streams(): execute('ver', ['up', str(increase_value)]) with version_file.open('r') as fh: self.assertEqual(fh.read().strip(), str(version_expected))
def test_specified_increase_value(self): increase_value = 7 version = Version(self.cfg.default_init_version) version_expected = version.up(self.cfg.up_part, increase_value) version_file = self.root / self.cfg.version_file with catch_streams(): execute('ver', ['up', str(increase_value)]) with version_file.open('r') as fh: assert fh.read().strip() == str(version_expected)
def test_specified_invalid_field(self): other_fields = set(Version.VALID_FIELDS) - set(Version.VALID_UP_FIELDS) other_fields.add('azsx') for field in other_fields: with catch_streams() as streams, \ pytest.raises(SystemExit): execute('ver', ['up', '--%s' % field]) assert re.search(r'(?ms).*unrecognized arguments: --%s' % field, streams.err.getvalue()) streams.err.truncate()
def test_all_fields_together(self): version_file = self.root / self.cfg.version_file with catch_streams(): args = ['set', '--major', '7', '--minor', '8', '--patch', '1', '--prerelease', 'ZZZ', '--build', 'XXX'] execute('ver', args) assert version_file.is_file(), "%s is not a file (exists: %s)" % (version_file, version_file.exists()) with version_file.open('r') as fh: assert fh.read().strip() == '7.8.1-ZZZ+XXX'
def test_specified_field_invalid_value(self): increase_value = 'asd' for field in Version.VALID_UP_FIELDS: with catch_streams() as streams, \ pytest.raises(SystemExit): execute('ver', ['up', '--%s' % field, increase_value]) assert re.search( r'(?ms).*argument value: invalid int value: \'%s\'' % increase_value, streams.err.getvalue()) streams.err.truncate()
def test_specified_version(self): version = '1.2.3+asd' version_file = self.root / self.cfg.version_file with catch_streams(): execute('ver', ['set', version]) assert version_file.is_file(), "%s is not a file (exists: %s)" % (version_file, version_file.exists()) with version_file.open('r') as fh: assert fh.read().strip() == version
def test_not_initialized(self): version = '1.2.3+asd' version_file = self.root / self.cfg.version_file version_file.unlink() with catch_streams() as streams,\ pytest.raises(SystemExit): execute('ver', ['set', version]) assert re.search(r'(?ms).*Version file .* doesn\'t exists', streams.err.getvalue())
def test_empty(self): version = self.cfg.default_init_version version_file = self.root / self.cfg.version_file with catch_streams(): execute('ver', ['init']) assert version_file.is_file(), "%s is not a file (exists: %s)" % ( version_file, version_file.exists()) with version_file.open('r') as fh: assert fh.read().strip() == version
def test_version_file_exsists(self): version = '1.2.3+asd' version_file = self.root / self.cfg.version_file open(str(version_file), 'w').close() with catch_streams() as streams,\ pytest.raises(SystemExit): execute('ver', ['init', version]) assert re.search(r'Version file .* already exists', streams.err.getvalue())
def test_all_fields_together(self): version_file = self.root / self.cfg.version_file with catch_streams(): args = ['set', '--major', '7', '--minor', '8', '--patch', '1', '--prerelease', 'ZZZ', '--build', 'XXX'] execute('ver', args) self.assertTrue(version_file.is_file(), "%s is not a file (exists: %s)" % (version_file, version_file.exists())) with version_file.open('r') as fh: self.assertEqual(fh.read().strip(), '7.8.1-ZZZ+XXX')
def test_specified_version(self): version = '1.2.3+asd' version_file = self.root / self.cfg.version_file with catch_streams(): execute('ver', ['set', version]) self.assertTrue(version_file.is_file(), "%s is not a file (exists: %s)" % (version_file, version_file.exists())) with version_file.open('r') as fh: self.assertEqual(fh.read().strip(), version)
def test_empty(self): version = self.cfg.default_init_version version_file = self.root / self.cfg.version_file with catch_streams(): execute('ver', []) self.assertTrue(version_file.is_file(), "%s is not a file (exists: %s)" % (version_file, version_file.exists())) with version_file.open('r') as fh: self.assertEqual(fh.read().strip(), version)
def test_multiple_fields_together(self): for field1, field2 in itertools.permutations( ('minor', 'major', 'patch'), 2): with catch_streams() as streams, \ pytest.raises(SystemExit): execute('ver', ['up', '--%s' % field1, '--%s' % field2]) assert re.search( r'(?ms).*argument --(%s|%s)/-.: not allowed with argument --(%s|%s)/-.' % (field1, field2, field1, field2), streams.err.getvalue(), ) streams.err.truncate()
def test_specified_fields(self): version = Version(self.cfg.default_init_version) version_file = self.root / self.cfg.version_file for field, value in zip(Version.VALID_FIELDS, (2, 3, 4, 'asd', 'qwe')): with catch_streams(): execute('ver', ['set', '--%s' % field, str(value)]) version = version.set(field, value) assert version_file.is_file(), "%s is not a file (exists: %s)" % (version_file, version_file.exists()) with version_file.open('r') as fh: assert fh.read().strip() == str(version)
def test_multiple_fields_together(self): for field1, field2 in itertools.permutations(('minor', 'major', 'patch'), 2): with catch_streams() as streams, \ self.assertRaises(SystemExit): execute('ver', ['up', '--%s' % field1, '--%s' % field2]) self.assertRegex( streams.err.getvalue(), r'(?ms).*argument --(%s|%s)/-.: not allowed with argument --(%s|%s)/-.' % ( field1, field2, field1, field2 ) ) streams.err.truncate()
def test_specified_fields(self): version = Version(self.cfg.default_init_version) version_file = self.root / self.cfg.version_file for field, value in zip(Version.VALID_FIELDS, (2, 3, 4, 'asd', 'qwe')): with catch_streams(): execute('ver', ['set', '--%s' % field, str(value)]) version = version.set(field, value) self.assertTrue(version_file.is_file(), "%s is not a file (exists: %s)" % (version_file, version_file.exists())) with version_file.open('r') as fh: self.assertEqual(fh.read().strip(), str(version))
def test_specified_fields_invalid(self): for field, value in zip(Version.VALID_UP_FIELDS, ('a', 'b', 'c')): with catch_streams() as streams,\ self.assertRaises(SystemExit): execute('ver', ['set', '--%s' % field, str(value)]) self.assertRegex(streams.err.getvalue(), r'(?ms).*argument --%s.*invalid int value' % field) other_fields = set(Version.VALID_FIELDS) - set(Version.VALID_UP_FIELDS) for field, value in zip(other_fields, ('ążśź', 'ążśź')): with catch_streams() as streams: execute('ver', ['set', '--%s' % field, str(value)]) self.assertRegex(streams.err.getvalue(), r'(?ms).*Invalid value for field %s: %s' % (field, value)) streams.err.truncate()
def test_specified_fields_invalid(self): for field, value in zip(Version.VALID_UP_FIELDS, ('a', 'b', 'c')): with catch_streams() as streams,\ pytest.raises(SystemExit): execute('ver', ['set', '--%s' % field, str(value)]) assert re.search(r'(?ms).*argument --%s.*invalid int value' % field, streams.err.getvalue()) other_fields = set(Version.VALID_FIELDS) - set(Version.VALID_UP_FIELDS) for field, value in zip(other_fields, ('ążśź', 'ążśź')): with catch_streams() as streams: execute('ver', ['set', '--%s' % field, str(value)]) assert re.search(r'(?ms).*Invalid value for field %s: %s' % (field, value), streams.err.getvalue()) streams.err.truncate()
def test_specified_invalid_version(self): version = '1.a.3+asd' with catch_streams() as streams: ret_code = execute('ver', ['set', version]) self.assertEqual(ret_code, 2) self.assertRegex(streams.err.getvalue(), r'^InvalidVersionError:')
def test_specified_invalid_version(self): version = '1.a.3+asd' with catch_streams() as streams: ret_code = execute('ver', ['set', version]) assert ret_code == 2 assert re.search(r'^InvalidVersionError:', streams.err.getvalue())
def test_specified_field_specified_value(self): increase_value = 7 version = Version(self.cfg.default_init_version) version_file = self.root / self.cfg.version_file for field in Version.VALID_UP_FIELDS: version = version.up(field, increase_value) with catch_streams(): execute('ver', ['up', '--%s' % field, str(increase_value)]) with version_file.open('r') as fh: self.assertEqual(fh.read().strip(), str(version)) other_fields = set(Version.VALID_FIELDS) - set(Version.VALID_UP_FIELDS) for field in other_fields: with self.assertRaisesRegex(ValueError, r'Invalid field type: %s' % field): version.up(field, increase_value)
def test_specified_field_specified_value(self): increase_value = 7 version = Version(self.cfg.default_init_version) version_file = self.root / self.cfg.version_file for field in Version.VALID_UP_FIELDS: version = version.up(field, increase_value) with catch_streams(): execute('ver', ['up', '--%s' % field, str(increase_value)]) with version_file.open('r') as fh: assert fh.read().strip() == str(version) other_fields = set(Version.VALID_FIELDS) - set(Version.VALID_UP_FIELDS) for field in other_fields: with pytest.raises(ValueError) as exc: version.up(field, increase_value) assert re.search(r'Invalid field type: %s' % field, str(exc.value))
def test_without_version(self): with catch_streams() as streams, \ self.assertRaises(SystemExit): execute('ver', ['set']) self.assertRegex(streams.err.getvalue(), r'Version is not specified')
def test_without_version(self): with catch_streams() as streams, \ pytest.raises(SystemExit): execute('ver', ['set']) assert re.search(r'Version is not specified', streams.err.getvalue())