Fred Drake | 3a28ca8 | 2001-08-13 20:26:19 +0000 | [diff] [blame] | 1 | ''' |
| 2 | Test cases for pyclbr.py |
| 3 | Nick Mathewson |
| 4 | ''' |
csabella | 246ff3b | 2017-07-03 21:31:25 -0400 | [diff] [blame] | 5 | |
| 6 | import os |
Christian Heimes | 05e8be1 | 2008-02-23 18:30:17 +0000 | [diff] [blame] | 7 | import sys |
csabella | 246ff3b | 2017-07-03 21:31:25 -0400 | [diff] [blame] | 8 | from textwrap import dedent |
Guido van Rossum | 1325790 | 2007-06-07 23:15:56 +0000 | [diff] [blame] | 9 | from types import FunctionType, MethodType, BuiltinFunctionType |
Fred Drake | 3a28ca8 | 2001-08-13 20:26:19 +0000 | [diff] [blame] | 10 | import pyclbr |
Zachary Ware | ac28b79 | 2015-12-04 23:32:23 -0600 | [diff] [blame] | 11 | from unittest import TestCase, main as unittest_main |
csabella | 246ff3b | 2017-07-03 21:31:25 -0400 | [diff] [blame] | 12 | from test import support |
Brett Cannon | 5086589 | 2019-03-22 15:16:50 -0700 | [diff] [blame] | 13 | from test.test_importlib import util as test_importlib_util |
csabella | 246ff3b | 2017-07-03 21:31:25 -0400 | [diff] [blame] | 14 | from functools import partial |
Fred Drake | 3a28ca8 | 2001-08-13 20:26:19 +0000 | [diff] [blame] | 15 | |
Anthony Baxter | c2a5a63 | 2004-08-02 06:10:11 +0000 | [diff] [blame] | 16 | StaticMethodType = type(staticmethod(lambda: None)) |
| 17 | ClassMethodType = type(classmethod(lambda c: None)) |
| 18 | |
Tim Peters | 0460106 | 2001-08-13 22:25:24 +0000 | [diff] [blame] | 19 | # Here we test the python class browser code. |
Fred Drake | 3a28ca8 | 2001-08-13 20:26:19 +0000 | [diff] [blame] | 20 | # |
| 21 | # The main function in this suite, 'testModule', compares the output |
| 22 | # of pyclbr with the introspected members of a module. Because pyclbr |
| 23 | # is imperfect (as designed), testModule is called with a set of |
| 24 | # members to ignore. |
| 25 | |
Guido van Rossum | 0ed7aa1 | 2002-12-02 14:54:20 +0000 | [diff] [blame] | 26 | class PyclbrTest(TestCase): |
Fred Drake | 3a28ca8 | 2001-08-13 20:26:19 +0000 | [diff] [blame] | 27 | |
| 28 | def assertListEq(self, l1, l2, ignore): |
| 29 | ''' succeed iff {l1} - {ignore} == {l2} - {ignore} ''' |
Raymond Hettinger | a690a99 | 2003-11-16 16:17:49 +0000 | [diff] [blame] | 30 | missing = (set(l1) ^ set(l2)) - set(ignore) |
Raymond Hettinger | 91bbd9a | 2003-05-02 09:06:28 +0000 | [diff] [blame] | 31 | if missing: |
Guido van Rossum | be19ed7 | 2007-02-09 05:37:30 +0000 | [diff] [blame] | 32 | print("l1=%r\nl2=%r\nignore=%r" % (l1, l2, ignore), file=sys.stderr) |
Raymond Hettinger | 91bbd9a | 2003-05-02 09:06:28 +0000 | [diff] [blame] | 33 | self.fail("%r missing" % missing.pop()) |
Tim Peters | 0460106 | 2001-08-13 22:25:24 +0000 | [diff] [blame] | 34 | |
Fred Drake | 3a28ca8 | 2001-08-13 20:26:19 +0000 | [diff] [blame] | 35 | def assertHasattr(self, obj, attr, ignore): |
| 36 | ''' succeed iff hasattr(obj,attr) or attr in ignore. ''' |
| 37 | if attr in ignore: return |
Guido van Rossum | be19ed7 | 2007-02-09 05:37:30 +0000 | [diff] [blame] | 38 | if not hasattr(obj, attr): print("???", attr) |
Benjamin Peterson | c9c0f20 | 2009-06-30 23:06:06 +0000 | [diff] [blame] | 39 | self.assertTrue(hasattr(obj, attr), |
Tim Peters | 5e5ca56 | 2002-07-10 02:37:21 +0000 | [diff] [blame] | 40 | 'expected hasattr(%r, %r)' % (obj, attr)) |
Fred Drake | 3a28ca8 | 2001-08-13 20:26:19 +0000 | [diff] [blame] | 41 | |
| 42 | |
| 43 | def assertHaskey(self, obj, key, ignore): |
Guido van Rossum | e2b70bc | 2006-08-18 22:13:04 +0000 | [diff] [blame] | 44 | ''' succeed iff key in obj or key in ignore. ''' |
Fred Drake | 3a28ca8 | 2001-08-13 20:26:19 +0000 | [diff] [blame] | 45 | if key in ignore: return |
Guido van Rossum | e2b70bc | 2006-08-18 22:13:04 +0000 | [diff] [blame] | 46 | if key not in obj: |
Guido van Rossum | be19ed7 | 2007-02-09 05:37:30 +0000 | [diff] [blame] | 47 | print("***",key, file=sys.stderr) |
Benjamin Peterson | 577473f | 2010-01-19 00:09:57 +0000 | [diff] [blame] | 48 | self.assertIn(key, obj) |
Fred Drake | 3a28ca8 | 2001-08-13 20:26:19 +0000 | [diff] [blame] | 49 | |
Anthony Baxter | c2a5a63 | 2004-08-02 06:10:11 +0000 | [diff] [blame] | 50 | def assertEqualsOrIgnored(self, a, b, ignore): |
Fred Drake | 3a28ca8 | 2001-08-13 20:26:19 +0000 | [diff] [blame] | 51 | ''' succeed iff a == b or a in ignore or b in ignore ''' |
Anthony Baxter | c2a5a63 | 2004-08-02 06:10:11 +0000 | [diff] [blame] | 52 | if a not in ignore and b not in ignore: |
Ezio Melotti | b3aedd4 | 2010-11-20 19:04:17 +0000 | [diff] [blame] | 53 | self.assertEqual(a, b) |
Fred Drake | 3a28ca8 | 2001-08-13 20:26:19 +0000 | [diff] [blame] | 54 | |
| 55 | def checkModule(self, moduleName, module=None, ignore=()): |
| 56 | ''' succeed iff pyclbr.readmodule_ex(modulename) corresponds |
| 57 | to the actual module object, module. Any identifiers in |
| 58 | ignore are ignored. If no module is provided, the appropriate |
| 59 | module is loaded with __import__.''' |
| 60 | |
Guido van Rossum | d858f70 | 2006-04-21 09:17:15 +0000 | [diff] [blame] | 61 | ignore = set(ignore) | set(['object']) |
| 62 | |
Benjamin Peterson | 2a691a8 | 2008-03-31 01:51:45 +0000 | [diff] [blame] | 63 | if module is None: |
Guido van Rossum | 0ed7aa1 | 2002-12-02 14:54:20 +0000 | [diff] [blame] | 64 | # Import it. |
| 65 | # ('<silly>' is to work around an API silliness in __import__) |
| 66 | module = __import__(moduleName, globals(), {}, ['<silly>']) |
Fred Drake | 3a28ca8 | 2001-08-13 20:26:19 +0000 | [diff] [blame] | 67 | |
| 68 | dict = pyclbr.readmodule_ex(moduleName) |
| 69 | |
Anthony Baxter | c2a5a63 | 2004-08-02 06:10:11 +0000 | [diff] [blame] | 70 | def ismethod(oclass, obj, name): |
| 71 | classdict = oclass.__dict__ |
Christian Heimes | 4a22b5d | 2007-11-25 09:39:14 +0000 | [diff] [blame] | 72 | if isinstance(obj, MethodType): |
| 73 | # could be a classmethod |
| 74 | if (not isinstance(classdict[name], ClassMethodType) or |
Christian Heimes | ff73795 | 2007-11-27 10:40:20 +0000 | [diff] [blame] | 75 | obj.__self__ is not oclass): |
Anthony Baxter | c2a5a63 | 2004-08-02 06:10:11 +0000 | [diff] [blame] | 76 | return False |
Christian Heimes | 4a22b5d | 2007-11-25 09:39:14 +0000 | [diff] [blame] | 77 | elif not isinstance(obj, FunctionType): |
| 78 | return False |
Anthony Baxter | c2a5a63 | 2004-08-02 06:10:11 +0000 | [diff] [blame] | 79 | |
Guido van Rossum | 7f6a439 | 2002-12-03 08:16:50 +0000 | [diff] [blame] | 80 | objname = obj.__name__ |
| 81 | if objname.startswith("__") and not objname.endswith("__"): |
Christian Heimes | 4a22b5d | 2007-11-25 09:39:14 +0000 | [diff] [blame] | 82 | objname = "_%s%s" % (oclass.__name__, objname) |
Guido van Rossum | 7f6a439 | 2002-12-03 08:16:50 +0000 | [diff] [blame] | 83 | return objname == name |
| 84 | |
Fred Drake | 3a28ca8 | 2001-08-13 20:26:19 +0000 | [diff] [blame] | 85 | # Make sure the toplevel functions and classes are the same. |
| 86 | for name, value in dict.items(): |
Tim Peters | 0460106 | 2001-08-13 22:25:24 +0000 | [diff] [blame] | 87 | if name in ignore: |
Fred Drake | 3a28ca8 | 2001-08-13 20:26:19 +0000 | [diff] [blame] | 88 | continue |
| 89 | self.assertHasattr(module, name, ignore) |
| 90 | py_item = getattr(module, name) |
| 91 | if isinstance(value, pyclbr.Function): |
Ezio Melotti | e961593 | 2010-01-24 19:26:24 +0000 | [diff] [blame] | 92 | self.assertIsInstance(py_item, (FunctionType, BuiltinFunctionType)) |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 93 | if py_item.__module__ != moduleName: |
| 94 | continue # skip functions that came from somewhere else |
Ezio Melotti | b3aedd4 | 2010-11-20 19:04:17 +0000 | [diff] [blame] | 95 | self.assertEqual(py_item.__module__, value.module) |
Fred Drake | 3a28ca8 | 2001-08-13 20:26:19 +0000 | [diff] [blame] | 96 | else: |
Ezio Melotti | e961593 | 2010-01-24 19:26:24 +0000 | [diff] [blame] | 97 | self.assertIsInstance(py_item, type) |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 98 | if py_item.__module__ != moduleName: |
| 99 | continue # skip classes that came from somewhere else |
| 100 | |
Fred Drake | 3a28ca8 | 2001-08-13 20:26:19 +0000 | [diff] [blame] | 101 | real_bases = [base.__name__ for base in py_item.__bases__] |
Tim Peters | 0460106 | 2001-08-13 22:25:24 +0000 | [diff] [blame] | 102 | pyclbr_bases = [ getattr(base, 'name', base) |
Fred Drake | 3a28ca8 | 2001-08-13 20:26:19 +0000 | [diff] [blame] | 103 | for base in value.super ] |
Tim Peters | 0460106 | 2001-08-13 22:25:24 +0000 | [diff] [blame] | 104 | |
Guido van Rossum | 0ed7aa1 | 2002-12-02 14:54:20 +0000 | [diff] [blame] | 105 | try: |
| 106 | self.assertListEq(real_bases, pyclbr_bases, ignore) |
| 107 | except: |
Guido van Rossum | be19ed7 | 2007-02-09 05:37:30 +0000 | [diff] [blame] | 108 | print("class=%s" % py_item, file=sys.stderr) |
Guido van Rossum | 0ed7aa1 | 2002-12-02 14:54:20 +0000 | [diff] [blame] | 109 | raise |
Fred Drake | 3a28ca8 | 2001-08-13 20:26:19 +0000 | [diff] [blame] | 110 | |
| 111 | actualMethods = [] |
Tim Peters | 37a309d | 2001-09-04 01:20:04 +0000 | [diff] [blame] | 112 | for m in py_item.__dict__.keys(): |
Anthony Baxter | c2a5a63 | 2004-08-02 06:10:11 +0000 | [diff] [blame] | 113 | if ismethod(py_item, getattr(py_item, m), m): |
Fred Drake | 3a28ca8 | 2001-08-13 20:26:19 +0000 | [diff] [blame] | 114 | actualMethods.append(m) |
| 115 | foundMethods = [] |
| 116 | for m in value.methods.keys(): |
| 117 | if m[:2] == '__' and m[-2:] != '__': |
| 118 | foundMethods.append('_'+name+m) |
| 119 | else: |
| 120 | foundMethods.append(m) |
| 121 | |
Guido van Rossum | 7f6a439 | 2002-12-03 08:16:50 +0000 | [diff] [blame] | 122 | try: |
| 123 | self.assertListEq(foundMethods, actualMethods, ignore) |
Ezio Melotti | b3aedd4 | 2010-11-20 19:04:17 +0000 | [diff] [blame] | 124 | self.assertEqual(py_item.__module__, value.module) |
Fred Drake | 3a28ca8 | 2001-08-13 20:26:19 +0000 | [diff] [blame] | 125 | |
Anthony Baxter | c2a5a63 | 2004-08-02 06:10:11 +0000 | [diff] [blame] | 126 | self.assertEqualsOrIgnored(py_item.__name__, value.name, |
| 127 | ignore) |
Guido van Rossum | 7f6a439 | 2002-12-03 08:16:50 +0000 | [diff] [blame] | 128 | # can't check file or lineno |
| 129 | except: |
Guido van Rossum | be19ed7 | 2007-02-09 05:37:30 +0000 | [diff] [blame] | 130 | print("class=%s" % py_item, file=sys.stderr) |
Guido van Rossum | 7f6a439 | 2002-12-03 08:16:50 +0000 | [diff] [blame] | 131 | raise |
Fred Drake | 3a28ca8 | 2001-08-13 20:26:19 +0000 | [diff] [blame] | 132 | |
| 133 | # Now check for missing stuff. |
Guido van Rossum | 0ed7aa1 | 2002-12-02 14:54:20 +0000 | [diff] [blame] | 134 | def defined_in(item, module): |
Guido van Rossum | 1325790 | 2007-06-07 23:15:56 +0000 | [diff] [blame] | 135 | if isinstance(item, type): |
Guido van Rossum | 0ed7aa1 | 2002-12-02 14:54:20 +0000 | [diff] [blame] | 136 | return item.__module__ == module.__name__ |
| 137 | if isinstance(item, FunctionType): |
Neal Norwitz | 221085d | 2007-02-25 20:55:47 +0000 | [diff] [blame] | 138 | return item.__globals__ is module.__dict__ |
Guido van Rossum | 0ed7aa1 | 2002-12-02 14:54:20 +0000 | [diff] [blame] | 139 | return False |
Fred Drake | 3a28ca8 | 2001-08-13 20:26:19 +0000 | [diff] [blame] | 140 | for name in dir(module): |
| 141 | item = getattr(module, name) |
Guido van Rossum | 1325790 | 2007-06-07 23:15:56 +0000 | [diff] [blame] | 142 | if isinstance(item, (type, FunctionType)): |
Guido van Rossum | 0ed7aa1 | 2002-12-02 14:54:20 +0000 | [diff] [blame] | 143 | if defined_in(item, module): |
| 144 | self.assertHaskey(dict, name, ignore) |
Fred Drake | 3a28ca8 | 2001-08-13 20:26:19 +0000 | [diff] [blame] | 145 | |
| 146 | def test_easy(self): |
| 147 | self.checkModule('pyclbr') |
Serhiy Storchaka | 3f22811 | 2018-09-27 17:42:37 +0300 | [diff] [blame] | 148 | # XXX: Metaclasses are not supported |
| 149 | # self.checkModule('ast') |
Benjamin Peterson | bed7d04 | 2009-07-19 21:01:52 +0000 | [diff] [blame] | 150 | self.checkModule('doctest', ignore=("TestResults", "_SpoofOut", |
Andrew Svetlov | 7c1017b | 2013-08-29 01:24:39 +0300 | [diff] [blame] | 151 | "DocTestCase", '_DocTestSuite')) |
Christian Heimes | 25bb783 | 2008-01-11 16:17:00 +0000 | [diff] [blame] | 152 | self.checkModule('difflib', ignore=("Match",)) |
Fred Drake | 3a28ca8 | 2001-08-13 20:26:19 +0000 | [diff] [blame] | 153 | |
Anthony Baxter | c2a5a63 | 2004-08-02 06:10:11 +0000 | [diff] [blame] | 154 | def test_decorators(self): |
| 155 | # XXX: See comment in pyclbr_input.py for a test that would fail |
| 156 | # if it were not commented out. |
| 157 | # |
Christian Heimes | 4a22b5d | 2007-11-25 09:39:14 +0000 | [diff] [blame] | 158 | self.checkModule('test.pyclbr_input', ignore=['om']) |
Tim Peters | 6db15d7 | 2004-08-04 02:36:18 +0000 | [diff] [blame] | 159 | |
csabella | 246ff3b | 2017-07-03 21:31:25 -0400 | [diff] [blame] | 160 | def test_nested(self): |
| 161 | mb = pyclbr |
| 162 | # Set arguments for descriptor creation and _creat_tree call. |
| 163 | m, p, f, t, i = 'test', '', 'test.py', {}, None |
| 164 | source = dedent("""\ |
| 165 | def f0: |
| 166 | def f1(a,b,c): |
| 167 | def f2(a=1, b=2, c=3): pass |
| 168 | return f1(a,b,d) |
| 169 | class c1: pass |
| 170 | class C0: |
| 171 | "Test class." |
| 172 | def F1(): |
| 173 | "Method." |
| 174 | return 'return' |
| 175 | class C1(): |
| 176 | class C2: |
| 177 | "Class nested within nested class." |
| 178 | def F3(): return 1+1 |
| 179 | |
| 180 | """) |
| 181 | actual = mb._create_tree(m, p, f, source, t, i) |
| 182 | |
| 183 | # Create descriptors, linked together, and expected dict. |
| 184 | f0 = mb.Function(m, 'f0', f, 1) |
| 185 | f1 = mb._nest_function(f0, 'f1', 2) |
| 186 | f2 = mb._nest_function(f1, 'f2', 3) |
| 187 | c1 = mb._nest_class(f0, 'c1', 5) |
| 188 | C0 = mb.Class(m, 'C0', None, f, 6) |
| 189 | F1 = mb._nest_function(C0, 'F1', 8) |
| 190 | C1 = mb._nest_class(C0, 'C1', 11) |
| 191 | C2 = mb._nest_class(C1, 'C2', 12) |
| 192 | F3 = mb._nest_function(C2, 'F3', 14) |
| 193 | expected = {'f0':f0, 'C0':C0} |
| 194 | |
| 195 | def compare(parent1, children1, parent2, children2): |
| 196 | """Return equality of tree pairs. |
| 197 | |
| 198 | Each parent,children pair define a tree. The parents are |
| 199 | assumed equal. Comparing the children dictionaries as such |
| 200 | does not work due to comparison by identity and double |
| 201 | linkage. We separate comparing string and number attributes |
| 202 | from comparing the children of input children. |
| 203 | """ |
| 204 | self.assertEqual(children1.keys(), children2.keys()) |
| 205 | for ob in children1.values(): |
| 206 | self.assertIs(ob.parent, parent1) |
| 207 | for ob in children2.values(): |
| 208 | self.assertIs(ob.parent, parent2) |
| 209 | for key in children1.keys(): |
| 210 | o1, o2 = children1[key], children2[key] |
| 211 | t1 = type(o1), o1.name, o1.file, o1.module, o1.lineno |
| 212 | t2 = type(o2), o2.name, o2.file, o2.module, o2.lineno |
| 213 | self.assertEqual(t1, t2) |
| 214 | if type(o1) is mb.Class: |
| 215 | self.assertEqual(o1.methods, o2.methods) |
| 216 | # Skip superclasses for now as not part of example |
| 217 | compare(o1, o1.children, o2, o2.children) |
| 218 | |
| 219 | compare(None, actual, None, expected) |
| 220 | |
Fred Drake | 3a28ca8 | 2001-08-13 20:26:19 +0000 | [diff] [blame] | 221 | def test_others(self): |
| 222 | cm = self.checkModule |
| 223 | |
Guido van Rossum | 7f6a439 | 2002-12-03 08:16:50 +0000 | [diff] [blame] | 224 | # These were once about the 10 longest modules |
Raymond Hettinger | e401b6f | 2002-12-30 07:21:32 +0000 | [diff] [blame] | 225 | cm('random', ignore=('Random',)) # from _random import Random as CoreGenerator |
Guido van Rossum | 7f6a439 | 2002-12-03 08:16:50 +0000 | [diff] [blame] | 226 | cm('cgi', ignore=('log',)) # set with = in module |
Antoine Pitrou | 91f4380 | 2019-05-26 17:10:09 +0200 | [diff] [blame] | 227 | cm('pickle', ignore=('partial', 'PickleBuffer')) |
Brian Curtin | 9f914a0 | 2017-11-10 11:38:25 -0500 | [diff] [blame] | 228 | # TODO(briancurtin): openfp is deprecated as of 3.7. |
| 229 | # Update this once it has been removed. |
R David Murray | 4d35e75 | 2013-07-25 16:12:01 -0400 | [diff] [blame] | 230 | cm('aifc', ignore=('openfp', '_aifc_params')) # set with = in module |
Serhiy Storchaka | bd48d27 | 2016-09-11 12:50:02 +0300 | [diff] [blame] | 231 | cm('sre_parse', ignore=('dump', 'groups', 'pos')) # from sre_constants import *; property |
Guido van Rossum | 7f6a439 | 2002-12-03 08:16:50 +0000 | [diff] [blame] | 232 | cm('pdb') |
Serhiy Storchaka | bdf6b91 | 2017-03-19 08:40:32 +0200 | [diff] [blame] | 233 | cm('pydoc', ignore=('input', 'output',)) # properties |
Fred Drake | 3a28ca8 | 2001-08-13 20:26:19 +0000 | [diff] [blame] | 234 | |
Guido van Rossum | 0ed7aa1 | 2002-12-02 14:54:20 +0000 | [diff] [blame] | 235 | # Tests for modules inside packages |
Neal Norwitz | 315d845 | 2007-08-30 03:06:59 +0000 | [diff] [blame] | 236 | cm('email.parser') |
Guido van Rossum | 7f6a439 | 2002-12-03 08:16:50 +0000 | [diff] [blame] | 237 | cm('test.test_pyclbr') |
Fred Drake | 3a28ca8 | 2001-08-13 20:26:19 +0000 | [diff] [blame] | 238 | |
Brett Cannon | 5086589 | 2019-03-22 15:16:50 -0700 | [diff] [blame] | 239 | |
| 240 | class ReadmoduleTests(TestCase): |
| 241 | |
| 242 | def setUp(self): |
| 243 | self._modules = pyclbr._modules.copy() |
| 244 | |
| 245 | def tearDown(self): |
| 246 | pyclbr._modules = self._modules |
| 247 | |
| 248 | |
| 249 | def test_dotted_name_not_a_package(self): |
Petri Lehtinen | 8d88604 | 2012-05-18 21:51:11 +0300 | [diff] [blame] | 250 | # test ImportError is raised when the first part of a dotted name is |
Brett Cannon | 5086589 | 2019-03-22 15:16:50 -0700 | [diff] [blame] | 251 | # not a package. |
| 252 | # |
| 253 | # Issue #14798. |
Petri Lehtinen | 8d88604 | 2012-05-18 21:51:11 +0300 | [diff] [blame] | 254 | self.assertRaises(ImportError, pyclbr.readmodule_ex, 'asyncore.foo') |
| 255 | |
Brett Cannon | 5086589 | 2019-03-22 15:16:50 -0700 | [diff] [blame] | 256 | def test_module_has_no_spec(self): |
| 257 | module_name = "doesnotexist" |
| 258 | assert module_name not in pyclbr._modules |
| 259 | with test_importlib_util.uncache(module_name): |
| 260 | with self.assertRaises(ModuleNotFoundError): |
| 261 | pyclbr.readmodule_ex(module_name) |
| 262 | |
Fred Drake | 2e2be37 | 2001-09-20 21:33:42 +0000 | [diff] [blame] | 263 | |
Fred Drake | 2e2be37 | 2001-09-20 21:33:42 +0000 | [diff] [blame] | 264 | if __name__ == "__main__": |
Zachary Ware | ac28b79 | 2015-12-04 23:32:23 -0600 | [diff] [blame] | 265 | unittest_main() |