def test_no_rotation(self):
        self._file = AutoFlushingRotatingFile(self._path)

        self.dump_bytes(100)

        file_size = os.path.getsize(self._path)
        self.assertEqual(LINE_STR_FULL_SIZE * 100, file_size)
    def test_no_rotation(self):
        self._file = AutoFlushingRotatingFile(self._path)

        self.dump_bytes()

        file_size = os.path.getsize(self._path)
        self.assertEqual(1000, file_size)
    def test_append_existing(self):
        self._file = AutoFlushingRotatingFile(self._path)
        self.dump_bytes()
        self._file.close()

        self._file = AutoFlushingRotatingFile(self._path)
        self.dump_bytes()

        file_size = os.path.getsize(self._path)
        self.assertEqual(2000, file_size)
    def test_append_existing(self):
        self._file = AutoFlushingRotatingFile(self._path)
        self.dump_bytes(100)
        self._file.close()

        self._file = AutoFlushingRotatingFile(self._path)
        self.dump_bytes(100)

        file_size = os.path.getsize(self._path)
        self.assertEqual(LINE_STR_FULL_SIZE * 200, file_size)
    def test_single_rotation(self):
        self._file = AutoFlushingRotatingFile(self._path, max_bytes=200, backup_count=1)
        self.dump_bytes()
        file_size = os.path.getsize(self._path)
        self.assertEqual(200, file_size)

        file_size = os.path.getsize("%s.1" % self._path)
        self.assertEqual(200, file_size)

        self.assertEqual(False, os.path.exists("%s.2" % self._path))
    def test_append_existing( self ):
        self._file = AutoFlushingRotatingFile( self._path )
        self.dump_bytes()
        self._file.close()

        self._file = AutoFlushingRotatingFile( self._path )
        self.dump_bytes()

        file_size = os.path.getsize( self._path )
        self.assertEqual( 2000, file_size )
    def test_multi_rotation(self):
        self._file = AutoFlushingRotatingFile(self._path, max_bytes=200, backup_count=3)
        self.dump_bytes()
        file_size = os.path.getsize(self._path)
        self.assertEqual(200, file_size)

        for i in range(1, 4, 1):
            file_size = os.path.getsize("%s.%d" % (self._path, i))
            self.assertEqual(200, file_size)

        self.assertEqual(False, os.path.exists("%s.4" % self._path))
    def test_multi_rotation(self):
        max_bytes = LINE_STR_FULL_SIZE * 10
        self._file = AutoFlushingRotatingFile(self._path,
                                              max_bytes=max_bytes,
                                              backup_count=3)
        self.dump_bytes(100)
        file_size = os.path.getsize(self._path)
        self.assertEqual(LINE_STR_FULL_SIZE * 10, file_size)

        for i in range(1, 4, 1):
            file_size = os.path.getsize("%s.%d" % (self._path, i))
            self.assertEqual(max_bytes, file_size)

        self.assertEqual(False, os.path.exists("%s.4" % self._path))
    def test_single_rotation(self):
        max_bytes = LINE_STR_FULL_SIZE * 10
        self._file = AutoFlushingRotatingFile(self._path,
                                              max_bytes=max_bytes,
                                              backup_count=1)
        self.dump_bytes(100)
        file_size = os.path.getsize(self._path)

        self.assertEqual(LINE_STR_FULL_SIZE * 10, file_size)

        file_size = os.path.getsize("%s.1" % self._path)
        self.assertEqual(max_bytes, file_size)

        self.assertEqual(False, os.path.exists("%s.2" % self._path))
    def test_no_rotation( self ):
        self._file = AutoFlushingRotatingFile( self._path )

        self.dump_bytes()

        file_size = os.path.getsize( self._path )
        self.assertEqual( 1000, file_size )
    def test_single_rotation( self ):
        self._file = AutoFlushingRotatingFile( self._path, max_bytes=200, backup_count=1 )
        self.dump_bytes()
        file_size = os.path.getsize( self._path )
        self.assertEqual( 200, file_size )

        file_size = os.path.getsize( "%s.1" % self._path )
        self.assertEqual( 200, file_size )

        self.assertEqual( False, os.path.exists( "%s.2" % self._path ) )
    def test_multi_rotation( self ):
        self._file = AutoFlushingRotatingFile( self._path, max_bytes=200, backup_count=3 )
        self.dump_bytes()
        file_size = os.path.getsize( self._path )
        self.assertEqual( 200, file_size )

        for i in range( 1, 4, 1 ):
            file_size = os.path.getsize( "%s.%d" % (self._path, i) )
            self.assertEqual( 200, file_size )

        self.assertEqual( False, os.path.exists( "%s.4" % self._path ) )
class AutoFlushingRotatingFileTestCase(unittest.TestCase):
    def setUp(self):
        self._tempdir = tempfile.mkdtemp()
        self._path = os.path.join(self._tempdir, 'out.log')

    def tearDown(self):
        self._file.close()
        shutil.rmtree(self._tempdir)

    def dump_bytes(self, amount=100):
        for i in range(0, amount, 1):
            self._file.write("abcdefghi")

    def test_no_rotation(self):
        self._file = AutoFlushingRotatingFile(self._path)

        self.dump_bytes()

        file_size = os.path.getsize(self._path)
        self.assertEqual(1000, file_size)

    def test_no_rotation_but_max_bytes(self):
        self._file = AutoFlushingRotatingFile(self._path, max_bytes=500)
        self.dump_bytes()
        file_size = os.path.getsize(self._path)
        self.assertEqual(1000, file_size)

    def test_append_existing(self):
        self._file = AutoFlushingRotatingFile(self._path)
        self.dump_bytes()
        self._file.close()

        self._file = AutoFlushingRotatingFile(self._path)
        self.dump_bytes()

        file_size = os.path.getsize(self._path)
        self.assertEqual(2000, file_size)

    def test_single_rotation(self):
        self._file = AutoFlushingRotatingFile(self._path,
                                              max_bytes=200,
                                              backup_count=1)
        self.dump_bytes()
        file_size = os.path.getsize(self._path)
        self.assertEqual(200, file_size)

        file_size = os.path.getsize("%s.1" % self._path)
        self.assertEqual(200, file_size)

        self.assertEqual(False, os.path.exists("%s.2" % self._path))

    def test_multi_rotation(self):
        self._file = AutoFlushingRotatingFile(self._path,
                                              max_bytes=200,
                                              backup_count=3)
        self.dump_bytes()
        file_size = os.path.getsize(self._path)
        self.assertEqual(200, file_size)

        for i in range(1, 4, 1):
            file_size = os.path.getsize("%s.%d" % (self._path, i))
            self.assertEqual(200, file_size)

        self.assertEqual(False, os.path.exists("%s.4" % self._path))
class AutoFlushingRotatingFileTestCase( unittest.TestCase ):

    def setUp(self):
        self._tempdir = tempfile.mkdtemp()
        self._path = os.path.join(self._tempdir, 'out.log')

    def tearDown(self):
        self._file.close()
        shutil.rmtree(self._tempdir)

    def dump_bytes( self, amount=100 ):
        for i in range( 0, amount, 1 ):
            self._file.write( "abcdefghi" )

    def test_no_rotation( self ):
        self._file = AutoFlushingRotatingFile( self._path )

        self.dump_bytes()

        file_size = os.path.getsize( self._path )
        self.assertEqual( 1000, file_size )

    def test_no_rotation_but_max_bytes( self ):
        self._file = AutoFlushingRotatingFile( self._path, max_bytes=500 )
        self.dump_bytes()
        file_size = os.path.getsize( self._path )
        self.assertEqual( 1000, file_size )

    def test_append_existing( self ):
        self._file = AutoFlushingRotatingFile( self._path )
        self.dump_bytes()
        self._file.close()

        self._file = AutoFlushingRotatingFile( self._path )
        self.dump_bytes()

        file_size = os.path.getsize( self._path )
        self.assertEqual( 2000, file_size )

    def test_single_rotation( self ):
        self._file = AutoFlushingRotatingFile( self._path, max_bytes=200, backup_count=1 )
        self.dump_bytes()
        file_size = os.path.getsize( self._path )
        self.assertEqual( 200, file_size )

        file_size = os.path.getsize( "%s.1" % self._path )
        self.assertEqual( 200, file_size )

        self.assertEqual( False, os.path.exists( "%s.2" % self._path ) )

    def test_multi_rotation( self ):
        self._file = AutoFlushingRotatingFile( self._path, max_bytes=200, backup_count=3 )
        self.dump_bytes()
        file_size = os.path.getsize( self._path )
        self.assertEqual( 200, file_size )

        for i in range( 1, 4, 1 ):
            file_size = os.path.getsize( "%s.%d" % (self._path, i) )
            self.assertEqual( 200, file_size )

        self.assertEqual( False, os.path.exists( "%s.4" % self._path ) )