17 Commits

Author SHA1 Message Date
Jon Grace-Cox
af9d06f5b0 test: Add escaping tests 2025-01-11 14:56:19 -08:00
Jon Grace-Cox
575833bf19 test: Ensure tests run against correct version
Update the `inv --test.local` command to ensure that tests are run against
the correct version of the package. The invoke command has been updated to:

- Ensure the `anybadge` command is not available on the system to start with

- Ensure `pip` is available

- Pip install the local project

- Run tests

- Pip uninstall `anybadge`

The net result is that invoke will be more robust in terms of making sure the
installed version is in sync when running CLI tests.
2025-01-11 14:56:19 -08:00
Jon Grace-Cox
9d4470a1a0 Allow badges with no value or no label (#89)
This commit allows badges to be generated with only a label or only
a value.

Badges must provide at least a label or a value, so it is not valid
to create a badge with no label and no value. This will result in
a `ValueError` being raised.
2024-12-30 06:53:33 -05:00
Jannis Mainczyk
2bd52f41cd anybadge cli accessible via python -m (#79)
* anybadge cli can be called via python -m

* fix: anybadge should be shown in cli usage string

* also allow executing anybadge.server as module

* test: same output regardless of how cli is called
2022-08-24 15:08:08 -04:00
Jon Grace-Cox
1c986d4ad8 Add package testing to CI (#68)
* Make `build_examples.py` callable from python
* Allow tests to run from outside project directory
* Add invoke tasks
* Add server tests
* Run travis tests against wheel package instead of local code
* Update `badge.write_badge()` to support `pathlib.Path`
* Update `CONTRIBUTING.md`
2022-08-13 13:22:15 -04:00
Jon Grace-Cox
8a434d95b5 Drop <3.7 support and add type hints (#59)
- Drop support for Python <3.7
- Bump the pre-commit version used in CI
- Add type hinting and docstrings
- Add mypy to pre-commit config
- Fix typing issues
- Update colors module
  - Update colors module to use uppercase hex codes
  - Add `__lt__` to allow sorting colors by name
- Fix `build_examples.py` to work with color Enum
- Update example badges in `README.md`
- Fix typing issues in server
- Update travis links in `README.md`
- Fix PyPi deployment bug (#60)
2022-08-08 23:19:50 -04:00
Jon Grace-Cox
f16867114a Add pre-commit config and apply changes (#54)
- Add .pre-commit-config.yaml with initial config.
- Add python black pre-commit config
- Apply pre-commit code changes
- Add information to CONTRIBUTING.md
- Add pre-commit to build requirements
- Run pre-commit during travis CI build
- Use a travis build matrix to control when pre-commit runs
  in the CI process. Use explicit include to only run
  pre-commit on Python 3.9.
2022-08-08 19:02:02 -04:00
Jon Grace-Cox
b6ca345ebe Drop py27 support and refactor (#51) (#52)
Python version support
======================
- Drop Python 2.7 support
- Add testing for Python 3.4 and 3.9
- Set python version requirements in setup.py

Package changes
===============
- Split module up into a package with submodules
- Break templates out into package resources
- Incorporate server into same package
- Use Enum for colors
- Refresh example badges
- Simplify documentation - Remove cli options and python api
  documentation from the README as it is hard to maintain, and
  often goes out-of-date
- Add CONTRIBUTING.md
2022-03-10 07:26:46 -05:00
Karthikeyan Singaravelan
17b4addc37 Use assertRaisesRegex for Python 3.11 compatibility (#48)
Use `assertRaisesRegex` instead of `assertRaisesRegexp` for Python 3.11 compatibility.
2021-11-09 10:49:24 -05:00
Jon Grace-Cox
a5ff4f0dfe Add semantic version support (#45) (#46)
Allow value and thresholds to be interpreted as semantic version numbers
by passing --semver (cli) or semver=True (python).

Add docs, unittests, import error handling, cli updates, requirements updates.
2021-05-25 18:22:43 -04:00
Jon Grace-Cox
aeedfbb93d Fix padding issues (#38)
* Set default padding chars to 0.5.
* Split num_padding_chars into num_label_padding_chars and num_value_padding_chars
  to allow better control. Retain num_padding_chars as an input parameter, but
  internally it is dropped.
* Remove padding multipliers.
* Add measurements image for developers. Helps show what each of the internal
  measurements are.
* Add script to build example badges.
* Update example badges.

Reliability
=======

* Raise a value error if an invalid font is passed.
* Handle labels that are not passed as str.
* Raise a value error if an invalid color name is passed.

Testing
=======

* Expand doctests to increase test coverage.
* Add Arial size 11 font and extra font sizes (mainly for testing).
* Make parse_args and main more testable by taking args as an input parameter.
* Use useful badge text in unittest badges.
* Add template svg file for testing.
* Add HTML coverage generation to travis yaml.
2020-03-15 12:51:34 -04:00
Jon Grace-Cox
fdf66043a0 Add unittest to validate handling of float values with .00 (#29) 2019-07-16 17:48:24 -04:00
Jon Grace-Cox
aebea09340 Fix int and float value detection (#26)
* Fix int and float value detection (Closes #25)
* Fix badge_width doctest
* Ignore all svg files across the whole project.  This is mainly to prevent
  accidentally adding them after tests run.
2019-07-11 21:43:48 -04:00
Jon Grace-Cox
3d24ecba0f Use different SVG mask ids for each generated badge
Within a single Python session anybadge will use different SVG mask IDs.
This is an attempt to fix the issue where SVG files displayed in the same
HTML will re-use the same mask, and therefore appear with the same dimensions.

Uses a singleton on the class to maintain a sequence of mask ids.

Includes unittests to ensure new ID is used for each badge.
2019-06-01 23:49:13 -04:00
Jon Grace-Cox
4bdb6dcdab Add repr and str dunder functions
* Add __repr__ function that prints the object representation.
* Add __str__ function that prints the Badge SVG text.

Also:
* Add constructor args to the Badge class docstring.
* Change the way defaults are used in the Badge constuctor.  Instead of
  setting values, use None and set arguments to the default values inside
  the constructor.
* Fix unittests that don't use overwrite=True.
2019-06-01 23:15:13 -04:00
Jon Grace-Cox
cc8dd5ac96 Add threshold and text color unittests 2019-06-01 03:38:41 -04:00
Jon Grace-Cox
1532cc247e Add more accurate width calculations for truetype fonts
* Use a better estimation technique to guess text widths.
* Add unittests for validating badge widths for various size badges.
* Add return types to function docstrings.
* Update relevant doctests.
2019-06-01 03:38:34 -04:00