def test_validate(self): with workspace() as wksp: with codecs.open('changelog', 'wb', encoding='utf8') as f: f.write('') self.releaser.config.__getitem__.return_value = ObjectDict( {'file': 'changelog'}) ChangelogHook(self.releaser)
def test_bump(self): content = dedent('''\ Dev ### - some changes ''') with workspace() as wksp: with codecs.open('changelog', 'wb', encoding='utf8') as f: f.write(content) self.releaser.config.__getitem__.return_value = ObjectDict({ 'file': 'changelog', 'separator': '#', 'bump': '{version} {date:%Y-%m-%d}', 'prepare': 'Dev', 'empty': 'Empty', }) hook = ChangelogHook(self.releaser) hook.bump([]) expected = dedent('''\ 1.2.3 {0:%Y-%m-%d} ################ - some changes ''').format(self.releaser.timestamp) self.releaser.perform.assert_called_once_with('changelog', content, expected)
def test_validate_ko_not_bazaar(self): with workspace('bazaar') as wksp: bazaar = Bazaar() with patch('bumpr.vcs.execute') as execute: with self.assertRaises(BumprError): bazaar.validate() self.assertFalse(execute.called)
def test_commit(self): config = Config({'file': 'fake.py', 'vcs': 'fake'}) with workspace('fake') as wksp: releaser = Releaser(config) with patch.object(releaser, 'vcs') as vcs: releaser.commit('message') vcs.commit.assert_called_with('message')
def test_validate_ko_not_git(self): with workspace('git'): git = Git() with patch('bumpr.vcs.execute') as execute: with self.assertRaises(BumprError): git.validate() self.assertFalse(execute.called)
def test_validate_ko_not_mercurial(self): with workspace('mercurial'): mercurial = Mercurial() with patch('bumpr.vcs.execute') as execute: with self.assertRaises(BumprError): mercurial.validate() self.assertFalse(execute.called)
def test_validate_ko_not_mercurial(self): with workspace('mercurial') as wksp: mercurial = Mercurial() with patch('bumpr.vcs.execute') as execute: with self.assertRaises(BumprError): mercurial.validate() self.assertFalse(execute.called)
def test_tag(self): config = Config({'file': 'fake.py', 'vcs': 'fake'}) with workspace('fake') as wksp: releaser = Releaser(config) with patch.object(releaser, 'vcs') as vcs: releaser.tag() vcs.tag.assert_called_with(str(releaser.version))
def test_validate_ko_not_bazaar(self): with workspace('bazaar'): bazaar = Bazaar() with patch('bumpr.vcs.execute') as execute: with self.assertRaises(BumprError): bazaar.validate() self.assertFalse(execute.called)
def test_validate_ko_not_git(self): with workspace('git') as wksp: git = Git() with patch('bumpr.vcs.execute') as execute: with self.assertRaises(BumprError): git.validate() self.assertFalse(execute.called)
def test_validate_ok(self): with workspace('bazaar'): os.mkdir('.bzr') bazaar = Bazaar() with patch('bumpr.vcs.execute') as execute: execute.return_value = '? new.py' bazaar.validate() execute.assert_called_with('bzr status --short', verbose=False)
def test_validate_ok(self): with workspace('mercurial'): os.mkdir('.hg') mercurial = Mercurial() with patch('bumpr.vcs.execute') as execute: execute.return_value = '?? new.py' mercurial.validate() execute.assert_called_with('hg status -mard', verbose=False)
def test_validate_ok(self): with workspace('git'): os.mkdir('.git') git = Git() with patch('bumpr.vcs.execute') as execute: execute.return_value = '?? new.py' git.validate() execute.assert_called_with('git status --porcelain', verbose=False)
def test_validate_ok(self): with workspace('bazaar') as wksp: os.mkdir('.bzr') bazaar = Bazaar() with patch('bumpr.vcs.execute') as execute: execute.return_value = '? new.py' bazaar.validate() execute.assert_called_with('bzr status --short', verbose=False)
def test_validate_ok(self): with workspace('mercurial') as wksp: os.mkdir('.hg') mercurial = Mercurial() with patch('bumpr.vcs.execute') as execute: execute.return_value = '?? new.py' mercurial.validate() execute.assert_called_with('hg status -mard', verbose=False)
def test_validate_ko_not_clean(self): with workspace('mercurial'): os.mkdir('.hg') mercurial = Mercurial() with patch('bumpr.vcs.execute') as execute: execute.return_value = '\n'.join((' M modified.py', '?? new.py')) with self.assertRaises(BumprError): mercurial.validate() execute.assert_called_with('hg status -mard', verbose=False)
def test_validate_ko_not_clean(self): with workspace('bazaar'): os.mkdir('.bzr') bazaar = Bazaar() with patch('bumpr.vcs.execute') as execute: execute.return_value = '\n'.join((' M modified.py', '? new.py')) with self.assertRaises(BumprError): bazaar.validate() execute.assert_called_with('bzr status --short', verbose=False)
def test_validate_ko_not_clean(self): with workspace('git'): os.mkdir('.git') git = Git() with patch('bumpr.vcs.execute') as execute: execute.return_value = '\n'.join((' M modified.py', '?? new.py')) with self.assertRaises(BumprError): git.validate() execute.assert_called_with('git status --porcelain', verbose=False)
def test_validate_ok(self): with workspace('git') as wksp: os.mkdir('.git') git = Git() with patch('bumpr.vcs.execute') as execute: execute.return_value = '?? new.py' git.validate() execute.assert_called_with('git status --porcelain', verbose=False)
def test_validate_ko_not_clean(self): with workspace('mercurial') as wksp: os.mkdir('.hg') mercurial = Mercurial() with patch('bumpr.vcs.execute') as execute: execute.return_value = '\n'.join( (' M modified.py', '?? new.py')) with self.assertRaises(BumprError): mercurial.validate() execute.assert_called_with('hg status -mard', verbose=False)
def test_validate_ko_not_clean(self): with workspace('bazaar') as wksp: os.mkdir('.bzr') bazaar = Bazaar() with patch('bumpr.vcs.execute') as execute: execute.return_value = '\n'.join( (' M modified.py', '? new.py')) with self.assertRaises(BumprError): bazaar.validate() execute.assert_called_with('bzr status --short', verbose=False)
def test_clean(self): config = Config({ 'file': 'fake.py', 'clean': 'clean command', }) with workspace('fake'): releaser = Releaser(config) with patch('bumpr.releaser.execute') as execute: releaser.clean() execute.assert_called_with('clean command', replacements=ANY, dryrun=ANY, verbose=ANY)
def test_validate_ko_not_clean(self): with workspace('git') as wksp: os.mkdir('.git') git = Git() with patch('bumpr.vcs.execute') as execute: execute.return_value = '\n'.join( (' M modified.py', '?? new.py')) with self.assertRaises(BumprError): git.validate() execute.assert_called_with('git status --porcelain', verbose=False)
def test_bump(self): with workspace('fake', '1.2.3.dev') as wksp: config = Config({'file': 'fake.py', 'files': [wksp.readme]}) releaser = Releaser(config) with patch.object(releaser, 'commit') as commit: with patch.object(releaser, 'tag') as tag: releaser.bump() self.assertFalse(commit.called) self.assertFalse(tag.called) for filename in wksp.module, wksp.readme: with open(filename) as f: content = f.read() self.assertIn('1.2.3', content) self.assertNotIn('1.2.3.dev', content)
def test_constructor_with_hooks(self): config = Config({'file': 'fake.py'}) hooks = [] for i in range(3): key = 'hook{0}'.format(i) config[key] = True mock = MagicMock() mock.key = key hooks.append(mock) with workspace('fake', '1.2.3.dev') as wksp: with patch('bumpr.releaser.HOOKS', hooks) as mock: releaser = Releaser(config) for hook in hooks: hook.assert_called_with(releaser)
def test_release_wihtout_vcs_or_commands(self): with workspace('fake', '1.2.3.dev') as wksp: config = Config({'file': 'fake.py', 'files': [wksp.readme]}) releaser = Releaser(config) with patch('bumpr.releaser.execute') as execute: with patch.object(releaser, 'commit') as commit: releaser.release() self.assertFalse(execute.called) self.assertFalse(commit.called) for filename in wksp.module, wksp.readme: with open(filename) as f: content = f.read() self.assertIn('1.2.3', content) self.assertNotIn('1.2.3.dev', content)
def test_constructor(self): config = Config({'file': 'fake.py'}) with workspace('fake', '1.2.3.dev') as wksp: releaser = Releaser(config) self.assertIsInstance(releaser.prev_version, Version) self.assertEqual(str(releaser.prev_version), '1.2.3.dev') self.assertIsInstance(releaser.version, Version) self.assertIsInstance(releaser.next_version, Version) self.assertIsNone(releaser.timestamp) self.assertFalse(hasattr(releaser, 'vcs')) self.assertFalse(hasattr(releaser, 'diffs')) self.assertEqual(releaser.hooks, [])
def test_constructor_with_hooks(self): config = Config({ 'file': 'fake.py' }) hooks = [] for i in range(3): key = 'hook{0}'.format(i) config[key] = True mock = MagicMock() mock.key = key hooks.append(mock) with workspace('fake', '1.2.3.dev') as wksp: with patch('bumpr.releaser.HOOKS', hooks) as mock: releaser = Releaser(config) for hook in hooks: hook.assert_called_with(releaser)
def test_constructor(self): config = Config({ 'file': 'fake.py' }) with workspace('fake', '1.2.3.dev') as wksp: releaser = Releaser(config) self.assertIsInstance(releaser.prev_version, Version) self.assertEqual(str(releaser.prev_version), '1.2.3.dev') self.assertIsInstance(releaser.version, Version) self.assertIsInstance(releaser.next_version, Version) self.assertIsNone(releaser.timestamp) self.assertFalse(hasattr(releaser, 'vcs')) self.assertFalse(hasattr(releaser, 'diffs')) self.assertEqual(releaser.hooks, [])
def test_prepare(self): content = dedent('''\ 1.2.3 {0:%Y-%m-%d} ################ - some changes ''').format(self.releaser.timestamp) with workspace() as wksp: with codecs.open('changelog', 'wb', encoding='utf8') as f: f.write(content) self.releaser.config.__getitem__.return_value = ObjectDict({ 'file': 'changelog', 'separator': '#', 'bump': '{version} {date:%Y-%m-%d}', 'prepare': 'Dev', 'empty': 'Empty', }) hook = ChangelogHook(self.releaser) hook.prepare([]) expected = dedent('''\ Dev ### - Empty 1.2.3 {0:%Y-%m-%d} ################ - some changes ''').format(self.releaser.timestamp) self.releaser.perform.assert_called_once_with( 'changelog', content, expected)
def test_release_dryrun(self): with workspace('fake', '1.2.3.dev') as wksp: config = Config({ 'file': 'fake.py', 'files': [wksp.readme], 'vcs': 'fake', 'dryrun': True, }) releaser = Releaser(config) with patch('bumpr.releaser.execute') as execute: with patch.object(releaser, 'vcs') as vcs: releaser.release() self.assertFalse(execute.called) self.assertFalse(vcs.commit.called) self.assertFalse(vcs.tag.called) for filename in wksp.module, wksp.readme: with open(filename) as f: content = f.read() self.assertIn('1.2.3.dev', content) self.assertNotIn('1.2.4', content)
def test_prepare(self): with workspace('fake', '1.2.3') as wksp: config = Config({ 'file': 'fake.py', 'files': [wksp.readme], 'prepare': { 'part': Version.PATCH, 'suffix': 'dev', } }) releaser = Releaser(config) with patch.object(releaser, 'commit') as commit: with patch.object(releaser, 'tag') as tag: releaser.prepare() self.assertFalse(commit.called) self.assertFalse(tag.called) for filename in wksp.module, wksp.readme: with open(filename) as f: content = f.read() self.assertIn('1.2.4.dev', content) self.assertNotIn('1.2.3', content)
def test_validate_file_does_not_exists(self): with workspace(): self.releaser.config.__getitem__.return_value = ObjectDict( {'file': 'changelog'}) with self.assertRaises(BumprError): hook = ChangelogHook(self.releaser)
def test_validate_file_does_not_exists(self): with workspace(): self.releaser.config.__getitem__.return_value = ObjectDict({'file': 'changelog'}) with self.assertRaises(BumprError): hook = ChangelogHook(self.releaser)
def test_validate(self): with workspace() as wksp: with codecs.open('changelog', 'wb', encoding='utf8') as f: f.write('') self.releaser.config.__getitem__.return_value = ObjectDict({'file': 'changelog'}) ChangelogHook(self.releaser)