Skip to content

Commit

Permalink
#22 | add tests for short param
Browse files Browse the repository at this point in the history
  • Loading branch information
mxndtaylor committed Jun 10, 2024
1 parent f201d40 commit d2d5d36
Showing 1 changed file with 74 additions and 1 deletion.
75 changes: 74 additions & 1 deletion tests/virtual_alias_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import pytest

from aliasing import TrampleAliasWarning, TrampleAliasError, valiases
from aliasing import TrampleAliasWarning, TrampleAliasError, valiases, auto_alias


class VirtualAliasTest:
Expand Down Expand Up @@ -83,3 +83,76 @@ def method2(self): ...
" method1 by default, pass `trample_ok=['method2']` to override "
"the member anyway."
)


def test_auto_alias_short_bool():
val = "my testing val 123"

class AutoAliasTest:
@auto_alias(short=True)
def method(self):
return val

tester = AutoAliasTest()
assert val == tester.method()

agg = ''
for char in 'method':
agg += char
assert tester.method.__code__ is getattr(tester, agg).__code__
assert tester.method() == getattr(tester, agg)()


def test_auto_alias_short_int():
val = "my testing val 123"

class AutoAliasTest:
@auto_alias(short=3)
def method(self):
return val

@auto_alias(short=2)
def proc(self):
return val + val

tester = AutoAliasTest()
assert val == tester.method()
assert val + val == tester.proc()

agg = ''
for char in 'met':
agg += char
assert tester.method.__code__ is getattr(tester, agg).__code__
assert tester.method() == getattr(tester, agg)()

agg = ''
for char in 'pr':
agg += char
assert tester.proc.__code__ is getattr(tester, agg).__code__
assert tester.proc() == getattr(tester, agg)()


def test_auto_alias_short_list_ints():
val = "my testing val 123"

class AutoAliasTest:
@auto_alias(short=[1, 4])
def method(self):
return val

@auto_alias(short=[2, 3])
def proc(self):
return val + val

tester = AutoAliasTest()
assert val == tester.method()
assert val + val == tester.proc()

for agg in 'm', 'meth':
assert tester.method.__code__ is getattr(tester, agg).__code__
assert tester.method() == getattr(tester, agg)()

for agg in 'pr', 'pro':
assert tester.proc.__code__ is getattr(tester, agg).__code__
assert tester.proc() == getattr(tester, agg)()

0 comments on commit d2d5d36

Please sign in to comment.