def _getScript(name='__main__'): module = sys.modules.get(name) # the syntax of doctest changed substantially between Python 2.3 and 2.4 # <http://sourceforge.net/tracker/index.php?func=detail&aid=1120348&group_id=118428&atid=681141> if sys.version_info >= (2, 4): # Python 2.4 returns comments, too, and doesn't always end in a \n, # which chokes exec/compile. Arguably a bug in Python. # <http://sourceforge.net/tracker/index.php?func=detail&aid=1172785&group_id=5470&atid=105470> return doctest.testsource(module, module.__name__) + '\n' else: return doctest.testsource(module, "")
def _getScript(name = '__main__'): module = sys.modules.get(name) # the syntax of doctest changed substantially between Python 2.3 and 2.4 # <http://sourceforge.net/tracker/index.php?func=detail&aid=1120348&group_id=118428&atid=681141> if sys.version_info >= (2, 4): # Python 2.4 returns comments, too, and doesn't always end in a \n, # which chokes exec/compile. Arguably a bug in Python. # <http://sourceforge.net/tracker/index.php?func=detail&aid=1172785&group_id=5470&atid=105470> return doctest.testsource(module, module.__name__) + '\n' else: return doctest.testsource(module, "")
# Adversarial Loss L_adv = objectives.binary_crossentropy(y_true_flat, y_pred_flat) # A to B loss b_flat = K.batch_flatten(b) bp_flat = K.batch_flatten(bp) if is_b_binary: L_atob = objectives.binary_crossentropy(b_flat, bp_flat) else: L_atob = K.mean(K.abs(b_flat - bp_flat)) return L_adv + alpha * L_atob # This network is used to train the generator. Freeze the discriminator part. pix2pix.get_layer('d').trainable = False pix2pix.compile(optimizer=opt, loss=pix2pix_loss) return pix2pix if __name__ == '__main__': import doctest TEST_TF = True if TEST_TF: os.environ['KERAS_BACKEND'] = 'tensorflow' else: os.environ['KERAS_BACKEND'] = 'theano' doctest.testsource('models.py', verbose=True, optionflags=doctest.ELLIPSIS)
def testPydoc(self): doctest.testsource(nemoc, "nemoc.render")
# Python Doctest API # The doctest module searches for pieces of text that look like interactive Python sessions, and then executes those sessions to verify that they work # exactly as shown. # # There are several common ways to use doctest: # > To check that a module’s docstrings are up-to-date by verifying that all interactive examples still work as documented. # > To perform regression testing by verifying that interactive examples from a test file or a test object work as expected. # > To write tutorial documentation for a package, liberally illustrated with input-output examples. # Depending on whether the examples or the expository text are emphasized, this has the flavor of “literate testing” or “executable documentation”. # # doctest.testsource(module, name): # Convert the doctest for an object to a script. # # # Argument module is a module object, or dotted name of a module, containing the object whose doctests are of interest. # Argument name is the name (within the module) of the object with the doctests of interest. # The result is a string, containing the object’s docstring converted to a Python script, as described for script_from_examples() above. # # For example, if module a.py contains a top-level function f(), then # import a, doctest print(doctest.testsource(a, "a.f")) # # prints a script version of function f()’s docstring, with doctests converted to code, and the rest placed in comments. #
def update_event(self, inp=-1): self.set_output_val(0, doctest.testsource(self.input(0), self.input(1)))