Exemplo n.º 1
0
def test_is_seq():
    fn = os.path.join(testdir, 'is_seq_test_file')
    file_write(fn, 'lala')
    fd = open(fn, 'r')
    for xx in ([1, 2, 3], (1, 2, 3), np.array([1, 2, 3])):
        print(type(xx))
        assert is_seq(xx) is True
    for xx in ('aaa', fd):
        print(type(xx))
        assert is_seq(xx) is False
    fd.close()
Exemplo n.º 2
0
def test_is_seq():
    fn = os.path.join(testdir, 'is_seq_test_file')
    file_write(fn, 'lala')
    fd = open(fn , 'r')
    for xx in ([1,2,3], (1,2,3), np.array([1,2,3])):
        print(type(xx))
        assert is_seq(xx) is True
    for xx in ('aaa', u'aaa', fd):
        print(type(xx))
        assert is_seq(xx) is False 
    fd.close()
Exemplo n.º 3
0
def skip_if_pkg_missing(pkgs):
    """Call skip() if package(s)/module(s) are not importable.

    Parameters
    ----------
    pkgs : str or sequence
        module/package name or sequence of names
    """
    def try_import(pkg):
        try:
            importlib.import_module(pkg)
        except ImportError:
            skip("skip test, package or module not found: {}".format(pkg))

    if isinstance(pkgs, str):
        try_import(pkgs)
    elif common.is_seq(pkgs):
        for pkg in pkgs:
            try_import(pkg)
    else:
        raise Exception("input is no str or sequence: {}".format(pkgs))
Exemplo n.º 4
0
 def is_set_attr_lst(self, attr_lst):
     assert common.is_seq(attr_lst), "attr_lst must be a sequence"
     for attr in attr_lst:
         if not self.is_set_attr(attr):
             return False
     return True                
Exemplo n.º 5
0
 def is_set_attr_lst(self, attr_lst):
     assert common.is_seq(attr_lst), "attr_lst must be a sequence"
     for attr in attr_lst:
         if not self.is_set_attr(attr):
             return False
     return True