"Fossies" - the Fresh Open Source Software Archive

Member "buildbot-2.3.1/buildbot/test/unit/test_changes_mail_CVSMaildirSource.py" (23 May 2019, 7497 Bytes) of package /linux/misc/buildbot-2.3.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. See also the last Fossies "Diffs" side-by-side code changes report for "test_changes_mail_CVSMaildirSource.py": 1.8.0_vs_2.0.0.

    1 # This file is part of Buildbot.  Buildbot is free software: you can
    2 # redistribute it and/or modify it under the terms of the GNU General Public
    3 # License as published by the Free Software Foundation, version 2.
    4 #
    5 # This program is distributed in the hope that it will be useful, but WITHOUT
    6 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    7 # FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
    8 # details.
    9 #
   10 # You should have received a copy of the GNU General Public License along with
   11 # this program; if not, write to the Free Software Foundation, Inc., 51
   12 # Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
   13 #
   14 # Copyright Buildbot Team Members
   15 
   16 from email import message_from_string
   17 from email.utils import mktime_tz
   18 from email.utils import parsedate_tz
   19 
   20 from twisted.trial import unittest
   21 
   22 from buildbot.changes.mail import CVSMaildirSource
   23 
   24 #
   25 # Sample message from CVS version 1.11
   26 #
   27 
   28 cvs1_11_msg = """From: Andy Howell <andy@example.com>
   29 To: buildbot@example.com
   30 Subject: cvs module MyModuleName
   31 Date: Sat, 07 Aug 2010 11:11:49 +0000
   32 X-Mailer: Python buildbot-cvs-mail $Revision: 1.3 $
   33 
   34 Cvsmode: 1.11
   35 Category: None
   36 CVSROOT: :ext:cvshost.example.com:/cvsroot
   37 Files: base/module/src/make GNUmakefile,1.362,1.363
   38 Project: MyModuleName
   39 Update of /cvsroot/base/module/src/make
   40 In directory cvshost:/tmp/cvs-serv10922
   41 
   42 Modified Files:
   43         GNUmakefile
   44 Log Message:
   45 Commented out some stuff.
   46 """
   47 
   48 #
   49 # Sample message from CVS version 1.12
   50 #
   51 # Paths are handled differently by the two versions
   52 #
   53 
   54 cvs1_12_msg = """Date: Wed, 11 Aug 2010 04:56:44 +0000
   55 From: andy@example.com
   56 To: buildbot@example.com
   57 Subject: cvs update for project RaiCore
   58 X-Mailer: Python buildbot-cvs-mail $Revision: 1.3 $
   59 
   60 Cvsmode: 1.12
   61 Category: None
   62 CVSROOT: :ext:cvshost.example.com:/cvsroot
   63 Files: file1.cpp 1.77 1.78 file2.cpp 1.75 1.76
   64 Path: base/module/src
   65 Project: MyModuleName
   66 Update of /cvsroot/base/module/src
   67 In directory example.com:/tmp/cvs-serv26648/InsightMonAgent
   68 
   69 Modified Files:
   70         file1.cpp file2.cpp
   71 Log Message:
   72 Changes for changes sake
   73 """
   74 
   75 
   76 class TestCVSMaildirSource(unittest.TestCase):
   77 
   78     def test_CVSMaildirSource_create_change_from_cvs1_11msg(self):
   79         m = message_from_string(cvs1_11_msg)
   80         src = CVSMaildirSource('/dev/null')
   81         src, chdict = src.parse(m)
   82         self.assertNotEqual(chdict, None)
   83         self.assertEqual(chdict['author'], 'andy')
   84         self.assertEqual(len(chdict['files']), 1)
   85         self.assertEqual(
   86             chdict['files'][0], 'base/module/src/make/GNUmakefile')
   87         self.assertEqual(chdict['comments'], 'Commented out some stuff.\n')
   88         self.assertFalse(chdict['isdir'])
   89         self.assertEqual(chdict['revision'], '2010-08-07 11:11:49')
   90         dateTuple = parsedate_tz('Sat, 07 Aug 2010 11:11:49 +0000')
   91         self.assertEqual(chdict['when'], mktime_tz(dateTuple))
   92         self.assertEqual(chdict['branch'], None)
   93         self.assertEqual(
   94             chdict['repository'], ':ext:cvshost.example.com:/cvsroot')
   95         self.assertEqual(chdict['project'], 'MyModuleName')
   96         self.assertEqual(len(chdict['properties']), 0)
   97         self.assertEqual(src, 'cvs')
   98 
   99     def test_CVSMaildirSource_create_change_from_cvs1_12msg(self):
  100         m = message_from_string(cvs1_12_msg)
  101         src = CVSMaildirSource('/dev/null')
  102         src, chdict = src.parse(m)
  103         self.assertNotEqual(chdict, None)
  104         self.assertEqual(chdict['author'], 'andy')
  105         self.assertEqual(len(chdict['files']), 2)
  106         self.assertEqual(chdict['files'][0], 'base/module/src/file1.cpp')
  107         self.assertEqual(chdict['files'][1], 'base/module/src/file2.cpp')
  108         self.assertEqual(chdict['comments'], 'Changes for changes sake\n')
  109         self.assertFalse(chdict['isdir'])
  110         self.assertEqual(chdict['revision'], '2010-08-11 04:56:44')
  111         dateTuple = parsedate_tz('Wed, 11 Aug 2010 04:56:44 +0000')
  112         self.assertEqual(chdict['when'], mktime_tz(dateTuple))
  113         self.assertEqual(chdict['branch'], None)
  114         self.assertEqual(
  115             chdict['repository'], ':ext:cvshost.example.com:/cvsroot')
  116         self.assertEqual(chdict['project'], 'MyModuleName')
  117         self.assertEqual(len(chdict['properties']), 0)
  118         self.assertEqual(src, 'cvs')
  119 
  120     def test_CVSMaildirSource_create_change_from_cvs1_12_with_no_path(self):
  121         msg = cvs1_12_msg.replace('Path: base/module/src', '')
  122         m = message_from_string(msg)
  123         src = CVSMaildirSource('/dev/null')
  124         try:
  125             assert src.parse(m)[1]
  126         except ValueError:
  127             pass
  128         else:
  129             self.fail('Expect ValueError.')
  130 
  131     def test_CVSMaildirSource_create_change_with_bad_cvsmode(self):
  132         # Branch is indicated after 'Tag:' in modified file list
  133         msg = cvs1_11_msg.replace('Cvsmode: 1.11', 'Cvsmode: 9.99')
  134         m = message_from_string(msg)
  135         src = CVSMaildirSource('/dev/null')
  136         try:
  137             assert src.parse(m)[1]
  138         except ValueError:
  139             pass
  140         else:
  141             self.fail('Expected ValueError')
  142 
  143     def test_CVSMaildirSource_create_change_with_branch(self):
  144         # Branch is indicated after 'Tag:' in modified file list
  145         msg = cvs1_11_msg.replace('        GNUmakefile',
  146                                   '      Tag: Test_Branch\n      GNUmakefile')
  147         m = message_from_string(msg)
  148         src = CVSMaildirSource('/dev/null')
  149         chdict = src.parse(m)[1]
  150         self.assertEqual(chdict['branch'], 'Test_Branch')
  151 
  152     def test_CVSMaildirSource_create_change_with_category(self):
  153         msg = cvs1_11_msg.replace('Category: None', 'Category: Test category')
  154         m = message_from_string(msg)
  155         src = CVSMaildirSource('/dev/null')
  156         chdict = src.parse(m)[1]
  157         self.assertEqual(chdict['category'], 'Test category')
  158 
  159     def test_CVSMaildirSource_create_change_with_no_comment(self):
  160         # Strip off comments
  161         msg = cvs1_11_msg[:cvs1_11_msg.find('Commented out some stuff')]
  162         m = message_from_string(msg)
  163         src = CVSMaildirSource('/dev/null')
  164         chdict = src.parse(m)[1]
  165         self.assertEqual(chdict['comments'], None)
  166 
  167     def test_CVSMaildirSource_create_change_with_no_files(self):
  168         # A message with no files is likely not for us
  169         msg = cvs1_11_msg.replace(
  170             'Files: base/module/src/make GNUmakefile,1.362,1.363', '')
  171         m = message_from_string(msg)
  172         src = CVSMaildirSource('/dev/null')
  173         chdict = src.parse(m)
  174         self.assertEqual(chdict, None)
  175 
  176     def test_CVSMaildirSource_create_change_with_no_project(self):
  177         msg = cvs1_11_msg.replace('Project: MyModuleName', '')
  178         m = message_from_string(msg)
  179         src = CVSMaildirSource('/dev/null')
  180         chdict = src.parse(m)[1]
  181         self.assertEqual(chdict['project'], None)
  182 
  183     def test_CVSMaildirSource_create_change_with_no_repository(self):
  184         msg = cvs1_11_msg.replace(
  185             'CVSROOT: :ext:cvshost.example.com:/cvsroot', '')
  186         m = message_from_string(msg)
  187         src = CVSMaildirSource('/dev/null')
  188         chdict = src.parse(m)[1]
  189         self.assertEqual(chdict['repository'], None)
  190 
  191     def test_CVSMaildirSource_create_change_with_property(self):
  192         m = message_from_string(cvs1_11_msg)
  193         propDict = {'foo': 'bar'}
  194         src = CVSMaildirSource('/dev/null', properties=propDict)
  195         chdict = src.parse(m)[1]
  196         self.assertEqual(chdict['properties']['foo'], 'bar')