def test_init_invalid_name(): invalid = ['', 'a', 'a-', '-a', '!', 'ab!c'] for i in invalid: with pytest.raises(ValueError, match=r'invalid name ".*"'): args = Problem.default_args() args.name = i p = Problem(args)
def test_init_happy_path(): args = Problem.default_args() args.name = '3sum' p = Problem(args) # misc attributes assert (p._verbose == False) # leetcode attributes assert (p._name == args.name) assert (p._url == problem.LEETCODE_URL_BASE + '/' + args.name) # github attributes assert (p._issue == -1) # problem attributes #assert(p._leetcode_number == -1) assert (p._problem_template == '') assert (p._difficulty == Difficulty.INVALID) assert (p._time == -1) assert (p._time_rank == -1) assert (p._time_complexity == '') assert (p._space == -1) assert (p._space_rank == -1) assert (p._space_complexity == '')
def test_init_invalid_verbose(): invalid = [None, 42, 'Foo'] for i in invalid: with pytest.raises(ValueError, match=r'invalid verbosity ".*"'): args = Problem.default_args() args.name = 'abc' args.verbose = i p = Problem(args)
def test_checkout_branch(): try: git.branch('-D', 'issue/42/foo-bar') except: pass args = Problem.default_args() args.issue = 42 args.name = 'foo-bar' p = Problem(args) p.checkout_branch() actual_branch_name = '{}'.format(repo.active_branch) expected_branch_name = 'issue/{}/{}'.format(args.issue, args.name) git.checkout(initial_branch) try: git.branch('-D', expected_branch_name) except: pass assert (actual_branch_name == expected_branch_name)