<commit_before>import unittest
import os
from pybagit.bagit import BagIt

class FetchTest(unittest.TestCase):
    ### THESE MAY FAIL if the Websites change their files. In that case,
    ### just comment this test out, or replace the assertion with a new
    ### SHA1 Checksum.
    def setUp(self):
        print "Setting up Fetch."
        self.bag = BagIt(os.path.join(os.getcwd(), 'test', 'testbag'))
        self.test_fetch_contents = [{'filename': u'data/bagitspec.pdf',
          'length': u'-',
          'url': u'http://www.digitalpreservation.gov/library/resources/tools/docs/bagitspec.pdf'}]
    
    def tearDown(self):
        # if os.path.exists(os.path.join(os.getcwd(), 'test', 'testbag', 'data', 'bagitspec.pdf')):
        #     os.remove(os.path.join(os.getcwd(), 'test', 'testbag', 'data', 'bagitspec.pdf'))
        if os.path.exists(os.path.join(os.getcwd(), 'test', 'testbag', 'data', 'stealin_mah_bag.jpg')):
            os.remove(os.path.join(os.getcwd(), 'test', 'testbag', 'data', 'stealin_mah_bag.jpg'))
        self.bag.add_fetch_entries(self.test_fetch_contents, append=False)
    
    def test_fetch_contents(self):
        self.assertEquals(self.bag.fetch_contents, self.test_fetch_contents)
    
    def test_can_fetch(self):
        self.bag.fetch()
        self.assertTrue(os.path.exists(os.path.join(os.getcwd(), 'test','testbag','data','bagitspec.pdf')))
    
    def test_can_fetch_and_validate(self):
        self.bag.fetch(validate_downloads=True)
        self.assertEquals(self.bag.manifest_contents['data/bagitspec.pdf'],
            'ea3ff12bfa706fb494a2fca5af6134e44f199f92')
            
    def set_fetch_contents(self):
        self.bag.add_fetch_entries([{'url': 'http://icanhascheezburger.files.wordpress.com/2007/06/stealing_my_bag.jpg', 
                'filename': os.path.join('data','stealin_mah_bag.jpg')}])
        self.assertTrue(os.path.exists(os.path.join(os.getcwd(), 'test', 'testbag', 'data', 'stealin_mah_bag.jpg')))

def suite():
    test_suite = unittest.makeSuite(FetchTest, 'test')
    return test_suite<commit_msg>Fixed: Updated bagit spec url.<commit_after>import unittest
import os
from pybagit.bagit import BagIt

class FetchTest(unittest.TestCase):
    ### THESE MAY FAIL if the Websites change their files. In that case,
    ### just comment this test out, or replace the assertion with a new
    ### SHA1 Checksum.
    def setUp(self):
        print "Setting up Fetch."
        self.bag = BagIt(os.path.join(os.getcwd(), 'test', 'testbag'))
        self.test_fetch_contents = [{'filename': u'data/bagitspec.pdf',
          'length': u'-',
          'url': u'http://www.digitalpreservation.gov/documents/bagitspec.pdf'}]
    
    def tearDown(self):
        # if os.path.exists(os.path.join(os.getcwd(), 'test', 'testbag', 'data', 'bagitspec.pdf')):
        #     os.remove(os.path.join(os.getcwd(), 'test', 'testbag', 'data', 'bagitspec.pdf'))
        if os.path.exists(os.path.join(os.getcwd(), 'test', 'testbag', 'data', 'stealin_mah_bag.jpg')):
            os.remove(os.path.join(os.getcwd(), 'test', 'testbag', 'data', 'stealin_mah_bag.jpg'))
        if os.path.exists(os.path.join(os.getcwd(), 'test', 'testbag', 'data', 'bagitspec.pdf')):
            os.remove(os.path.join(os.getcwd(), 'test', 'testbag', 'data', 'bagitspec.pdf'))
        self.bag.add_fetch_entries(self.test_fetch_contents, append=False)
    
    def test_fetch_contents(self):
        self.assertEquals(self.bag.fetch_contents, self.test_fetch_contents)
    
    def test_can_fetch(self):
        self.bag.fetch()
        self.assertTrue(os.path.exists(os.path.join(os.getcwd(), 'test','testbag','data','bagitspec.pdf')))
    
    def test_can_fetch_and_validate(self):
        self.bag.fetch(validate_downloads=True)
        self.assertEquals(self.bag.manifest_contents['data/bagitspec.pdf'],
            '4649c6540ac4e4dcf271ca236abfe62faa4d7f08')
            
    def set_fetch_contents(self):
        self.bag.add_fetch_entries([{'url': 'http://icanhascheezburger.files.wordpress.com/2007/06/stealing_my_bag.jpg', 
                'filename': os.path.join('data','stealin_mah_bag.jpg')}])
        self.assertTrue(os.path.exists(os.path.join(os.getcwd(), 'test', 'testbag', 'data', 'stealin_mah_bag.jpg')))

def suite():
    test_suite = unittest.makeSuite(FetchTest, 'test')
    return test_suite
{'fraction_non_alphanumeric': 0.16356107660455488, 'fraction_numerical': 0.013342535081665517, 'mean_word_length': 3.4686536485097634, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2436242', 'n_tokens_mistral': 1556, 'n_tokens_neox': 1513, 'n_words': 236}