background preloader

Test-Driven Development with Python

Test-Driven Development with Python
Test-Driven Development with Python Test-Driven Development with Python Harry Percival Gillian McGarvey Rebecca Demarest Wendy Catalano Randy Comer David Futato Copyright © 2014 Harry Percival Printed in the United States of America. O’Reilly books may be purchased for educational, business, or sales promotional use. Nutshell Handbook, the Nutshell Handbook logo, and the O’Reilly logo are registered trademarks of O’Reilly Media, Inc. Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. While every precaution has been taken in the preparation of this book, the publisher and authors assume no responsibility for errors or omissions, or for damages resulting from the use of the information contained herein. Praise for Test-Driven Development with Python Table of Contents © 2013, O’Reilly Media, Inc. Related:  DevOps

Making good use of random in your python unit tests Writing efficient UnitTest to validate that your code performs as expected is a difficult endeavor. Lot has been written about the benefits of Test Driven development and on how to best approach testing, and lot can be learned reading the available litterature. One thing however that we don’t see often mentionned is that architecting efficient UnitTest is pretty hard and that no tools or testing framework are of much value without a fair understanding of the code base that needs to be tested. The techniques we will be briefly introducing now are no different. You may use them to impress your colleagues and show them TestSuite you have just written that contains millions of tests. Basic idea Assumes you wish to provide tests for an hypothetical func_to_test that looks like so : def func_to_test(x, y): ... return result To proceed with unit testing func_to_test, our first goal is to generate values that optimally covers the expected domain. Be repeatable TestCase factories

1.3. A Quick Tour — Buildbot 0.9.12 documentation 1.3.1. Goal This tutorial will expand on the First Run tutorial by taking a quick tour around some of the features of buildbot that are hinted at in the comments in the sample configuration. As a part of this tutorial, we will make buildbot do a few actual builds. This section will teach you how to: make simple configuration changes and activate themdeal with configuration errorsforce buildsenable and control the IRC botenable ssh debuggingadd a ‘try’ scheduler 1.3.2. Let’s start simple by looking at where you would customize the buildbot’s project name and URL. We continue where we left off in the First Run tutorial. Open a new terminal, and first enter the same sandbox you created before (where $EDITOR is your editor of choice like vim, gedit, or emacs): cd ~/tmp/bb-master source sandbox/bin/activate $EDITOR master/master.cfg Now, look for the section marked PROJECT IDENTITY which reads: After making a change go into the terminal and type: 1.3.3. This creates a Python SyntaxError. 1.3.4. Note

Text Processing in Python (a book) A couple of you make donations each month (out of about a thousand of you reading the text each week). Tragedy of the commons and all that... but if some more of you would donate a few bucks, that would be great support of the author. In a community spirit (and with permission of my publisher), I am making my book available to the Python community. Minor corrections can be made to later printings, and at the least errata noted on this website. A few caveats: (1) This stuff is copyrighted by AW (except the code samples which are released to the public domain).

An Extended Introduction to the nose Unit Testing Framework Welcome! This is an introduction, with lots and lots of examples, to the nose unit test discovery & execution framework. If that's not what you want to read, I suggest you hit the Back button now. The latest version of this document can be found at (Last modified October 2006.) A unit test is an automated code-level test for a small "unit" of functionality. (There's lots of discussion on whether unit tests should do things like access external resources, and whether or not they are still "unit" tests if they do. Unit tests are almost always pretty simple, by intent; for example, if you wanted to test an (intentionally naive) regular expression for validating the form of e-mail addresses, your test might look something like this: EMAIL_REGEXP = r'[\S.] There are a couple of ways to integrate unit tests into your development style. It's pretty common to write tests for a library module like so: "Why use nose in particular?" First, install nose.

Continuous Integration - Full Stack Python Continuous integration automates the building, testing and deploying of applications. Software projects, whether created by a single individual or entire teams, typically use continuous integration as a hub to ensure important steps such as unit testing are automated rather than manual processes. Why is continuous integration important? When continuous integration (CI) is established as a step in a software project's development process it can dramatically reduce deployment times by minimizing steps that require human intervention. Automated testing Another major advantage with CI is that testing can be an automated step in the deployment process. The automated testing on checked in source code can be thought of like the bumper guards in bowling that prevent code quality from going too far off track. Continuous integration example The following picture represents a high level perspective on how continuous integration and deployment can work. Open source CI projects Jenkins CI resources

introduction to python - Random stream This is the material which I use for teaching python to beginners. tld;dr: Very minimal explanation more code. Python? Interpreted languageMultiparadigm Introduction hasgeek@hasgeek-MacBook:~/codes/python/hacknight$ python Python 2.7.3 (default, Aug 1 2012, 05:14:39) [GCC 4.6.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> >>> print "Let's learn Python" Let's learn Python Numbers Expressions >>> 3 < 2 False >>> 3 > 2 True >>> 3 > 2 < 1 False >>> (3 > 2) and (2 < 1) False >>> 3 > 2 > 1 > 0 True >>> (3 > 2) and (2 > 1) and (1 > 0) True >>> 1 or 2 1 >>> 2 or 1 2 >>> 1 + 2 + 3 * 4 + 5 20 1 + 2 + 3 * 4 + 5 ↓ 3 + 3 * 4 + 5 ↓ 3 + 12 + 5 ↓ 15 + 5 ↓ 20 >>> "python" > "perl" True >>> "python" > "java" True Variables >>> a = 23 >>> print a 23 >>> a = "Python" >>> print a Python Guess the output True = False False = True print True, False print 2 > 3 Parallel Assignment z, y = 23, z + 23 a, b = 23, 12, 20 a = 1, 2 Swap Variable String Guess output Condition Data Structure List

New and Improved Coming changes to unittest in Python 2.7 & 3.2 The Pycon Testing Goat. unittest is the Python standard library testing framework. It is sometimes known as PyUnit and has a rich heritage as part of the xUnit family of testing libraries. Python has the best testing infrastructure available of any of the major programming languages, but by virtue of being included in the standard library unittest is the most widely used Python testing framework. unittest has languished whilst other Python testing frameworks have innovated. This article will go through the major changes, like the new assert methods, test discovery and the load_tests protocol, and also explain how they can be used with earlier versions of Python. The new features are documented in the Python 2.7 development documentation at: An important thing to note is that this is evolution not revolution, backwards compatibility is important. And even more... addTypeEqualityFunc(type, function)

What's in a transport layer? Microservices are small programs, each with a specific and narrow scope, that are glued together to produce what appears from the outside to be one coherent web application. This architectural style is used in contrast with a traditional "monolith" where every component and sub-routine of the application is bundled into one codebase and not separated by a network boundary. In recent years microservices have enjoyed increased popularity, concurrent with (but not necessarily requiring the use of) enabling new technologies such as Amazon Web Services and Docker. In this article, we will take a look at the "what" and "why" of microservices and at gRPC, an open source framework released by Google, which is a tool organizations are increasingly reaching for in their migration towards microservices. Why Use Microservices? To understand the general history and structure of microservices emerging as an architectural pattern, this Martin Fowler article is a good and fairly comprehensive read.

gregmalcolm/python_koans · GitHub