From e4d35ecd85a5ab22ccf9f2e17902e012af9160cc Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Sun, 2 Sep 2018 04:41:53 -0400 Subject: [PATCH] major updates --- .gitignore | 2 ++ .pytest_cache/README.md | 8 ++++++ Pipfile | 1 + Pipfile.lock | 59 +++++++++++++++++++++++++++++++++++++++-- pytheory/core.py | 11 +++++--- test_pytheory.py | 23 ++++++++++++++++ 6 files changed, 99 insertions(+), 5 deletions(-) create mode 100644 .pytest_cache/README.md create mode 100644 test_pytheory.py diff --git a/.gitignore b/.gitignore index c6f9a44..6b758b2 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ .vscode/settings.json +.DS_Store +.pytest_cache diff --git a/.pytest_cache/README.md b/.pytest_cache/README.md new file mode 100644 index 0000000..bb78ba0 --- /dev/null +++ b/.pytest_cache/README.md @@ -0,0 +1,8 @@ +# pytest cache directory # + +This directory contains data from the pytest's cache plugin, +which provides the `--lf` and `--ff` options, as well as the `cache` fixture. + +**Do not** commit this to version control. + +See [the docs](https://docs.pytest.org/en/latest/cache.html) for more information. diff --git a/Pipfile b/Pipfile index 5749daf..b196f54 100644 --- a/Pipfile +++ b/Pipfile @@ -8,6 +8,7 @@ pytuning = "*" numeral = "*" [dev-packages] +pytest = "*" [requires] python_version = "3.7" diff --git a/Pipfile.lock b/Pipfile.lock index bc17570..55efc4c 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "ac018f7f051023c6003e48cdda8b169b48f7f81b587045089fee168037769851" + "sha256": "4fa838a86692773eb1959e2b6009ee6f324a3708bc8272e74983e24d30c0a963" }, "pipfile-spec": 6, "requires": { @@ -77,5 +77,60 @@ "version": "==1.2" } }, - "develop": {} + "develop": { + "atomicwrites": { + "hashes": [ + "sha256:0312ad34fcad8fac3704d441f7b317e50af620823353ec657a53e981f92920c0", + "sha256:ec9ae8adaae229e4f8446952d204a3e4b5fdd2d099f9be3aaf556120135fb3ee" + ], + "markers": "python_version != '3.2.*' and python_version != '3.3.*' and python_version != '3.1.*' and python_version != '3.0.*' and python_version >= '2.7'", + "version": "==1.2.1" + }, + "attrs": { + "hashes": [ + "sha256:10cbf6e27dbce8c30807caf056c8eb50917e0eaafe86347671b57254006c3e69", + "sha256:ca4be454458f9dec299268d472aaa5a11f67a4ff70093396e1ceae9c76cf4bbb" + ], + "version": "==18.2.0" + }, + "more-itertools": { + "hashes": [ + "sha256:c187a73da93e7a8acc0001572aebc7e3c69daf7bf6881a2cea10650bd4420092", + "sha256:c476b5d3a34e12d40130bc2f935028b5f636df8f372dc2c1c01dc19681b2039e", + "sha256:fcbfeaea0be121980e15bc97b3817b5202ca73d0eae185b4550cbfce2a3ebb3d" + ], + "version": "==4.3.0" + }, + "pluggy": { + "hashes": [ + "sha256:6e3836e39f4d36ae72840833db137f7b7d35105079aee6ec4a62d9f80d594dd1", + "sha256:95eb8364a4708392bae89035f45341871286a333f749c3141c20573d2b3876e1" + ], + "markers": "python_version != '3.2.*' and python_version != '3.3.*' and python_version != '3.1.*' and python_version != '3.0.*' and python_version >= '2.7'", + "version": "==0.7.1" + }, + "py": { + "hashes": [ + "sha256:06a30435d058473046be836d3fc4f27167fd84c45b99704f2fb5509ef61f9af1", + "sha256:50402e9d1c9005d759426988a492e0edaadb7f4e68bcddfea586bc7432d009c6" + ], + "markers": "python_version != '3.2.*' and python_version != '3.3.*' and python_version != '3.1.*' and python_version != '3.0.*' and python_version >= '2.7'", + "version": "==1.6.0" + }, + "pytest": { + "hashes": [ + "sha256:2d7c49e931316cc7d1638a3e5f54f5d7b4e5225972b3c9838f3584788d27f349", + "sha256:ad0c7db7b5d4081631e0155f5c61b80ad76ce148551aaafe3a718d65a7508b18" + ], + "index": "pypi", + "version": "==3.7.4" + }, + "six": { + "hashes": [ + "sha256:70e8a77beed4562e7f14fe23a786b54f6296e34344c23bc42f07b15018ff98e9", + "sha256:832dc0e10feb1aa2c68dcc57dbb658f1c7e65b9b61af69048abc87a2db00a0eb" + ], + "version": "==1.11.0" + } + } } diff --git a/pytheory/core.py b/pytheory/core.py index 86cb709..976701a 100644 --- a/pytheory/core.py +++ b/pytheory/core.py @@ -99,11 +99,15 @@ class Tone: f"Tone {self.name!r} was not found in system: {self.system.tones!r}" ) - def __repr__(self): + @property + def full_name(self): if self.octave: - return f"" + return f"{self.name}{self.octave}" else: - return f"" + return self.name + + def __repr__(self): + return f"" def __eq__(self, other): @@ -296,6 +300,7 @@ class System: if offset: scale = scale[offset - 1 :] + scale[: offset - 1] + # descending goes in meta? return {"intervals": scale, "hemitonic": hemitonic, "meta": {}} def __repr__(self): diff --git a/test_pytheory.py b/test_pytheory.py new file mode 100644 index 0000000..a80c915 --- /dev/null +++ b/test_pytheory.py @@ -0,0 +1,23 @@ +import pytest + +import pytheory +from pytheory import Tone, TonedScale, Tone + + +def test_tone_from_string(): + c4 = Tone.from_string("C4") + assert c4.name == "C" + assert c4.octave == 4 + + +def test_tone_initialization(): + c4 = Tone(name="C", octave=4) + assert c4.name == "C" + assert c4.octave == 4 + + +def test_tone_addition(): + assert ( + Tone.from_string("C4", system=pytheory.SYSTEMS["western"]).add(12).full_name + == "C5" + )