Ejemplo n.º 1
0
    def test_is_str(self):
        self.assertTrue(labtypes.is_str("Hello, World!"))
        self.assertTrue(labtypes.is_str(str("Hello, World!")))

        if lab.is_python3():
            self.assertFalse(labtypes.is_str("Hello, World!".encode("utf-8")))
            self.assertFalse(labtypes.is_str(bytes("Hello, World!".encode("utf-8"))))
        else:
            self.assertTrue(labtypes.is_str("Hello, World!".encode("utf-8")))
            self.assertTrue(labtypes.is_str(bytes("Hello, World!".encode("utf-8"))))

        self.assertFalse(labtypes.is_str(8))
        self.assertFalse(labtypes.is_str(['a', 'b', 'c']))
        self.assertFalse(labtypes.is_str({'a': 'b', 'c': 18}))
Ejemplo n.º 2
0
def import_foreign(name, custom_name=None):
    """
    Import a module with a custom name.

    NOTE this is only needed for Python2. For Python3, import the
    module using the "as" keyword to declare the custom name.

    For implementation details, see:
    http://stackoverflow.com/a/6032023

    Example:

      To import the standard module "math" as "std_math":

          if labm8.is_python3():
            import math as std_math
          else:
            std_math = modules.import_foreign("math", "std_math")

    Arguments:

        name (str): The name of the module to import.
        custom_name (str, optional): The custom name to assign the module to.

    Raises:
        ImportError: If the module is not found.
    """
    if lab.is_python3():
        io.error(("Ignoring attempt to import foreign module '{mod}' "
                  "using python version {major}.{minor}"
                  .format(mod=name, major=sys.version_info[0],
                          minor=sys.version_info[1])))
        return

    custom_name = custom_name or name

    f, pathname, desc = imp.find_module(name, sys.path[1:])
    module = imp.load_module(custom_name, f, pathname, desc)
    f.close()

    return module
Ejemplo n.º 3
0
#
import labm8
import numpy as np

from labm8 import fs
from labm8.time import nowstr
from subprocess import Popen, PIPE
from tempfile import NamedTemporaryFile
from random import randint

import clgen
from clgen import log as clgen_log
from clgen import model
from clgen import preprocess

if labm8.is_python3():
    from io import StringIO
else:
    from StringIO import StringIO


def features_from_file(path):
    """
    Fetch features from file.

    Arguments:
        path (str): Path to file.

    Returns:
        np.array: Feature values.
    """
Ejemplo n.º 4
0
#
import labm8
import numpy as np

from labm8 import fs
from labm8.time import nowstr
from subprocess import Popen, PIPE
from tempfile import NamedTemporaryFile
from random import randint

import clgen
from clgen import log as clgen_log
from clgen import model
from clgen import preprocess

if labm8.is_python3():
    from io import StringIO
else:
    from StringIO import StringIO


def features_from_file(path):
    """
    Fetch features from file.

    Arguments:
        path (str): Path to file.

    Returns:
        np.array: Feature values.
    """
Ejemplo n.º 5
0
 def test_is_python3(self):
     if sys.version_info >= (3, 0):
         self._test(True, lab.is_python3())
     else:
         self._test(False, lab.is_python3())
Ejemplo n.º 6
0
# or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
# License for more details.
#
# You should have received a copy of the GNU General Public License
# along with labm8.  If not, see <http://www.gnu.org/licenses/>.
import atexit
import csv
import re
import six
import sqlite3 as sql

import labm8 as lab
from labm8 import fs
from labm8 import io

if lab.is_python3():
    from io import StringIO
else:
    from StringIO import StringIO


class Error(Exception):
    """
    Module-level base error class.
    """
    pass


class SchemaError(Error):
    """
    Error thrown in case of conflicting schemas.