Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions av/container/core.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,12 @@ cdef class Container(object):
# Finish releasing the whole structure.
lib.avformat_free_context(self.ptr)

def __enter__(self):
return self

def __exit__(self, exc_type, exc_val, exc_tb):
self.close()

def __repr__(self):
return '<av.%s %r>' % (self.__class__.__name__, self.file or self.name)

Expand Down
7 changes: 6 additions & 1 deletion tests/test_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import av

from .common import TestCase
from .common import TestCase, fate_suite


# On Windows, Python 3.0 - 3.5 have issues handling unicode filenames.
Expand All @@ -22,6 +22,11 @@

class TestContainers(TestCase):

def test_context_manager(self):
with av.open(fate_suite('h264/interlaced_crop.mp4')) as container:
self.assertEqual(container.format.long_name, 'QuickTime / MOV')
self.assertEqual(len(container.streams), 1)

@unittest.skipIf(broken_unicode, 'Unicode filename handling is broken')
def test_unicode_filename(self):

Expand Down