def test_import_object_any(self): this = os.path.abspath(os.path.dirname(__file__)) data = os.path.join(this, "datadoc") with sys_path_append(data): obj, name, kind = import_any_object("exdocassert.onefunction") self.assertTrue(obj is not None) self.assertTrue(obj(4, 5), 9) self.assertEqual(kind, 'function')
def test_import_object_any(self): this = os.path.abspath(os.path.dirname(__file__)) data = os.path.join(this, "datadoc") with sys_path_append(data): obj, name, kind = import_any_object("exdocassert.onefunction") self.assertTrue(obj is not None) self.assertTrue(obj(4, 5), 9) self.assertEqual(kind, 'function')
def test_import_any_object(self): this = os.path.abspath(os.path.dirname(__file__)) data = os.path.join(this, "datadoc") with sys_path_append(data): obj, name, kind = import_any_object("exsig.clex") self.assertTrue(obj is not None) # self.assertTrue(obj.(4, 5), 9) self.assertEqual(name, "clex") self.assertEqual(kind, "class")
def test_import_any_object_benchmark(self): this = os.path.abspath(os.path.dirname(__file__)) data = os.path.join(this, "datadoc") with sys_path_append(data): name = "pyquickhelper.benchhelper.grid_benchmark.GridBenchMark.bench_experiment" import_object(name, "method") obj, name, kind = import_any_object(name) self.assertTrue(obj is not None) # self.assertTrue(obj.(4, 5), 9) self.assertEqual(name, "bench_experiment") self.assertEqual(kind, "method")
def test_import_object_kind_check(self): self.assertNotEmpty(import_object('pandas.DataFrame', 'class')) self.assertRaise(lambda: import_object( 'pandas.DataFrame', 'function'), TypeError) self.assertNotEmpty(import_object( 'pandas.core.frame.DataFrame', 'class')) self.assertRaise(lambda: import_object( 'pandas.core.frame.DataFrame', 'function'), TypeError) obj, name, kind = import_any_object("pandas.core.frame.DataFrame") self.assertNotEmpty(obj) self.assertEqual(name, 'DataFrame') self.assertEqual(kind, 'class')
def test_autosignature_open(self): self.assertIsInstance(numpy.ndarray.__init__.__text_signature__, str) res = import_object("numpy.ndarray.__init__", "method") self.assertNotEmpty(res) obj, _, kind = import_any_object( "numpy.ndarray.__init__", use_init=False) self.assertNotEmpty(obj) self.assertIn(kind, ("method", "property")) newstring = [ ".. autosignature:: numpy.ndarray.__init__\n :path: full"] newstring = "\n".join(newstring) res = rst2html(newstring, writer="rst", layout="sphinx") self.assertIn("numpy.ndarray.__init__", res)
def test_import_any_object_property(self): this = os.path.abspath(os.path.dirname(__file__)) data = os.path.join(this, "datadoc") sys.path.append(data) name = "pyquickhelper.benchhelper.benchmark.BenchMark.Name" import_object(name, "property") obj, name, kind = import_any_object(name) sys.path.pop() self.assertTrue(obj is not None) # self.assertTrue(obj.(4, 5), 9) self.assertEqual(name, "Name") self.assertEqual(kind, "property")
def test_import_object_kind_check(self): self.assertNotEmpty(import_object('pandas.DataFrame', 'class')) self.assertRaise(lambda: import_object('pandas.DataFrame', 'function'), TypeError) self.assertNotEmpty( import_object('pandas.core.frame.DataFrame', 'class')) self.assertRaise( lambda: import_object('pandas.core.frame.DataFrame', 'function'), TypeError) obj, name, kind = import_any_object("pandas.core.frame.DataFrame") self.assertNotEmpty(obj) self.assertEqual(name, 'DataFrame') self.assertEqual(kind, 'class')
def test_autosignature_open(self): self.assertIsInstance(numpy.ndarray.__init__.__text_signature__, str) res = import_object("numpy.ndarray.__init__", "method") self.assertNotEmpty(res) obj, _, kind = import_any_object("numpy.ndarray.__init__", use_init=False) self.assertNotEmpty(obj) self.assertIn(kind, ("method", "property")) newstring = [ ".. autosignature:: numpy.ndarray.__init__\n :path: full" ] newstring = "\n".join(newstring) res = rst2html(newstring, writer="rst", layout="sphinx") self.assertIn("numpy.ndarray.__init__", res)
def test_import_any_object_static(self): this = os.path.abspath(os.path.dirname(__file__)) data = os.path.join(this, "datadoc") with sys_path_append(data): name = "pyquickhelper.filehelper.transfer_api.TransferAPI_FileInfo.read_json" try: import_object(name, "method") self.assertTrue(False) except TypeError as e: pass import_object(name, "staticmethod") obj, name, kind = import_any_object(name) self.assertTrue(obj is not None) # self.assertTrue(obj.(4, 5), 9) self.assertEqual(name, "read_json") self.assertEqual(kind, "staticmethod")
def test_import_object(self): obj = 'cpyquickhelper.numbers.cbenchmark.vector_dot_product16' res = import_object(obj, 'function', use_init=False) self.assertNotEmpty(res) res = import_any_object(obj) self.assertNotEmpty(res)
def test_import_object(self): obj = 'cpyquickhelper.numbers.cbenchmark.vector_dot_product16' res = import_object(obj, 'function', use_init=False) self.assertNotEmpty(res) res = import_any_object(obj) self.assertNotEmpty(res)