Ejemplo n.º 1
0
    def __init__(self, *args, **kwargs):
        # Run ContainerMixin init
        ContainerMixin.__init__(self, *args, **kwargs)

        # Run FileMixin init
        FileMixin.__init__(self, *args, **kwargs)

        super(ObjectContainer, self).__init__(*args, **kwargs)
Ejemplo n.º 2
0
    def __init__(self, *args, **kwargs):
        # Run ContainerMixin init
        ContainerMixin.__init__(self, *args, **kwargs)

        # Run FileMixin init
        FileMixin.__init__(self, *args, **kwargs)

        super(DictContainer, self).__init__(*args)

        self.non_hashable_fields = [
            '_hash',
            'verbose',
        ]
        if kwargs.get('non_hashable_fields'):
            self.non_hashable_fields.update(kwargs.get('non_hashable_fields'))
Ejemplo n.º 3
0
    def __init__(self, *args, **kwargs):
        """Constructor

        Parameters
        ----------
        filename : str, optional
            File path

        """

        # Run FileMixin init
        FileMixin.__init__(self, *args, **kwargs)

        # Run super init to call init of mixins too
        super(File, self).__init__(*args, **kwargs)
Ejemplo n.º 4
0
def test_FileMixin_delimiters():
    delimiters = [',', ';', '\t']
    for delimiter in delimiters:
        tmp = tempfile.NamedTemporaryFile('r+',
                                          suffix='.txt',
                                          dir='/tmp',
                                          delete=False)
        try:
            tmp.write('0.5' + delimiter + '0.7\n')
            tmp.write('2.5' + delimiter + '2.7\n')
            tmp.close()

            item = FileMixin(filename=tmp.name)
            nose.tools.eq_(item.delimiter(), delimiter)
        finally:
            os.unlink(tmp.name)
Ejemplo n.º 5
0
    def __init__(self, *args, **kwargs):
        """Constructor

        Parameters
        ----------
        filename : str, optional
            File path
        """

        # Run ContainerMixin init
        ContainerMixin.__init__(self, *args, **kwargs)

        # Run FileMixin init
        FileMixin.__init__(self, *args, **kwargs)

        # Run list init
        list.__init__(self, *args)
Ejemplo n.º 6
0
    def __init__(self, *args, **kwargs):
        """Constructor

        Parameters
        ----------
        filename : str, optional
            File path

        valid_formats : list of FileFormat items
            List of valid formats (FileFormat)
            Default [YAML,JSON,CPICKLE,MARSHAL,MSGPACK,TXT,CSV,ZIP,TAR]

        """

        # Run FileMixin init
        FileMixin.__init__(self, *args, **kwargs)

        # Run super init to call init of mixins too
        super(File, self).__init__(*args, **kwargs)
Ejemplo n.º 7
0
    def __init__(self, *args, **kwargs):
        """Constructor

        Parameters
        ----------
        filename : str, optional
            File path
        """

        # Run ContainerMixin init
        ContainerMixin.__init__(self, *args, **kwargs)

        # Run FileMixin init
        FileMixin.__init__(self, *args, **kwargs)

        # Run list init
        list.__init__(self, *args)

        # Convert list items to DictContainers
        for item_id, item in enumerate(self):
            self[item_id] = DictContainer(item)
Ejemplo n.º 8
0
def test_FileMixin_formats():
    nose.tools.eq_(
        FileMixin(filename='test.yaml').detect_file_format().format,
        FileFormat.YAML)
    nose.tools.eq_(
        FileMixin(filename='test.xml').detect_file_format().format,
        FileFormat.XML)
    nose.tools.eq_(
        FileMixin(filename='test.json').detect_file_format().format,
        FileFormat.JSON)
    nose.tools.eq_(
        FileMixin(filename='test.cpickle').detect_file_format().format,
        FileFormat.CPICKLE)
    nose.tools.eq_(
        FileMixin(filename='test.pickle').detect_file_format().format,
        FileFormat.CPICKLE)
    nose.tools.eq_(
        FileMixin(filename='test.pkl').detect_file_format().format,
        FileFormat.CPICKLE)
    nose.tools.eq_(
        FileMixin(filename='test.marshal').detect_file_format().format,
        FileFormat.MARSHAL)
    nose.tools.eq_(
        FileMixin(filename='test.wav').detect_file_format().format,
        FileFormat.WAV)
    nose.tools.eq_(
        FileMixin(filename='test.flac').detect_file_format().format,
        FileFormat.FLAC)
    nose.tools.eq_(
        FileMixin(filename='test.mp3').detect_file_format().format,
        FileFormat.MP3)
    nose.tools.eq_(
        FileMixin(filename='test.m4a').detect_file_format().format,
        FileFormat.M4A)
    nose.tools.eq_(
        FileMixin(filename='test.txt').detect_file_format().format,
        FileFormat.TXT)
    nose.tools.eq_(
        FileMixin(filename='test.hash').detect_file_format().format,
        FileFormat.TXT)
    nose.tools.eq_(
        FileMixin(filename='test.webm').detect_file_format().format,
        FileFormat.WEBM)
    nose.tools.eq_(
        FileMixin(filename='test.tar').detect_file_format().format,
        FileFormat.TAR)
    nose.tools.eq_(
        FileMixin(filename='test.tar.gz').detect_file_format().format,
        FileFormat.TAR)
    nose.tools.eq_(
        FileMixin(filename='test.zip').detect_file_format().format,
        FileFormat.ZIP)
    nose.tools.eq_(
        FileMixin(filename='test.csv').detect_file_format().format,
        FileFormat.CSV)
    nose.tools.eq_(
        FileMixin(filename='test.ann').detect_file_format().format,
        FileFormat.ANN)

    nose.tools.eq_(FileMixin(filename='test.zip').is_package(), True)
    nose.tools.eq_(FileMixin(filename='test.tar').is_package(), True)
    nose.tools.eq_(FileMixin(filename='test.tar.gz').is_package(), True)
    nose.tools.eq_(FileMixin(filename='test.wav').is_package(), False)