Package: aurornis
Aurornis - A command line program test helperAurornis is a small, yet powerful library designed to help testing command line programs.
The name is a reference to theaurornis xui, a prehistoric bird that lived 10 million years ago.InstallationAurornis is available in PyPI, so all you need is to install it with PIP:pipinstall--useraurornisIf you are using Pipenv or Poetry, it is recommended to install it as a development dependency:pipenvinstall--devaurornis
poetryadd--devaurornisImportant note:this library has not been tested on a production environment. For security reasons, it recommended to use it for development tests only.
This might evolve in the future.Main featuresOne simple function: give it the command, and it will take care of all the complexity for youSupports the standard input, output and errorComputes the execution time of the command, so you can test its global performance directlyProvides a way to clean the colors to make testing simpler (with native support of theNO_COLORstandard)Supports Linux, macOS and Windows. Probably also works on FreeBSD.Basic usageAurornis provides a package with only one function to run a command, that returns an object with the result of the command:importaurorniscommand_result=aurornis.run(["ls","-la","/"])# <CommandResult command="ls -la /" return_code=0 stdout="total 68 ..." stderr="">For better security and reproducibility, the environment variables of your system are not reproduced, with the exception of$PATHon UNIX andSystemRooton Windows.If you need to specify environment variables (or even overwrite some of them) before you run the command, add them to therunfunction:importaurorniscommand_result=aurornis.run(["env"],environment={"HOME":"/home/deuchnord"})By default, theLANGenvironment variable (used for internationalization) is reset toC(default system language, commonly English). You can change it if you want to test with another locale.Once you get the result, all you need to do is to use your favorite unit test framework to check it returned what you expected it to return:importaurornisimportunittestclassCommandTest(unittest.TestCase):deftest_ls_home(self):command_result=aurornis.run(["ls","-l","$HOME"],environment={"HOME":"/home/deuchnord"})# You can check quickly the command was successful:self.assertTrue(command_result.successful)# Or if you expected a more specific return value:self.assertEqual(2,command_result.return_code)# ls returns 2 if the file does not exist# Then, check the text returned in standard output and standard error:self.assertEqual("""total 6drwxr-xr-x 1 deuchnord deuchnord 40 27 May 13:19 Desktopdrwxr-xr-x 1 deuchnord deuchnord 40 14 Oct 18:08 Documentsdrwxr-xr-x 1 deuchnord deuchnord 40  1 Sep 16:52 Downloadsdrwxr-xr-x 1 deuchnord deuchnord 40 29 Sep 09:11 Picturesdrwxr-xr-x 1 deuchnord deuchnord 40 11 Jun  2020 Musicdrwxr-xr-x 1 deuchnord deuchnord 40 10 Nov 11:32 Videos""",command_result.stdout)self.assertEqual("",command_result.stderr)If your command returns colors in your standard output or standard error, you can ask Aurornis to automatically remove them:importaurornisaurornis.run(["echo","-e",r'\e[0;32mHello World!\e[0m'],remove_colors=True)This option also automatically setsthe standardNO_COLORenvironment variable. If your application shows colors, you may want to handle this environment variable to facilitate their deactivation by end users.FAQ/TroubleshootingHow to handle correctly the return lines when my tests are executed on both Windows and non-Windows systems?Therun()function provides a way to handle it for you.
Just set thenormalize_carriage_returnargument toTrue, and any\r\nwill be replaced with\n.
This will become the default behavior in the version 2.0.