Exemplo n.º 1
0
 def testNewWithDotConflict(self):
     env = robjects.Environment()
     env['__dict__'] = robjects.StrVector('abcd')
     env['a_a'] = robjects.IntVector((1, 2, 3))
     env['c'] = robjects.r(''' function(x) x^2''')
     self.assertRaises(packages.LibraryError, robjects.packages.Package,
                       env, "dummy_package")
Exemplo n.º 2
0
def test_clear():
    env = robjects.Environment()
    env['a'] = 123
    env['b'] = 234
    assert len(env) == 2
    env.clear()
    assert len(env) == 0
Exemplo n.º 3
0
 def test_new_with_dot_conflict(self):
     env = robjects.Environment()
     env['a.a_a'] = robjects.StrVector('abcd')
     env['a_a.a'] = robjects.IntVector((1, 2, 3))
     env['c'] = robjects.r(''' function(x) x^2''')
     with pytest.raises(packages.LibraryError):
         robjects.packages.Package(env, "dummy_package")
Exemplo n.º 4
0
def test_getsetitem():
    env = robjects.Environment()
    env['a'] = 123
    assert 'a' in env
    a = env['a']
    assert len(a) == 1
    assert a[0] == 123
Exemplo n.º 5
0
def test_keys():
    env = robjects.Environment()
    env['a'] = 123
    keys = list(env.keys())
    assert len(keys) == 1
    keys.sort()
    for it_a, it_b in zip(keys, ('a', )):
        assert it_a == it_b
Exemplo n.º 6
0
 def testKeys(self):
     env = robjects.Environment()
     env['a'] = 123
     keys = list(env.keys())
     self.assertEquals(1, len(keys))
     keys.sort()
     for it_a, it_b in zip(keys, ('a', )):
         self.assertEquals(it_a, it_b)
Exemplo n.º 7
0
def test_items():
    env = robjects.Environment()
    env['a'] = 123
    items = list(env.items())
    assert len(items) == 1
    items.sort(key=lambda x: x[0])
    for it_a, it_b in zip(items, (('a', 123), )):
        assert it_a[0] == it_b[0]
        assert it_a[1][0] == it_b[1]
Exemplo n.º 8
0
 def testItems(self):
     env = robjects.Environment()
     env['a'] = 123
     items = list(env.items())
     self.assertEquals(1, len(items))
     items.sort(key=lambda x: x[0])
     for it_a, it_b in zip(items, (('a', 123), )):
         self.assertEquals(it_a[0], it_b[0])
         self.assertEquals(it_a[1][0], it_b[1])
Exemplo n.º 9
0
 def testNew(self):
     env = robjects.Environment()
     env['a'] = robjects.StrVector('abcd')
     env['b'] = robjects.IntVector((1, 2, 3))
     env['c'] = robjects.r(''' function(x) x^2''')
     pck = robjects.packages.Package(env, "dummy_package")
     self.assertTrue(isinstance(pck.a, robjects.Vector))
     self.assertTrue(isinstance(pck.b, robjects.Vector))
     self.assertTrue(isinstance(pck.c, robjects.Function))
Exemplo n.º 10
0
 def test_new_with_dot(self):
     env = robjects.Environment()
     env['a.a'] = robjects.StrVector('abcd')
     env['b'] = robjects.IntVector((1, 2, 3))
     env['c'] = robjects.r(''' function(x) x^2''')
     pck = robjects.packages.Package(env, "dummy_package")
     assert isinstance(pck.a_a, robjects.Vector)
     assert isinstance(pck.b, robjects.Vector)
     assert isinstance(pck.c, robjects.Function)
Exemplo n.º 11
0
def test_values():
    env = robjects.Environment()
    env['a'] = 123
    env['b'] = 234
    values = list(env.values())
    assert len(values) == 2
    values.sort(key=lambda x: x[0])
    for it_a, it_b in zip(values, (123, 234)):
        assert len(it_a) == 1
        assert it_a[0] == it_b
 def testAssignNumpyObject(self):
     x = numpy.arange(-10., 10., 1)
     env = robjects.Environment()
     env["x"] = x
     self.assertEqual(1, len(env))
     # do have an R object of the right type ?
     x_r = env["x"]
     self.assertEqual(robjects.rinterface.REALSXP, x_r.typeof)
     #
     self.assertEqual((20, ), tuple(x_r.dim))
Exemplo n.º 13
0
 def test_assign_numpy_object(self):
     x = numpy.arange(-10., 10., 1)
     env = robjects.Environment()
     env['x'] = x
     assert len(env) == 1
     # do have an R object of the right type ?
     x_r = env['x']
     assert robjects.rinterface.RTYPES.REALSXP == x_r.typeof
     #
     assert tuple(x_r.dim) == (20, )
Exemplo n.º 14
0
    def testEvalInEnvironment(self):
        code = """
x <- 1+2
y <- (x+1) / 2
"""
        env = robjects.Environment()
        res = lg.eval(code, envir=env)
        self.assertTrue('x' in env.keys())
        self.assertEqual(3, env['x'][0])
        self.assertTrue('y' in env.keys())
        self.assertEqual(2, env['y'][0])
Exemplo n.º 15
0
def testeval_in_environment(clean_globalenv):
    code = """
    x <- 1+2
    y <- (x+1) / 2
    """
    env = robjects.Environment()
    res = lg.eval(code, envir=env)
    assert 'x' in env.keys()
    assert env['x'][0] == 3
    assert 'y' in env.keys()
    assert env['y'][0] == 2
Exemplo n.º 16
0
def test_popitem():
    env = robjects.Environment()
    env['a'] = 123
    env['b'] = 456
    robjs = []
    assert len(env) == 2
    robjs.append(env.popitem())
    assert len(env) == 1
    robjs.append(env.popitem())
    assert len(env) == 0
    assert sorted([(k, v[0]) for k, v in robjs]) == [('a', 123), ('b', 456)]

    with pytest.raises(KeyError):
        robjs.append(env.popitem())
Exemplo n.º 17
0
def test_pop_key():
    env = robjects.Environment()
    env['a'] = 123
    env['b'] = 456
    robjs = []
    assert len(env) == 2
    robjs.append(env.pop('a'))
    assert len(env) == 1
    robjs.append(env.pop('b'))
    assert len(env) == 0
    assert [x[0] for x in robjs] == [123, 456]
    with pytest.raises(KeyError):
        env.pop('c')
    assert env.pop('c', 789) == 789
    with pytest.raises(ValueError):
        env.pop('c', 1, 2)
Exemplo n.º 18
0
 def test_new_with_dot_conflict2(self):
     env = robjects.Environment()
     name_in_use = dir(packages.Package(env, "foo"))[0]
     env[name_in_use] = robjects.StrVector('abcd')
     with pytest.raises(packages.LibraryError):
         robjects.packages.Package(env, "dummy_package")
Exemplo n.º 19
0
 def testNewWithDotConflict2(self):
     env = robjects.Environment()
     env['__dict__'] = robjects.StrVector('abcd')
     self.assertRaises(packages.LibraryError, robjects.packages.Package,
                       env, "dummy_package")
Exemplo n.º 20
0
 def testAssignNumpyObject(self):
     x = numpy.arange(-10., 10., 1)
     env = robjects.Environment()
     env["x"] = x
     self.assertEqual(1, len(env))
     self.assertEqual(type(x), type(env["x"]))
Exemplo n.º 21
0
 def tests_package_repr(self):
     env = robjects.Environment()
     pck = robjects.packages.Package(env, "dummy_package")
     assert isinstance(repr(pck), str)
Exemplo n.º 22
0
 def testAssignNumpyObject(self):
     x = numpy.arange(-10., 10., 1)
     env = robjects.Environment()
     env["x"] = x
     self.assertEqual(1, len(env))
     self.assertTrue(isinstance(env["x"], robjects.Array))
Exemplo n.º 23
0
 def testSetItem(self):
     env = robjects.Environment()
     env['a'] = 123
     self.assertTrue('a' in env)
Exemplo n.º 24
0
 def testNew(self):
     env = robjects.Environment()
     self.assertEqual(rinterface.ENVSXP, env.typeof)
Exemplo n.º 25
0
def test_init_empty():
    env = robjects.Environment()
    assert env.typeof == rinterface.RTYPES.ENVSXP
Exemplo n.º 26
0
 def testNewWithDotConflict2(self):
     env = robjects.Environment()
     name_in_use = dir(packages.Package(env, "foo"))[0]
     env[name_in_use] = robjects.StrVector('abcd')
     self.assertRaises(packages.LibraryError, robjects.packages.Package,
                       env, "dummy_package")
Exemplo n.º 27
0
def test_init_invalid():
    with pytest.raises(ValueError):
        robjects.Environment('a')