mirror of
				https://github.com/KevinMidboe/tableprint.git
				synced 2025-10-29 18:00:16 +00:00 
			
		
		
		
	Adds the first test (for humantime)
This commit is contained in:
		
							
								
								
									
										6
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										6
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							| @@ -1,7 +1,4 @@ | ||||
| # Byte-compiled / optimized / DLL files | ||||
| *.pyc | ||||
|  | ||||
| # Distribution / packaging | ||||
| build/ | ||||
| dist/ | ||||
| lib/ | ||||
| @@ -10,6 +7,3 @@ lib64/ | ||||
| *.egg | ||||
| *.zip | ||||
| docs/_build | ||||
|  | ||||
| # PyCharm | ||||
| .idea/ | ||||
|   | ||||
							
								
								
									
										6
									
								
								Makefile
									
									
									
									
									
								
							
							
						
						
									
										6
									
								
								Makefile
									
									
									
									
									
								
							| @@ -7,6 +7,12 @@ develop: | ||||
| upload: | ||||
| 	python setup.py sdist bdist_wininst upload | ||||
|  | ||||
| test2: | ||||
| 	python2 /usr/local/bin/nosetests --logging-level=INFO | ||||
|  | ||||
| test: | ||||
| 	nosetests -v --with-coverage --cover-package=tableprint --logging-level=INFO | ||||
|  | ||||
| clean: | ||||
| 	rm -rf tableprint.egg-info | ||||
| 	rm -f *.pyc | ||||
|   | ||||
							
								
								
									
										14
									
								
								tests/test_headers.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								tests/test_headers.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,14 @@ | ||||
| # -*- coding: utf-8 -*- | ||||
| from __future__ import unicode_literals | ||||
| from tableprint import humantime | ||||
|  | ||||
| # def table(data, headers=None, format_spec=FMT, width=WIDTH, style=STYLE, out=sys.stdout): | ||||
| # def header(headers, width=WIDTH, style=STYLE, add_hr=True): | ||||
| # def row(values, width=WIDTH, format_spec=FMT, style=STYLE): | ||||
| # def hr(n, width=WIDTH, linestyle=LineStyle('|', '-', '+', '|')): | ||||
| # def top(n, width=WIDTH, style=STYLE): | ||||
| # def bottom(n, width=WIDTH, style=STYLE): | ||||
| # def banner(message, width=30, style='banner', out=sys.stdout): | ||||
| # def dataframe(df, **kwargs): | ||||
| # def humantime(t): | ||||
| # def _format_line(data, linestyle): | ||||
							
								
								
									
										29
									
								
								tests/test_utils.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										29
									
								
								tests/test_utils.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,29 @@ | ||||
| # -*- coding: utf-8 -*- | ||||
| from __future__ import unicode_literals | ||||
| from tableprint import humantime | ||||
| import pytest | ||||
|  | ||||
|  | ||||
| def test_humantime(): | ||||
|  | ||||
|     # test numeric input | ||||
|     assert humantime(1e6) == u'1 weeks, 4 days, 13 hours, 46 min., 40 s' | ||||
|     assert humantime(2e5) == u'2 days, 7 hours, 33 min., 20 s' | ||||
|     assert humantime(5e3) == u'1 hours, 23 min., 20 s' | ||||
|     assert humantime(60) == u'1 min., 0 s' | ||||
|     assert humantime(1) == u'1 s' | ||||
|     assert humantime(0) == u'0 s' | ||||
|     assert humantime(0.1) == u'100 ms' | ||||
|     assert humantime(0.005) == u'5 ms' | ||||
|     assert humantime(1e-5) == u'10 μs' | ||||
|     assert humantime(5.25e-4) == u'525 μs' | ||||
|     assert humantime(5e-7) == u'500 ns' | ||||
|     assert humantime(1e-12) == u'0.001 ns' | ||||
|  | ||||
|     # test non-numeric input | ||||
|     for val in ('abc', [], {'x': 5}): | ||||
|  | ||||
|         with pytest.raises(ValueError) as context: | ||||
|             humantime(val) | ||||
|  | ||||
|         assert 'Input must be numeric' in str(context.value) | ||||
		Reference in New Issue
	
	Block a user