Exemplo n.º 1
0
    def test_copy02(self):
        """
        Test the copy() function some more
        """
        # First we create a 1MB file
        tmp_file = join(self.tmp_dir, 'NNTPContent_Test.copy', '1MB.rar')
        # File should not already exist
        assert (isfile(tmp_file) is False)
        # Create our file
        assert (self.touch(tmp_file, size='1MB', random=True) is True)
        # File should exist now
        assert (isfile(tmp_file) is True)

        # Now we want to load it into a NNTPContent object
        content_a = NNTPContent(filepath=tmp_file, work_dir=self.tmp_dir)

        # We want to make a copy of it
        content_b = content_a.copy()

        # Our content should be the same
        assert (len(content_a) == len(content_b))
        assert (content_a.md5() == content_b.md5())

        # Because we made a copy, we're working with a different file however
        # we share the exact same content and filename identifier.
        assert (content_a == content_b)

        # Our paths are not the same though; this is what makes us a official
        # copy
        assert (content_a.path() != content_b.path())
Exemplo n.º 2
0
    def test_copy02(self):
        """
        Test the copy() function some more
        """
        # First we create a 1MB file
        tmp_file = join(self.tmp_dir, 'NNTPContent_Test.copy', '1MB.rar')
        # File should not already exist
        assert(isfile(tmp_file) is False)
        # Create our file
        assert(self.touch(tmp_file, size='1MB', random=True) is True)
        # File should exist now
        assert(isfile(tmp_file) is True)

        # Now we want to load it into a NNTPContent object
        content_a = NNTPContent(filepath=tmp_file, work_dir=self.tmp_dir)

        # We want to make a copy of it
        content_b = content_a.copy()

        # Our content should be the same
        assert(len(content_a) == len(content_b))
        assert(content_a.md5() == content_b.md5())

        # Because we made a copy, we're working with a different file however
        # we share the exact same content and filename identifier.
        assert(content_a == content_b)

        # Our paths are not the same though; this is what makes us a official
        # copy
        assert(content_a.path() != content_b.path())
Exemplo n.º 3
0
    def test_copy01(self):
        """
        Test our copy function
        The copy function allows us to duplicate an existing NNTPContent
        object without obstructing the original.  Copied content is
        always attached; so if the object falls out of scope; so does
        the file.
        """
        my_dir = join(self.tmp_dir, 'NNTPContent', 'test_copy')
        assert (isdir(my_dir) is False)
        assert (mkdir(my_dir) is True)
        assert (isdir(my_dir) is True)

        #  Now create our NNTPContent object witin our directory
        obj = NNTPContent(
            filepath='myfile',
            work_dir=my_dir,
        )

        # Content is attached by default
        assert (obj.is_attached() is True)
        obj.detach()
        assert (obj.is_attached() is False)

        new_dir = join(my_dir, 'copy')
        assert (isdir(new_dir) is False)

        # Create a copy of our object
        obj_copy = obj.copy()

        # Successfully loaded files are never attached reguardless
        # of the original copy
        assert (obj_copy.is_attached() is True)

        # Reattach the original so it dies when this test is over
        obj.attach()
        assert (obj.is_attached() is True)

        # Create a copy of our copy
        obj_copy2 = obj_copy.copy()
        assert (obj_copy2.is_attached() is True)
        assert (isfile(obj_copy2.path()))
        _path = obj_copy2.path()
        del obj_copy2
        assert (isfile(_path) is False)

        assert (isfile(obj_copy.path()) is True)
        _path = obj_copy.path()
        del obj_copy
        assert (isfile(_path) is False)

        assert (isfile(obj.path()) is True)
        _path = obj.path()
        del obj
        assert (isfile(_path) is False)

        # now lets do a few more tests but with actual files this time
        tmp_file = join(my_dir, '2MB.zip')
        assert (self.touch(tmp_file, size='2MB', random=True) is True)

        #  Now create our NNTPContent object witin our directory
        obj = NNTPContent(
            filepath=tmp_file,
            work_dir=my_dir,
        )
        assert (isfile(obj.path()) is True)

        obj_copy = obj.copy()
        assert (isfile(obj_copy.path()) is True)
        stats = stat(obj_copy.path())
        assert (bytes_to_strsize(stats['size']) == "2.00MB")

        # Compare that our content is the same
        assert (compare(obj_copy.path(), obj.path()) is True)

        # note that the filenames are NOT the same so we are dealing with 2
        # distinct copies here
        assert (isfile(obj_copy.path()) is True)
        assert (isfile(obj.path()) is True)
        assert (obj.path() != obj_copy.path())
Exemplo n.º 4
0
    def test_saves(self):
        """
        Saving allows for a variety of inputs, test that they all
        check out okay
        """
        # First we create a 1MB file
        tmp_file = join(self.tmp_dir, 'NNTPContent_Test.save', 'testfile.tmp')
        # File should not already exist
        assert (isfile(tmp_file) is False)
        # Create a random file
        assert (self.touch(tmp_file, size='5MB', random=True) is True)
        # File should exist now
        assert (isfile(tmp_file) is True)
        # Now we want to load it into a NNTPContent object
        content = NNTPContent(filepath=tmp_file, work_dir=self.tmp_dir)
        # Test our file exists
        assert (len(content) == strsize_to_bytes('5M'))
        # By default our load makes it so our file is NOT attached
        assert (content.is_attached() is False)
        # as we can't make a copy of our current file on top of the old
        _filepath = content.path()
        assert (content.save(copy=True) is True)
        assert (content.path() == _filepath)
        assert (content.path() == tmp_file)

        # File should still be detached
        assert (content.is_attached() is False)
        # Filepath shoul still not have changed
        # Let's attach it
        content.attach()
        assert (content.is_attached() is True)

        # If we call save() a copy parameter, there should be no change
        assert (content.save(copy=True) is True)
        # Still no change
        assert (content.is_attached() is True)

        # Now lets actually copy it to a new location
        tmp_file_copy = join(self.tmp_dir, 'NNTPContent_Test.save',
                             'testfile.copy.tmp')
        # File should not already exist
        assert (isfile(tmp_file_copy) is False)
        # call save using our copy variable and new filename
        assert (content.save(tmp_file_copy, copy=True) is True)
        # File should exist now
        assert (isfile(tmp_file_copy) is True)
        # Old File should still exist too
        assert (isfile(tmp_file) is True)
        # Path should still be the old path and not the new
        assert (content.path() == tmp_file)
        # Still no change in attachment
        assert (content.is_attached() is True)

        # Create a new file now
        tmp_file_copy2 = join(self.tmp_dir, 'NNTPContent_Test.save',
                              'testfile.copy2.tmp')
        assert (isfile(tmp_file_copy2) is False)
        # call save with copy set to false; This performs an official
        # move (adjusting our internal records.
        assert (content.save(tmp_file_copy2, copy=False) is True)
        # Old File should no longer exist
        assert (isfile(tmp_file) is False)
        # Content should be detached
        assert (content.is_attached() is False)
        # New file should exist
        assert (isfile(tmp_file_copy2) is True)
        assert (content.path() != _filepath)
        assert (content.path() == tmp_file_copy2)
Exemplo n.º 5
0
    def test_copy01(self):
        """
        Test our copy function
        The copy function allows us to duplicate an existing NNTPContent
        object without obstructing the original.  Copied content is
        always attached; so if the object falls out of scope; so does
        the file.
        """
        my_dir = join(self.tmp_dir, 'NNTPContent', 'test_copy')
        assert(isdir(my_dir) is False)
        assert(mkdir(my_dir) is True)
        assert(isdir(my_dir) is True)

        #  Now create our NNTPContent object witin our directory
        obj = NNTPContent(
            filepath='myfile',
            work_dir=my_dir,
        )

        # Content is attached by default
        assert(obj.is_attached() is True)
        obj.detach()
        assert(obj.is_attached() is False)

        new_dir = join(my_dir, 'copy')
        assert(isdir(new_dir) is False)

        # Create a copy of our object
        obj_copy = obj.copy()

        # Successfully loaded files are never attached reguardless
        # of the original copy
        assert(obj_copy.is_attached() is True)

        # Reattach the original so it dies when this test is over
        obj.attach()
        assert(obj.is_attached() is True)

        # Create a copy of our copy
        obj_copy2 = obj_copy.copy()
        assert(obj_copy2.is_attached() is True)
        assert(isfile(obj_copy2.path()))
        _path = obj_copy2.path()
        del obj_copy2
        assert(isfile(_path) is False)

        assert(isfile(obj_copy.path()) is True)
        _path = obj_copy.path()
        del obj_copy
        assert(isfile(_path) is False)

        assert(isfile(obj.path()) is True)
        _path = obj.path()
        del obj
        assert(isfile(_path) is False)

        # now lets do a few more tests but with actual files this time
        tmp_file = join(my_dir, '2MB.zip')
        assert(self.touch(tmp_file, size='2MB', random=True) is True)

        #  Now create our NNTPContent object witin our directory
        obj = NNTPContent(
            filepath=tmp_file,
            work_dir=my_dir,
        )
        assert(isfile(obj.path()) is True)

        obj_copy = obj.copy()
        assert(isfile(obj_copy.path()) is True)
        stats = stat(obj_copy.path())
        assert(bytes_to_strsize(stats['size']) == "2.00MB")

        # Compare that our content is the same
        assert(compare(obj_copy.path(), obj.path()) is True)

        # note that the filenames are NOT the same so we are dealing with 2
        # distinct copies here
        assert(isfile(obj_copy.path()) is True)
        assert(isfile(obj.path()) is True)
        assert(obj.path() != obj_copy.path())
Exemplo n.º 6
0
    def test_saves(self):
        """
        Saving allows for a variety of inputs, test that they all
        check out okay
        """
        # First we create a 1MB file
        tmp_file = join(
            self.tmp_dir, 'NNTPContent_Test.save', 'testfile.tmp')
        # File should not already exist
        assert(isfile(tmp_file) is False)
        # Create a random file
        assert(self.touch(tmp_file, size='5MB', random=True) is True)
        # File should exist now
        assert(isfile(tmp_file) is True)
        # Now we want to load it into a NNTPContent object
        content = NNTPContent(filepath=tmp_file, work_dir=self.tmp_dir)
        # Test our file exists
        assert(len(content) == strsize_to_bytes('5M'))
        # By default our load makes it so our file is NOT attached
        assert(content.is_attached() is False)
        # as we can't make a copy of our current file on top of the old
        _filepath = content.path()
        assert(content.save(copy=True) is True)
        assert(content.path() == _filepath)
        assert(content.path() == tmp_file)

        # File should still be detached
        assert(content.is_attached() is False)
        # Filepath shoul still not have changed
        # Let's attach it
        content.attach()
        assert(content.is_attached() is True)

        # If we call save() a copy parameter, there should be no change
        assert(content.save(copy=True) is True)
        # Still no change
        assert(content.is_attached() is True)

        # Now lets actually copy it to a new location
        tmp_file_copy = join(
            self.tmp_dir, 'NNTPContent_Test.save', 'testfile.copy.tmp')
        # File should not already exist
        assert(isfile(tmp_file_copy) is False)
        # call save using our copy variable and new filename
        assert(content.save(tmp_file_copy, copy=True) is True)
        # File should exist now
        assert(isfile(tmp_file_copy) is True)
        # Old File should still exist too
        assert(isfile(tmp_file) is True)
        # Path should still be the old path and not the new
        assert(content.path() == tmp_file)
        # Still no change in attachment
        assert(content.is_attached() is True)

        # Create a new file now
        tmp_file_copy2 = join(
            self.tmp_dir, 'NNTPContent_Test.save', 'testfile.copy2.tmp')
        assert(isfile(tmp_file_copy2) is False)
        # call save with copy set to false; This performs an official
        # move (adjusting our internal records.
        assert(content.save(tmp_file_copy2, copy=False) is True)
        # Old File should no longer exist
        assert(isfile(tmp_file) is False)
        # Content should be detached
        assert(content.is_attached() is False)
        # New file should exist
        assert(isfile(tmp_file_copy2) is True)
        assert(content.path() != _filepath)
        assert(content.path() == tmp_file_copy2)