def test_has_traits(self):
        """ has traits """

        module = self.code_browser.read_file(
                     os.path.join(
                         get_path(CodeBrowserTestCase),
                         'example_1.py'))

        # Check the module name and documentation.
        self.assertEqual('example_1', module.name)

        # Check that the module contains the specified class.
        klass = module.klasses.get('Base')
        self.assertNotEqual(None, klass)

        # Check the class' base class.
        self.assertEqual(['HasTraits'], klass.bases)

        # Check that the class has the appropriate traits and methods.
        self.assertEqual(2, len(klass.traits))
        x = klass.traits['x']
        y = klass.traits['y']

        self.assertEqual(2, len(klass.methods))
        foo = klass.methods['foo']
        bar = klass.methods['bar']

        return
Ejemplo n.º 2
0
    def test_has_traits(self):
        """ has traits """

        module = self.code_browser.read_file(
            os.path.join(get_path(CodeBrowserTestCase), 'example_1.py')
        )

        # Check the module name and documentation.
        self.assertTrue(module.name.endswith('example_1'))

        # Check that the module contains the specified class.
        klass = module.klasses.get('Base')
        self.assertNotEqual(None, klass)

        # Check the class' base class.
        self.assertEqual(['HasTraits'], klass.bases)

        # Check that the class has the appropriate traits and methods.
        self.assertEqual(2, len(klass.traits))
        self.assertIn("x", klass.traits)
        self.assertIn("y", klass.traits)

        self.assertEqual(2, len(klass.methods))
        self.assertIn("foo", klass.methods)
        self.assertIn("bar", klass.methods)

        return
Ejemplo n.º 3
0
    def get_family_ranges_from_file(self, filename=None):
        """Retrieves a list of left/right range parameters from a file.

            Parameters
            ----------
            filename:
                full path and name of spec file for ranges
        """

        # this function should probably live somewhere else (refactor style-
        #  manager).

        is_data = False
        column_names = []
        system_names = []

        if not filename:
            filename = os.path.join(get_path(self), 'data',
                                    'unit_ranges.txt')
        fh = open(filename)

        csv_reader = csv.reader(fh, delimiter=' ', skipinitialspace=True)

        logger.debug('Loading default unit info from %s...' % filename)

        for data in csv_reader:
            if (len(data) == 0) or (data[0][0:1] == '#'):
                # Ignore blank lines and comment lines:
                pass

            elif is_data:
                try:
                    self.unit_ranges[data[0]] = {}
                    col_count = 1  # skip first column (family_name)
                    for system in system_names:
                        self.unit_ranges[
                            data[0]][system] = (
                            cvt_float(
                                data[col_count]), cvt_float(
                data[
                    col_count + 1]))
                        col_count += 2

                except KeyError:
                    logger.warn('Duplicate family found for %s')

            else:
                # Parse the header line
                is_data = True
                column_names = []
                system_names = []
                for column in data:
                    if column[-5:] == '_LEFT':
                        system_names.append(column[:-5].lower())
                    column_names.append(column.lower())  # not used?

        fh.close()
        logger.debug('Loading default unit info...Done')
        return
Ejemplo n.º 4
0
def get_bitmap(root, name):
    """
    Convenience function that returns a bitmap
    root - either an instance of a class or a path
    name - name of png file to load
    """
    path = os.path.join(get_path(root), name)
    bmp = wx.Bitmap(path, wx.BITMAP_TYPE_PNG)
    return bmp
Ejemplo n.º 5
0
def get_bitmap(root, name):
    """
    Convenience function that returns a bitmap
    root - either an instance of a class or a path
    name - name of png file to load
    """
    path = os.path.join(get_path(root), name)
    bmp = wx.Bitmap(path, wx.BITMAP_TYPE_PNG)
    return bmp
Ejemplo n.º 6
0
    def get_family_ranges_from_file(self, filename=None):
        """Retrieves a list of left/right range parameters from a file.

            Parameters
            ----------
            filename:
                full path and name of spec file for ranges
        """

        # this function should probably live somewhere else (refactor style-
        #  manager).

        is_data = False
        column_names = []
        system_names = []

        if not filename:
            filename = os.path.join(get_path(self), 'data', 'unit_ranges.txt')
        fh = open(filename)

        csv_reader = csv.reader(fh, delimiter=' ', skipinitialspace=True)

        logger.debug('Loading default unit info from %s...' % filename)

        for data in csv_reader:
            if (len(data) == 0) or (data[0][0:1] == '#'):
                # Ignore blank lines and comment lines:
                pass

            elif is_data:
                try:
                    self.unit_ranges[data[0]] = {}
                    col_count = 1  # skip first column (family_name)
                    for system in system_names:
                        self.unit_ranges[data[0]][system] = (cvt_float(
                            data[col_count]), cvt_float(data[col_count + 1]))
                        col_count += 2

                except KeyError:
                    logger.warn('Duplicate family found for %s')

            else:
                # Parse the header line
                is_data = True
                column_names = []
                system_names = []
                for column in data:
                    if column[-5:] == '_LEFT':
                        system_names.append(column[:-5].lower())
                    column_names.append(column.lower())  # not used?

        fh.close()
        logger.debug('Loading default unit info...Done')
        return
Ejemplo n.º 7
0
    def get_family_format_from_file(self, filename=None):
        """Retrieves a list of formatting parameters from a file.

            Parameters
            ----------
            filename:
                full path and name of spec file for formats
        """

        # this function should probably live somewhere else (refactor style-
        #  manager).

        is_data = False
        column_names = []

        if not filename:
            filename = os.path.join(get_path(self), 'data',
                                    'unit_formatting.txt')
        fh = open(filename)

        csv_reader = csv.reader(fh, delimiter=' ', skipinitialspace=True)

        logger.debug('Loading default unit info from %s...' % filename)

        for data in csv_reader:
            if (len(data) == 0) or (data[0][0:1] == '#'):
                # Ignore blank lines and comment lines:
                pass

            elif is_data:
                try:
                    self.unit_formats[data[0]] = {}
                    for i, column in enumerate(column_names):
                        # skip the first one (family name)
                        if i == 0:
                            pass
                        else:
                            self.unit_formats[data[0]][column] = data[i]
                except KeyError:
                    logger.warn('Duplicate family found for %s' % data[0])

            else:
                # Parse the header line
                is_data = True
                column_names = []
                for column in data:
                    column_names.append(column.lower())

        fh.close()
        logger.debug('Loading default unit info...Done')
        return
Ejemplo n.º 8
0
    def get_family_format_from_file(self, filename=None):
        """Retrieves a list of formatting parameters from a file.

            Parameters
            ----------
            filename:
                full path and name of spec file for formats
        """

        # this function should probably live somewhere else (refactor style-
        #  manager).

        is_data = False
        column_names = []

        if not filename:
            filename = os.path.join(get_path(self), 'data',
                                    'unit_formatting.txt')
        fh = open(filename)

        csv_reader = csv.reader(fh, delimiter=' ', skipinitialspace=True)

        logger.debug('Loading default unit info from %s...' % filename)

        for data in csv_reader:
            if (len(data) == 0) or (data[0][0:1] == '#'):
                # Ignore blank lines and comment lines:
                pass

            elif is_data:
                try:
                    self.unit_formats[data[0]] = {}
                    for i, column in enumerate(column_names):
                        # skip the first one (family name)
                        if i == 0:
                            pass
                        else:
                            self.unit_formats[data[0]][column] = data[i]
                except KeyError:
                    logger.warn('Duplicate family found for %s' % data[0])

            else:
                # Parse the header line
                is_data = True
                column_names = []
                for column in data:
                    column_names.append(column.lower())

        fh.close()
        logger.debug('Loading default unit info...Done')
        return
    def _get_default_resource_path(self, object):
        """ Returns the default resource path for an object. """

        resource_path = []
        for klass in inspect.getmro(object.__class__):
            try:
                resource_path.append(get_path(klass))

            # We get an attribute error when we get to a C extension type (in
            # our case it will most likley be 'CHasTraits'.  We simply ignore
            # everything after this point!
            except AttributeError:
                break

        return resource_path
Ejemplo n.º 10
0
    def _get_default_resource_path(self, object):
        """ Returns the default resource path for an object. """

        resource_path = []
        for klass in inspect.getmro(object.__class__):
            try:
                resource_path.append(get_path(klass))

            # We get an attribute error when we get to a C extension type (in
            # our case it will most likley be 'CHasTraits'.  We simply ignore
            # everything after this point!
            except AttributeError:
                break

        return resource_path
Ejemplo n.º 11
0
    def test_file_path(self):
        """
            Run 'check_file_path.py' as a spawned process and test
            return value,
            The python source is stored into a temporary test file before
            being executed in a subprocess.
        """
        store_resource('AppTools',
                       os.path.join('apptools', 'persistence','tests',
                                    'check_file_path.py'),
                       self.tmpname)

        retcode = subprocess.call([sys.executable, self.tmpname],
                                  cwd=get_path(Tests))

        self.assertEqual(retcode, 0)
Ejemplo n.º 12
0
    def get_family_members_from_file(self, filename=None):
        """Retrieves a list of family names and member lists from a file.

            Parameters
            ----------
            filename:
                full path and name of spec file for member names
        """

        if not filename:
            filename = os.path.join(get_path(self), 'data',
                                    'unit_family_membership.txt')
        fh = open(filename)

        csv_reader = csv.reader(fh, delimiter=' ', skipinitialspace=True)

        logger.debug('Loading default unit info from %s...' % filename)

        for data in csv_reader:
            # Ignore blank lines, comment lines and column names row:
            if (len( data ) == 0) or (data[0][0:1] == '#') or \
               data[0].startswith("FAMILY"):
                pass
            else:
                family_name = data[0].lower()
                # add the family name to the alias list as well ....
                for member_name in data:
                    if member_name in self.member_names:
                        print(
                            'Warning: duplicate key: %s in %s' %
                            (member_name, filename))
                    # print '    adding %s to member_names...' % member_name
                    self.member_names[member_name] = family_name

                # set up the preferred log name for the family to be the
                # first one in the alias list if possible.  Otherwise just
                # use the family_name
                if len(data) > 1:
                    self.preferred_names[family_name] = data[1].lower()
                else:
                    self.preferred_names[family_name] = data[1].lower()

        fh.close()
        logger.debug('Loading default unit info...Done')
        return
Ejemplo n.º 13
0
    def get_family_members_from_file(self, filename=None):
        """Retrieves a list of family names and member lists from a file.

            Parameters
            ----------
            filename:
                full path and name of spec file for member names
        """

        if not filename:
            filename = os.path.join(get_path(self), 'data',
                                    'unit_family_membership.txt')
        fh = file(filename)

        csv_reader = csv.reader(fh, delimiter=' ', skipinitialspace=True)

        logger.debug('Loading default unit info from %s...' % filename)

        for data in csv_reader:
            # Ignore blank lines, comment lines and column names row:
            if (len( data ) == 0) or (data[0][0:1] == '#') or \
               data[0].startswith("FAMILY"):
                pass
            else:
                family_name = data[0].lower()
                # add the family name to the alias list as well ....
                for member_name in data:
                    if member_name in self.member_names:
                        print('Warning: duplicate key: %s in %s' %
                              (member_name, filename))
                    #print '    adding %s to member_names...' % member_name
                    self.member_names[member_name] = family_name

                # set up the preferred log name for the family to be the
                # first one in the alias list if possible.  Otherwise just
                # use the family_name
                if len(data) > 1:
                    self.preferred_names[family_name] = data[1].lower()
                else:
                    self.preferred_names[family_name] = data[1].lower()

        fh.close()
        logger.debug('Loading default unit info...Done')
        return
Ejemplo n.º 14
0
    def get_unit_families_from_file(self, filename=None):
        """Retrieves a list of family names and member lists from a file.

            Parameters
            ----------
            filepath:
                full path and name of spec file for member names
        """

        if not filename:
            filename = os.path.join(get_path(self), 'data',
                                    'unit_families.txt')

        is_data = False
        converters = []
        fh = open(filename)

        logger.debug('Loading default unit info from %s...' % filename)

        for data in csv.reader(fh, delimiter=' ', skipinitialspace=True):
            if (len(data) == 0) or (data[0][0:1] == '#'):
                # Ignore blank lines and comment lines:
                pass
            elif is_data:
                self.unit_names[data[0].lower()] = list(map(lambda func,
                                                            x: func(x),
                                                            converters, data))
            else:
                # Parse the header line
                is_data = True
                column_names = self.column_names
                converters = []
                for i, column in enumerate(data):
                    column_names[column] = i
                    if column[-6:] == '_UNITS':
                        converters.append(cvt_unit)
                        self.unit_systems.append(column[:-6])
                    else:
                        converters.append(cvt_str)
        fh.close()
        logger.debug('Loading default unit info...Done')
        return
Ejemplo n.º 15
0
    def get_unit_families_from_file(self, filename=None):
        """Retrieves a list of family names and member lists from a file.

            Parameters
            ----------
            filepath:
                full path and name of spec file for member names
        """

        if not filename:
            filename = os.path.join(get_path(self), 'data',
                                    'unit_families.txt')

        is_data = False
        converters = []
        fh = open(filename)

        logger.debug('Loading default unit info from %s...' % filename)

        for data in csv.reader(fh, delimiter=' ', skipinitialspace=True):
            if (len(data) == 0) or (data[0][0:1] == '#'):
                # Ignore blank lines and comment lines:
                pass
            elif is_data:
                self.unit_names[data[0].lower()] = list(
                    map(lambda func, x: func(x), converters, data))
            else:
                # Parse the header line
                is_data = True
                column_names = self.column_names
                converters = []
                for i, column in enumerate(data):
                    column_names[column] = i
                    if column[-6:] == '_UNITS':
                        converters.append(cvt_unit)
                        self.unit_systems.append(column[:-6])
                    else:
                        converters.append(cvt_str)
        fh.close()
        logger.debug('Loading default unit info...Done')
        return