Skip to content

Commit a65af18

Browse files
committed
fixes
1 parent a2ba0dc commit a65af18

File tree

9 files changed

+154
-42
lines changed

9 files changed

+154
-42
lines changed

python2_to_python3/guide.md

Lines changed: 0 additions & 39 deletions
This file was deleted.

python2_to_python3/run.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
from codegen import Codebase
33

44
# Initialize codebase
5-
codebase = Codebase("./")
65

76
# Define the target directory
87
TARGET_DIR = "input_repo"
@@ -151,4 +150,6 @@ def run():
151150

152151

153152
if __name__ == "__main__":
153+
codebase = Codebase("./")
154+
154155
run(codebase)

unittest_to_pytest/input_repo/jj_classes/__init__.py

Whitespace-only changes.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# jj_classes/castle.py
2+
3+
class Castle:
4+
"""Defines the Castle class."""
5+
6+
def __init__(self, name):
7+
"""Initialize the castle."""
8+
if not name:
9+
raise ValueError("Castle name cannot be empty.")
10+
self._name = name
11+
self._boss = "Bowser"
12+
self._world = "Grass Land"
13+
14+
def has_access(self, character):
15+
"""Check if a character has access to the castle."""
16+
return character.powerup == "Super Mushroom"
17+
18+
@property
19+
def name(self):
20+
return self._name
21+
22+
@property
23+
def boss(self):
24+
return self._boss
25+
26+
@property
27+
def world(self):
28+
return self._world
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# jj_classes/character.py
2+
3+
class Character:
4+
"""Defines the Character class."""
5+
6+
def __init__(self, name):
7+
"""Initialize the character."""
8+
if not name:
9+
raise ValueError("Character name cannot be empty.")
10+
self._name = name
11+
self._powerup = None
12+
13+
@property
14+
def name(self):
15+
return self._name
16+
17+
@property
18+
def powerup(self):
19+
return self._powerup
20+
21+
@powerup.setter
22+
def powerup(self, value):
23+
self._powerup = value
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# run_tests.py
2+
3+
import unittest
4+
5+
if __name__ == "__main__":
6+
loader = unittest.TestLoader()
7+
tests = loader.discover("tests")
8+
test_runner = unittest.TextTestRunner()
9+
test_runner.run(tests)

unittest_to_pytest/input_repo/tests/__init__.py

Whitespace-only changes.
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# tests/test_classes.py
2+
3+
import unittest
4+
from unittest.mock import Mock
5+
from jj_classes.castle import Castle
6+
from jj_classes.character import Character
7+
8+
9+
class TestCastle(unittest.TestCase):
10+
"""Tests for the Castle class."""
11+
12+
def setUp(self):
13+
"""Set up a test castle."""
14+
self.castle = Castle("Test Castle")
15+
16+
def test_castle_name(self):
17+
"""Test that the castle name is set correctly."""
18+
self.assertEqual(self.castle.name, "Test Castle")
19+
20+
def test_castle_boss(self):
21+
"""Test that the default boss is Bowser."""
22+
self.assertEqual(self.castle.boss, "Bowser")
23+
24+
def test_castle_world(self):
25+
"""Test that the default world is Grass Land."""
26+
self.assertEqual(self.castle.world, "Grass Land")
27+
28+
def test_has_access_granted(self):
29+
"""Test that access is granted for the correct powerup."""
30+
character = Mock(powerup="Super Mushroom")
31+
self.assertTrue(self.castle.has_access(character))
32+
33+
def test_has_access_denied(self):
34+
"""Test that access is denied for an incorrect powerup."""
35+
character = Mock(powerup="Starman")
36+
self.assertFalse(self.castle.has_access(character))
37+
38+
def test_empty_name_raises_error(self):
39+
"""Test that an empty castle name raises a ValueError."""
40+
with self.assertRaises(ValueError):
41+
Castle("")
42+
43+
44+
class TestCharacter(unittest.TestCase):
45+
"""Tests for the Character class."""
46+
47+
def setUp(self):
48+
"""Set up a test character."""
49+
self.character = Character("Mario")
50+
51+
def test_character_name(self):
52+
"""Test that the character name is set correctly."""
53+
self.assertEqual(self.character.name, "Mario")
54+
55+
def test_default_powerup(self):
56+
"""Test that the default powerup is None."""
57+
self.assertIsNone(self.character.powerup)
58+
59+
def test_set_powerup(self):
60+
"""Test setting a powerup."""
61+
self.character.powerup = "Fire Flower"
62+
self.assertEqual(self.character.powerup, "Fire Flower")
63+
64+
def test_empty_name_raises_error(self):
65+
"""Test that an empty character name raises a ValueError."""
66+
with self.assertRaises(ValueError):
67+
Character("")
68+
69+
70+
class TestCastleAndCharacter(unittest.TestCase):
71+
"""Tests for the interaction between Castle and Character."""
72+
73+
def setUp(self):
74+
"""Set up a test castle and character."""
75+
self.castle = Castle("Test Castle")
76+
self.character = Character("Mario")
77+
78+
def test_character_has_access(self):
79+
"""Test that a character with the correct powerup has access."""
80+
self.character.powerup = "Super Mushroom"
81+
self.assertTrue(self.castle.has_access(self.character))
82+
83+
def test_character_denied_access(self):
84+
"""Test that a character with the wrong powerup is denied access."""
85+
self.character.powerup = "Starman"
86+
self.assertFalse(self.castle.has_access(self.character))
87+
88+
89+
if __name__ == "__main__":
90+
unittest.main()

unittest_to_pytest/run.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22
from codegen import Codebase
33

44
# Initialize codebase
5-
codebase = Codebase("./")
65

76
# Define the target directory
8-
TARGET_DIR = "repo-before/tests"
7+
TARGET_DIR = "input_repo/tests"
98

109

1110
def remove_unittest_inheritance(file):
@@ -78,4 +77,5 @@ def run(codebase: Codebase):
7877

7978

8079
if __name__ == "__main__":
80+
codebase = Codebase("./")
8181
run(codebase)

0 commit comments

Comments
 (0)