{"id":13501726,"url":"https://github.com/mschwager/memunit","last_synced_at":"2025-04-10T23:30:41.093Z","repository":{"id":146382492,"uuid":"103323039","full_name":"mschwager/memunit","owner":"mschwager","description":"A testing library for ensuring memory usage levels in Python.","archived":false,"fork":false,"pushed_at":"2020-12-04T17:15:54.000Z","size":23,"stargazers_count":37,"open_issues_count":0,"forks_count":1,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-10-31T20:40:58.159Z","etag":null,"topics":["memory","profiler","python","ram","test","testing","unit-test","unittest"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mschwager.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2017-09-12T21:38:51.000Z","updated_at":"2024-06-04T15:09:56.000Z","dependencies_parsed_at":"2024-01-16T10:37:25.448Z","dependency_job_id":"ba09a439-c8e1-4a9d-876b-411e65b2a742","html_url":"https://github.com/mschwager/memunit","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mschwager%2Fmemunit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mschwager%2Fmemunit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mschwager%2Fmemunit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mschwager%2Fmemunit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mschwager","download_url":"https://codeload.github.com/mschwager/memunit/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223449748,"owners_count":17146984,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["memory","profiler","python","ram","test","testing","unit-test","unittest"],"created_at":"2024-07-31T22:01:47.631Z","updated_at":"2024-11-07T03:14:00.608Z","avatar_url":"https://github.com/mschwager.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"# Memunit\n\n[![Build Status](https://travis-ci.org/mschwager/memunit.svg?branch=master)](https://travis-ci.org/mschwager/memunit)\n[![Coverage Status](https://coveralls.io/repos/github/mschwager/memunit/badge.svg?branch=master)](https://coveralls.io/github/mschwager/memunit?branch=master)\n[![Python Versions](https://img.shields.io/pypi/pyversions/memunit.svg)](https://img.shields.io/pypi/pyversions/memunit.svg)\n[![PyPI Version](https://img.shields.io/pypi/v/memunit.svg)](https://img.shields.io/pypi/v/memunit.svg)\n\n`Memunit` is a testing library for ensuring memory usage levels in Python.\n\n# Installing\n\n```\n$ pip install memunit\n```\n\n# Using\n\n`Memunit` can easily be added to existing tests via a decorator:\n\n```python\n#!/usr/bin/env python\n\nimport unittest\n\nimport memunit\n\n\nclass TestMemunit(unittest.TestCase):\n\n    @memunit.assert_lt_mb(35)\n    def test_low_memory_usage(self):\n        data = [str(i) for i in range(10)]\n\n        self.assertTrue(data)\n\n    @memunit.assert_lt_mb(35)\n    def test_high_memory_usage(self):\n        data = [str(i) for i in range(100000)]\n\n        self.assertTrue(data)\n\n\nif __name__ == \"__main__\":\n    unittest.main()\n```\n\nCode with poor memory performance can be protected against:\n\n```\n$ python profile.py\nE.\n======================================================================\nERROR: test_high_memory_usage (__main__.TestMemunit)\n----------------------------------------------------------------------\nTraceback (most recent call last):\n  File \"/home/matt/documents/memunit/lib/memunit.py\", line 27, in wrapper\n    raise MemoryUsageException(failure_message.format(max_usage))\nMemoryUsageException: Max usage 39.88Mb \u003e= 35Mb\n\n----------------------------------------------------------------------\nRan 2 tests in 0.108s\n\nFAILED (errors=1)\n```\n\n`memunit.assert_mb` can be used to determine a memory usage baseline:\n\n```\n======================================================================\nERROR: test_memory_usage (__main__.TestMemunit)\n----------------------------------------------------------------------\nTraceback (most recent call last):\n  File \"/home/matt/documents/memunit/lib/memunit.py\", line 27, in wrapper\n    raise MemoryUsageException(failure_message.format(max_usage))\nMemoryUsageException: Max usage 40.14\n\n----------------------------------------------------------------------\nRan 1 test in 0.072s\n\nFAILED (errors=1)\n```\n\n# Developing\n\nFirst, clone the repository and install the required packages:\n\n```\n$ git clone https://github.com/mschwager/memunit.git\n$ cd memunit\n$ pip install -r requirements.txt\n$ pip install -r requirements-dev.txt\n```\n\n## Testing\n\n```\n$ nose2 --with-coverage\n```\n\n## Linting\n\n```\n$ flake8\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmschwager%2Fmemunit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmschwager%2Fmemunit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmschwager%2Fmemunit/lists"}