Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mschwager/memunit
A testing library for ensuring memory usage levels in Python.
https://github.com/mschwager/memunit
memory profiler python ram test testing unit-test unittest
Last synced: about 22 hours ago
JSON representation
A testing library for ensuring memory usage levels in Python.
- Host: GitHub
- URL: https://github.com/mschwager/memunit
- Owner: mschwager
- License: gpl-3.0
- Created: 2017-09-12T21:38:51.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2020-12-04T17:15:54.000Z (almost 4 years ago)
- Last Synced: 2024-10-31T20:40:58.159Z (7 days ago)
- Topics: memory, profiler, python, ram, test, testing, unit-test, unittest
- Language: Python
- Size: 22.5 KB
- Stars: 37
- Watchers: 5
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Memunit
[![Build Status](https://travis-ci.org/mschwager/memunit.svg?branch=master)](https://travis-ci.org/mschwager/memunit)
[![Coverage Status](https://coveralls.io/repos/github/mschwager/memunit/badge.svg?branch=master)](https://coveralls.io/github/mschwager/memunit?branch=master)
[![Python Versions](https://img.shields.io/pypi/pyversions/memunit.svg)](https://img.shields.io/pypi/pyversions/memunit.svg)
[![PyPI Version](https://img.shields.io/pypi/v/memunit.svg)](https://img.shields.io/pypi/v/memunit.svg)`Memunit` is a testing library for ensuring memory usage levels in Python.
# Installing
```
$ pip install memunit
```# Using
`Memunit` can easily be added to existing tests via a decorator:
```python
#!/usr/bin/env pythonimport unittest
import memunit
class TestMemunit(unittest.TestCase):
@memunit.assert_lt_mb(35)
def test_low_memory_usage(self):
data = [str(i) for i in range(10)]self.assertTrue(data)
@memunit.assert_lt_mb(35)
def test_high_memory_usage(self):
data = [str(i) for i in range(100000)]self.assertTrue(data)
if __name__ == "__main__":
unittest.main()
```Code with poor memory performance can be protected against:
```
$ python profile.py
E.
======================================================================
ERROR: test_high_memory_usage (__main__.TestMemunit)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/matt/documents/memunit/lib/memunit.py", line 27, in wrapper
raise MemoryUsageException(failure_message.format(max_usage))
MemoryUsageException: Max usage 39.88Mb >= 35Mb----------------------------------------------------------------------
Ran 2 tests in 0.108sFAILED (errors=1)
````memunit.assert_mb` can be used to determine a memory usage baseline:
```
======================================================================
ERROR: test_memory_usage (__main__.TestMemunit)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/matt/documents/memunit/lib/memunit.py", line 27, in wrapper
raise MemoryUsageException(failure_message.format(max_usage))
MemoryUsageException: Max usage 40.14----------------------------------------------------------------------
Ran 1 test in 0.072sFAILED (errors=1)
```# Developing
First, clone the repository and install the required packages:
```
$ git clone https://github.com/mschwager/memunit.git
$ cd memunit
$ pip install -r requirements.txt
$ pip install -r requirements-dev.txt
```## Testing
```
$ nose2 --with-coverage
```## Linting
```
$ flake8
```