def test_Get(self): for count in range(1, 4): for name, interval in Accidental.Accidentals.items(): if not name: continue with self.subTest(accidenta=name, count=count): self.assertEqual(Accidental.Get(name * count), interval * count)
def Get(cls, name): if isinstance(name, int): return cls.__GetDegree(name) if not (isinstance(name, str)): raise TypeError('引数nameはstr型かint型にしてください。') d, a = cls.__Split(name) degree = cls.__GetDegree(int(d)) accidental = Accidental.Get(a) return degree + accidental
def Get(cls, name: str): if not (isinstance(name, str)): raise TypeError('引数nameはstr型にしてください。') if isinstance(name, int): return cls.__GetDegree(name) k, a = cls.__Split(name) key = cls.__GetKeyHalfToneNum(k) accidental = Accidental.Get(a) return key + accidental
def test_Get_Valid_NotSameChars(self): with self.assertRaises(ValueError) as e: Accidental.Get('+-') self.assertIn('引数accidentalは同じ文字のみ連続使用を許されます。異なる文字を混在させることはできません。', str(e.exception))
def test_Get_Invalid(self): with self.assertRaises(ValueError) as e: Accidental.Get('無無無') self.assertIn('引数accidentalに使える文字は次のものだけです。', str(e.exception))
def test_Get_int(self): with self.assertRaises(TypeError) as e: Accidental.Get(100) self.assertIn('引数accidentalは文字列型にしてください。', str(e.exception))
def test_Get_Blank(self): self.assertEqual(Accidental.Get(''), 0)
def test_Get_None(self): self.assertEqual(Accidental.Get(None), 0)