Ejemplo n.º 1
0
    def __init__(self,
                 plate_image,
                 new=False,
                 categories=None,
                 tags='PlateMeasurement',
                 well_dimensions=(8, 12),
                 configuration_path='config',
                 plate_design=None,
                 pixel_intensities=False):

        Treant.__init__(self, plate_image, categories=categories, tags=tags)

        # store the image name provided in the categories, if there is one
        if 'ImageFileName' in self.categories.keys():
            self.image_name = self.categories['ImageFileName']
        elif 'IMAGEFILENAME' in self.categories.keys():
            self.image_name = self.categories['IMAGEFILENAME']

        # store the (rows,cols) of the plate
        self.well_dimensions = well_dimensions

        # calculate and store the total number of wells
        self.number_of_wells = self.well_dimensions[0] * self.well_dimensions[1]

        # store the path and name of the plate
        self.configuration_path = '/'.join(('..', configuration_path))
        self.plate_design = plate_design

        # remember whether we will be analysing and keeping the pixel intensities etc
        self.pixel_intensities = pixel_intensities
Ejemplo n.º 2
0
    def test_regen(self, tags, categories, tmpdir):
        """Test regenerating Treant.

        - create Treant
        - modify Treant a little
        - create same Treant (should regenerate)
        - check that modifications were saved
        """
        with tmpdir.as_cwd():
            C1 = Treant('regen', tags=tags, categories=categories)

            C2 = Treant('regen')  # should be regen of C1

            if tags is not None:
                for tag in tags:
                    assert tag in C2.tags
            if categories is not None:
                for cat, val in categories.items():
                    assert cat in C2.categories
                    assert C2.categories[cat] == val

            assert C1 == C2

            # they point to the same file, but they are not the same object
            assert C1 is not C2
Ejemplo n.º 3
0
    def test_gen_methods(self, tmpdir):
        """Test the variety of ways we can generate a new Treant

        1. ``Treant('treant')``, where 'treant' is not an existing file or
           directory path

        2. ``Treant('treant')``, where 'treant' is an existing directory
           without Treant state files inside

        3. ``Treant('/somedir/treant')``, where 'treant' is not an existing
           file or directory in 'somedir'

        4. ``Treant('/somedir/treant')``, where 'treant' is an existing
           directory in 'somedir' without any Treant state files inside

        """
        with tmpdir.as_cwd():
            # 1
            t1 = Treant('newone')
            assert os.path.exists(t1._treantdir)

            # 2
            os.mkdir('another')
            t2 = Treant('another')
            assert os.path.exists(t2._treantdir)

            # 3
            t3 = Treant('yet/another')
            assert os.path.exists(t3._treantdir)

            # 4
            os.mkdir('yet/more')
            t4 = Treant('yet/more')
            assert os.path.exists(t4._treantdir)
Ejemplo n.º 4
0
    def test_cmp(self, tmpdir):
        """Test the comparison of Treants when sorting"""
        with tmpdir.as_cwd():
            c1 = Treant('a')
            c2 = Treant('b')
            c3 = Treant('c')

        assert sorted([c3, c2, c1]) == [c1, c2, c3]
        assert c1 <= c2 < c3
        assert c3 >= c2 > c1
Ejemplo n.º 5
0
 def basic_treant(self, tmpdir):
     # treant with tags and cats, in tmpdir
     with tmpdir.as_cwd():
         t1 = Treant('Rincewind')
         t1.tags.add('magical')
         t1.categories.add({'colour': 'octarine'})
         yield t1
Ejemplo n.º 6
0
 def test_gen_OSError(self, tmpdir):
     with tmpdir.as_cwd():
         with mock.patch('os.makedirs') as mp:
             mp.sideeffect = OSError(os.errno.ENOSPC, 'Mock - disk full')
             with pytest.raises(OSError) as error:
                 t = Treant('new')
                 t.tags.add('worthless')
                 assert error.errno == os.errno.ENOSPC
Ejemplo n.º 7
0
 def test_gen_OSError13(self, tmpdir):
     with tmpdir.as_cwd():
         with mock.patch('os.makedirs') as mp:
             mp.sideeffect = OSError(os.errno.EACCES, 'Mock - disk full')
             with pytest.raises(OSError) as error:
                 t = Treant('new')
                 t.tags.add('worthless')
                 assert error.errno == os.errno.EACCES
                 assert ("Permission denied; cannot create 'new'"
                         in str(error))
Ejemplo n.º 8
0
def test_init_treant(tmpdir):
    pool = mp.Pool(processes=4)
    num = 73

    # TODO: eventually want this to work without initing the treant
    # here
    init_treant(tmpdir, ['bark'])
    for i in range(num):
        pool.apply_async(init_treant, args=(tmpdir, ['run_{}'.format(i)]))
    pool.close()
    pool.join()

    with tmpdir.as_cwd():
        tf = Treant('sprout')

    assert len(tf.tags) == num + 1
Ejemplo n.º 9
0
        def test_tags_setting(self, tmpdir):
            """Test that we can set tags with lists or sets, or with Tags
            objects.

            """
            with tmpdir.as_cwd():

                # set with a list
                t1 = Treant('maple')
                t1.tags = ['sprout', 'deciduous']

                assert t1.tags == {'sprout', 'deciduous'}

                # set with a set
                t2 = Treant('elm')
                t2.tags = {'sprout', 'deciduous'}

                assert t2.tags == {'sprout', 'deciduous'}

                # set with a Tags object
                t3 = Treant('sequoia')
                t3.tags = t2.tags

                assert t3.tags == {'sprout', 'deciduous'}
Ejemplo n.º 10
0
    def test_init_from_Tree(self, tmpdir):
        with tmpdir.as_cwd():
            tree = dtr.Tree('this')
            t = Treant(tree)

            assert t.path == tree.path
Ejemplo n.º 11
0
        def test_tags_set_behavior(self, tmpdir):
            with tmpdir.as_cwd():
                # 1
                t1 = Treant('maple')
                t1.tags.add(['sprout', 'deciduous'])

                # 2
                t2 = Treant('sequoia')
                t2.tags.add(['sprout', 'evergreen'])

                tags_union = t1.tags | t2.tags
                for t in ['sprout', 'deciduous', 'evergreen']:
                    assert t in tags_union

                tags_intersect = t1.tags & t2.tags
                assert 'sprout' in tags_intersect
                for t in ['deciduous', 'evergreen']:
                    assert t not in tags_intersect

                tags_diff = t1.tags - t2.tags
                assert 'deciduous' in tags_diff
                for t in ['sprout', 'evergreen']:
                    assert t not in tags_diff

                tags_symm_diff = t1.tags ^ t2.tags
                for t in ['deciduous', 'evergreen']:
                    assert t in tags_symm_diff
                assert 'sprout' not in tags_symm_diff

                # 3
                t3 = Treant('oak')
                t3.tags.add(['deciduous'])

                # Test set membership
                assert t1.tags <= t1.tags
                assert not t1.tags < t1.tags
                assert t1.tags == t1.tags
                assert not t1.tags < t3.tags
                assert t1.tags > t3.tags

                # test TypeErrors in Tags
                # type_error_msg = "Operands must be AggTags, Tags, or a set."
                with pytest.raises(TypeError) as e:
                    ('tree') == t1.tags
                # assert e.value.message == type_error_msg
                with pytest.raises(TypeError) as e:
                    t1.tags < ('tree')
                # assert e.value.message == type_error_msg
                with pytest.raises(TypeError) as e:
                    ('tree') - t1.tags
                # assert e.value.message == type_error_msg
                with pytest.raises(TypeError) as e:
                    t1.tags - ('tree')
                # assert e.value.message == type_error_msg
                with pytest.raises(TypeError) as e:
                    ('tree') | t1.tags
                # assert e.value.message == type_error_msg
                with pytest.raises(TypeError) as e:
                    t1.tags | ('tree')
                # assert e.value.message == type_error_msg
                with pytest.raises(TypeError) as e:
                    ('tree') & t1.tags
                # assert e.value.message == type_error_msg
                with pytest.raises(TypeError) as e:
                    t1.tags & ('tree')
                # assert e.value.message == type_error_msg
                with pytest.raises(TypeError) as e:
                    ('tree') ^ t1.tags
                # assert e.value.message == type_error_msg
                with pytest.raises(TypeError) as e:
                    t1.tags ^ ('tree')
Ejemplo n.º 12
0
def init_treant(tmpdir, tags):
    with tmpdir.as_cwd():
        tf = Treant('sprout', tags=tags)
    return tf
Ejemplo n.º 13
0
def pokefile(treantpath, string):
    """Add a number of tags to a Treant."""
    treant = Treant(treantpath)
    treant.tags.add(* ["{}_{}".format(string, i) for i in range(100)])
Ejemplo n.º 14
0
def treant(tmpdir):
    with tmpdir.as_cwd():
        t = Treant('sprout')
    return t