def testGetFile(self): """Testing CVSTool.get_file""" expected = "test content\n" file = 'test/testfile' rev = Revision('1.1') badrev = Revision('2.1') self.assertEqual(self.tool.get_file(file, rev), expected) self.assertEqual(self.tool.get_file(file + ",v", rev), expected) self.assertEqual( self.tool.get_file(self.tool.repopath + '/' + file + ",v", rev), expected) self.assert_(self.tool.file_exists('test/testfile')) self.assert_( self.tool.file_exists(self.tool.repopath + '/test/testfile')) self.assert_(self.tool.file_exists('test/testfile,v')) self.assert_(not self.tool.file_exists('test/testfile2')) self.assert_(not self.tool.file_exists(self.tool.repopath + '/test/testfile2')) self.assert_(not self.tool.file_exists('test/testfile2,v')) self.assert_(not self.tool.file_exists('test/testfile', badrev)) self.assertRaises(FileNotFoundError, lambda: self.tool.get_file('')) self.assertRaises(FileNotFoundError, lambda: self.tool.get_file('hello', PRE_CREATION))
def test_get_file(self): """Testing CVSTool.get_file""" expected = b'test content\n' file = 'test/testfile' rev = Revision('1.1') badrev = Revision('2.1') value = self.tool.get_file(file, rev) self.assertTrue(isinstance(value, bytes)) self.assertEqual(value, expected) self.assertEqual(self.tool.get_file(file + ',v', rev), expected) self.assertEqual( self.tool.get_file(self.tool.repopath + '/' + file + ',v', rev), expected) self.assertTrue(self.tool.file_exists('test/testfile')) self.assertTrue( self.tool.file_exists(self.tool.repopath + '/test/testfile')) self.assertTrue(self.tool.file_exists('test/testfile,v')) self.assertTrue(not self.tool.file_exists('test/testfile2')) self.assertTrue(not self.tool.file_exists(self.tool.repopath + '/test/testfile2')) self.assertTrue(not self.tool.file_exists('test/testfile2,v')) self.assertTrue(not self.tool.file_exists('test/testfile', badrev)) self.assertRaises(FileNotFoundError, lambda: self.tool.get_file('')) self.assertRaises(FileNotFoundError, lambda: self.tool.get_file('hello', PRE_CREATION))
def test_https_repo(self): """Testing HgTool.file_exists with an HTTPS-based repository""" repo = Repository(name='Test HG2', path='https://www.mercurial-scm.org/repo/hg', tool=Tool.objects.get(name='Mercurial')) tool = repo.get_scmtool() self.assertTrue( tool.file_exists('mercurial/hgweb/common.py', Revision('f0735f2ce542'))) self.assertFalse( tool.file_exists('mercurial/hgweb/common.py', Revision('abcdef123456')))
def testGetFile(self): """Testing SVNTool.get_file""" expected = 'include ../tools/Makefile.base-vars\nNAME = misc-docs\n' + \ 'OUTNAME = svn-misc-docs\nINSTALL_DIR = $(DESTDIR)/usr/s' + \ 'hare/doc/subversion\ninclude ../tools/Makefile.base-rul' + \ 'es\n' # There are 3 versions of this test in order to get 100% coverage of # the svn module. rev = Revision('2') file = 'trunk/doc/misc-docs/Makefile' self.assertEqual(self.tool.get_file(file, rev), expected) self.assertEqual(self.tool.get_file('/' + file, rev), expected) self.assertEqual( self.tool.get_file(self.repository.path + '/' + file, rev), expected) self.assert_(self.tool.file_exists('trunk/doc/misc-docs/Makefile')) self.assert_( not self.tool.file_exists('trunk/doc/misc-docs/Makefile2')) self.assertRaises(FileNotFoundError, lambda: self.tool.get_file('')) self.assertRaises(FileNotFoundError, lambda: self.tool.get_file('hello', PRE_CREATION))
def test_file_exists_with_special_url_chars(self): """Testing SVN (<backend>) file_exists with filename containing characters that are special in URLs """ self.assertTrue(self.tool.file_exists('trunk/crazy& ?#.txt', Revision('12'))) # These should not crash. We'll be testing both file:// URLs # (which fail for anything lower than ASCII code 32) and for actual # URLs (which support all characters). self.assertFalse(self.tool.file_exists('trunk/%s.txt' % ''.join( chr(c) for c in range(32, 128) ))) self.tool.client.repopath = 'svn+ssh://localhost:0/svn' try: self.assertFalse(self.tool.file_exists('trunk/%s.txt' % ''.join( chr(c) for c in range(128) ))) except SCMError: # Couldn't connect. Valid result. pass
def test_get_file(self): """Testing SVN (<backend>) get_file""" expected = (b'include ../tools/Makefile.base-vars\n' b'NAME = misc-docs\n' b'OUTNAME = svn-misc-docs\n' b'INSTALL_DIR = $(DESTDIR)/usr/share/doc/subversion\n' b'include ../tools/Makefile.base-rules\n') # There are 3 versions of this test in order to get 100% coverage of # the svn module. rev = Revision('2') file = 'trunk/doc/misc-docs/Makefile' value = self.tool.get_file(file, rev) self.assertTrue(isinstance(value, bytes)) self.assertEqual(value, expected) self.assertEqual(self.tool.get_file('/' + file, rev), expected) self.assertEqual( self.tool.get_file(self.repository.path + '/' + file, rev), expected) self.assertTrue(self.tool.file_exists('trunk/doc/misc-docs/Makefile')) self.assertTrue( not self.tool.file_exists('trunk/doc/misc-docs/Makefile2')) self.assertRaises(FileNotFoundError, lambda: self.tool.get_file('')) self.assertRaises(FileNotFoundError, lambda: self.tool.get_file('hello', PRE_CREATION))
def test_get_file(self): """Testing SVN (<backend>) get_file""" tool = self.tool expected = (b'include ../tools/Makefile.base-vars\n' b'NAME = misc-docs\n' b'OUTNAME = svn-misc-docs\n' b'INSTALL_DIR = $(DESTDIR)/usr/share/doc/subversion\n' b'include ../tools/Makefile.base-rules\n') # There are 3 versions of this test in order to get 100% coverage of # the svn module. rev = Revision('2') filename = 'trunk/doc/misc-docs/Makefile' value = tool.get_file(filename, rev) self.assertIsInstance(value, bytes) self.assertEqual(value, expected) value = tool.get_file('/%s' % filename, rev) self.assertIsInstance(value, bytes) self.assertEqual(value, expected) value = tool.get_file('%s/%s' % (self.repository.path, filename), rev) self.assertIsInstance(value, bytes) self.assertEqual(value, expected) with self.assertRaises(FileNotFoundError): tool.get_file('')
def test_get_file_with_special_url_chars(self): """Testing SVN (<backend>) get_file with filename containing characters that are special in URLs and repository path as a URI """ value = self.tool.get_file('trunk/crazy& ?#.txt', Revision('12')) self.assertTrue(isinstance(value, bytes)) self.assertEqual(value, b'Lots of characters in this one.\n')
def test_get_file_base_commit_id_override(self): """Testing base_commit_id overrides revision in HgTool.get_file""" base_commit_id = Revision('661e5dd3c493') bogus_rev = Revision('bogusrevision') file = 'doc/readme' value = self.tool.get_file(file, bogus_rev, base_commit_id=base_commit_id) self.assertTrue(isinstance(value, bytes)) self.assertEqual(value, b'Hello\n\ngoodbye\n') self.assertTrue( self.tool.file_exists('doc/readme', bogus_rev, base_commit_id=base_commit_id)) self.assertTrue(not self.tool.file_exists( 'doc/readme2', bogus_rev, base_commit_id=base_commit_id))
def test_bad_root(self): """Testing CVSTool with a bad CVSROOT""" file = 'test/testfile' rev = Revision('1.1') badrepo = Repository(name='CVS', path=self.cvs_repo_path + '2', tool=Tool.objects.get(name='CVS')) badtool = badrepo.get_scmtool() self.assertRaises(SCMError, lambda: badtool.get_file(file, rev))
def test_get_file_with_keywords(self): """Testing CVSTool.get_file with file containing keywords""" value = self.tool.get_file('test/testfile', Revision('1.2')) self.assertEqual( value, '$Id$\n' '$Author$\n' '\n' 'test content\n')
def test_https_repo(self): """Testing HgTool.file_exists with an HTTPS-based repository""" repo = Repository(name='Test HG2', path='https://bitbucket.org/pypy/pypy', tool=Tool.objects.get(name='Mercurial')) tool = repo.get_scmtool() rev = Revision('877cf1960916') self.assertTrue(tool.file_exists('TODO.rst', rev)) self.assertTrue(not tool.file_exists('TODO.rstNotFound', rev))
def test_file_exists(self): """Testing CVSTool.file_exists""" tool = self.tool self.assertTrue(tool.file_exists('test/testfile')) self.assertTrue(tool.file_exists('%s/test/testfile' % tool.repopath)) self.assertTrue(tool.file_exists('test/testfile,v')) self.assertFalse(tool.file_exists('test/testfile2')) self.assertFalse(tool.file_exists('%s/test/testfile2' % tool.repopath)) self.assertFalse(tool.file_exists('test/testfile2,v')) self.assertFalse(tool.file_exists('test/testfile', Revision('2.1')))
def test_get_file(self): """Testing HgTool.get_file""" tool = self.tool value = tool.get_file('doc/readme', Revision('661e5dd3c493')) self.assertIsInstance(value, bytes) self.assertEqual(value, b'Hello\n\ngoodbye\n') with self.assertRaises(FileNotFoundError): tool.get_file('') with self.assertRaises(FileNotFoundError): tool.get_file('hello', PRE_CREATION)
def testGetFile(self): """Testing HgTool.get_file""" rev = Revision('661e5dd3c493') file = 'doc/readme' self.assertEqual(self.tool.get_file(file, rev), 'Hello\n\ngoodbye\n') self.assert_(self.tool.file_exists('doc/readme')) self.assert_(not self.tool.file_exists('doc/readme2')) self.assertRaises(FileNotFoundError, lambda: self.tool.get_file('')) self.assertRaises(FileNotFoundError, lambda: self.tool.get_file('hello', PRE_CREATION))
def test_get_file(self): """Testing HgTool.get_file""" rev = Revision('661e5dd3c493') file = 'doc/readme' value = self.tool.get_file(file, rev) self.assertTrue(isinstance(value, bytes)) self.assertEqual(value, b'Hello\n\ngoodbye\n') self.assertTrue(self.tool.file_exists('doc/readme', rev)) self.assertTrue(not self.tool.file_exists('doc/readme2', rev)) self.assertRaises(FileNotFoundError, lambda: self.tool.get_file('')) self.assertRaises(FileNotFoundError, lambda: self.tool.get_file('hello', PRE_CREATION))
def testUnterminatedKeywordDiff(self): """Testing parsing SVN diff with unterminated keywords""" diff = "Index: Makefile\n" \ "===========================================================" \ "========\n" \ "--- Makefile (revision 4)\n" \ "+++ Makefile (working copy)\n" \ "@@ -1,6 +1,7 @@\n" \ " # $Id$\n" \ " # $Id:\n" \ " # $Rev$\n" \ " # $Revision:: $\n" \ "+# foo\n" \ " include ../tools/Makefile.base-vars\n" \ " NAME = misc-docs\n" \ " OUTNAME = svn-misc-docs\n" filename = 'trunk/doc/misc-docs/Makefile' rev = Revision('5') file = self.tool.get_file(filename, rev) patch(diff, file, filename)
def test_unterminated_keyword_diff(self): """Testing SVN (<backend>) parsing diff with unterminated keywords""" diff = (b'Index: Makefile\n' b'===========================================================' b'========\n' b'--- Makefile (revision 4)\n' b'+++ Makefile (working copy)\n' b'@@ -1,6 +1,7 @@\n' b' # $Id$\n' b' # $Id:\n' b' # $Rev$\n' b' # $Revision:: $\n' b'+# foo\n' b' include ../tools/Makefile.base-vars\n' b' NAME = misc-docs\n' b' OUTNAME = svn-misc-docs\n') filename = 'trunk/doc/misc-docs/Makefile' rev = Revision('5') file = self.tool.get_file(filename, rev) patch(diff, file, filename)
def test_keyword_diff(self): """Testing SVN (<backend>) parsing diff with keywords""" # 'svn cat' will expand special variables in svn:keywords, # but 'svn diff' doesn't expand anything. This causes the # patch to fail if those variables appear in the patch context. diff = (b'Index: Makefile\n' b'===========================================================' b'========\n' b'--- Makefile (revision 4)\n' b'+++ Makefile (working copy)\n' b'@@ -1,6 +1,7 @@\n' b' # $Id$\n' b' # $Rev$\n' b' # $Revision:: $\n' b'+# foo\n' b' include ../tools/Makefile.base-vars\n' b' NAME = misc-docs\n' b' OUTNAME = svn-misc-docs\n') filename = 'trunk/doc/misc-docs/Makefile' rev = Revision('4') file = self.tool.get_file(filename, rev) patch(diff, file, filename)
def test_get_file(self): """Testing CVSTool.get_file""" tool = self.tool expected = b'test content\n' filename = 'test/testfile' rev = Revision('1.1') value = tool.get_file(filename, rev) self.assertIsInstance(value, bytes) self.assertEqual(value, expected) value = tool.get_file('%s,v' % filename, rev) self.assertIsInstance(value, bytes) self.assertEqual(value, expected) value = tool.get_file('%s/%s,v' % (tool.repopath, filename), rev) self.assertIsInstance(value, bytes) self.assertEqual(value, expected) with self.assertRaises(FileNotFoundError): tool.get_file('') with self.assertRaises(FileNotFoundError): tool.get_file('hello', PRE_CREATION)
def test_file_exists(self): """Testing HgTool.file_exists""" rev = Revision('661e5dd3c493') self.assertTrue(self.tool.file_exists('doc/readme', rev)) self.assertFalse(self.tool.file_exists('doc/readme2', rev))
def test_file_exists_with_special_url_chars(self): """Testing SVN (<backend>) file_exists with filename containing characters that are special in URLs """ self.assertTrue(self.tool.file_exists('trunk/crazy& ?#.txt', Revision('12')))