Skip to content

Commit

Permalink
Merge pull request #34 from BlackSound1/test/simplify-tests
Browse files Browse the repository at this point in the history
Simplify tests
  • Loading branch information
BlackSound1 authored May 1, 2024
2 parents 38a0f4e + 3ce01fa commit bd8408d
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 140 deletions.
6 changes: 3 additions & 3 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

56 changes: 19 additions & 37 deletions tests/test_clicks.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,44 +24,26 @@ async def test_clicks(self):
:return: None
"""

async with self.monitor_app.run_test() as pilot:

# Test clicking the processes pane
await pilot.click("#processes")
self.assertIs(type(self.monitor_app.screen), ProcessesScreen)
self.assertEqual(self.monitor_app.screen.BORDER_TITLE, "Processes")
await pilot.press("p")
self.assertIs(type(self.monitor_app.screen), MainScreen)
# Define the screens to be tested
SCREENS = [
("#processes", ProcessesScreen, "Processes", 'p'),
("#drives", DriveScreen, "Drive Usage", 'd'),
("#mem", MemoryScreen, "Memory", 'm'),
("#cpu", CPU_Screen, "CPU Usage", 'c'),
("#network", NetworkScreen, "Network", 'n'),
("#gpu", GPU_Screen, "GPU Info", 'v')
]

# Test clicking the drives pane
await pilot.click("#drives")
self.assertIs(type(self.monitor_app.screen), DriveScreen)
self.assertEqual(self.monitor_app.screen.BORDER_TITLE, "Drive Usage")
await pilot.press("d")
self.assertIs(type(self.monitor_app.screen), MainScreen)

# Test clicking the memory pane
await pilot.click("#mem")
self.assertIs(type(self.monitor_app.screen), MemoryScreen)
self.assertEqual(self.monitor_app.screen.BORDER_TITLE, "Memory")
await pilot.press("m")
self.assertIs(type(self.monitor_app.screen), MainScreen)
async with self.monitor_app.run_test() as pilot:

# Test clicking the CPU pane
await pilot.click("#cpu")
self.assertIs(type(self.monitor_app.screen), CPU_Screen)
self.assertEqual(self.monitor_app.screen.BORDER_TITLE, "CPU Usage")
await pilot.press("c")
self.assertIs(type(self.monitor_app.screen), MainScreen)
# Iterate over each screen
for screen_class, screen_type, screen_title, screen_key in SCREENS:

# Test clicking the network pane
await pilot.click("#network")
self.assertIs(type(self.monitor_app.screen), NetworkScreen)
self.assertEqual(self.monitor_app.screen.BORDER_TITLE, "Network")
await pilot.press("n")
self.assertIs(type(self.monitor_app.screen), MainScreen)
# Click on the screen and assert that we are on the correct screen
await pilot.click(screen_class)
self.assertIs(type(self.monitor_app.screen), screen_type)
self.assertEqual(self.monitor_app.screen.BORDER_TITLE, screen_title)

# Test clicking the GPU pane
await pilot.click("#gpu")
self.assertIs(type(self.monitor_app.screen), GPU_Screen)
self.assertEqual(self.monitor_app.screen.BORDER_TITLE, "GPU Info")
# Press the key to go back to the main screen and assert that we are on the main screen
await pilot.press(screen_key)
self.assertIs(type(self.monitor_app.screen), MainScreen)
156 changes: 56 additions & 100 deletions tests/test_keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,79 +26,33 @@ async def test_keys_main(self):
:return: None
"""

async with self.monitor_app.run_test() as pilot:
# Make sure we are on the main screen to begin
self.assertIs(type(self.monitor_app.screen), MainScreen)

# Go to the processes screen
await pilot.press("p")
self.assertIs(type(self.monitor_app.screen), ProcessesScreen)
self.assertEqual(self.monitor_app.screen.BORDER_TITLE, "Processes")

# Go back to the main screen
await pilot.press("p")
self.assertIs(type(self.monitor_app.screen), MainScreen)
self.assertEqual(self.monitor_app.screen.BORDER_TITLE, "")

# Go to the drives screen
await pilot.press("d")
self.assertIs(type(self.monitor_app.screen), DriveScreen)
self.assertEqual(self.monitor_app.screen.BORDER_TITLE, "Drive Usage")

# Go back to the main screen
await pilot.press("d")
self.assertIs(type(self.monitor_app.screen), MainScreen)
self.assertEqual(self.monitor_app.screen.BORDER_TITLE, "")

# Go to the memory screen
await pilot.press("m")
self.assertIs(type(self.monitor_app.screen), MemoryScreen)
self.assertEqual(self.monitor_app.screen.BORDER_TITLE, "Memory")

# Go back to the main screen
await pilot.press("m")
self.assertIs(type(self.monitor_app.screen), MainScreen)
self.assertEqual(self.monitor_app.screen.BORDER_TITLE, "")

# Go to the CPU screen
await pilot.press("c")
self.assertIs(type(self.monitor_app.screen), CPU_Screen)
self.assertEqual(self.monitor_app.screen.BORDER_TITLE, "CPU Usage")
SCREENS = [
(ProcessesScreen, "p", "Processes"),
(DriveScreen, "d", "Drive Usage"),
(MemoryScreen, "m", "Memory"),
(CPU_Screen, "c", "CPU Usage"),
(NetworkScreen, "n", "Network"),
(GPU_Screen, "v", "GPU Info"),
(GuideScreen, "g", "")
]

# Go back to the main screen
await pilot.press("c")
self.assertIs(type(self.monitor_app.screen), MainScreen)
self.assertEqual(self.monitor_app.screen.BORDER_TITLE, "")

# Go to the network screen
await pilot.press("n")
self.assertIs(type(self.monitor_app.screen), NetworkScreen)
self.assertEqual(self.monitor_app.screen.BORDER_TITLE, "Network")
async with self.monitor_app.run_test() as pilot:

# Go back to the main screen
await pilot.press("n")
# Make sure we are on the main screen to begin
self.assertIs(type(self.monitor_app.screen), MainScreen)
self.assertEqual(self.monitor_app.screen.BORDER_TITLE, "")

# Go to the GPU screen
await pilot.press("v")
self.assertIs(type(self.monitor_app.screen), GPU_Screen)
self.assertEqual(self.monitor_app.screen.BORDER_TITLE, "GPU Info")
# Go through each screen in the SCREENS list
for screen_class, key, title in SCREENS:

# Go back to the main screen
await pilot.press("v")
self.assertIs(type(self.monitor_app.screen), MainScreen)
self.assertEqual(self.monitor_app.screen.BORDER_TITLE, "")

# Go to the guide screen
await pilot.press("g")
self.assertIs(type(self.monitor_app.screen), GuideScreen)
self.assertEqual(self.monitor_app.screen.BORDER_TITLE, "")
# Press the key and assert that we are on the correct screen
await pilot.press(key)
self.assertIs(type(self.monitor_app.screen), screen_class)
self.assertEqual(self.monitor_app.screen.BORDER_TITLE, title)

# Go back to the main screen
await pilot.press("g")
self.assertIs(type(self.monitor_app.screen), MainScreen)
self.assertEqual(self.monitor_app.screen.BORDER_TITLE, "")
# Go back to the main screen and assert that we are back there
await pilot.press(key)
self.assertIs(type(self.monitor_app.screen), MainScreen)
self.assertEqual(self.monitor_app.screen.BORDER_TITLE, "")

@pytest.mark.asyncio
async def test_keys_relative(self):
Expand All @@ -107,28 +61,29 @@ async def test_keys_relative(self):
:return: None
"""

# Define the screens and their corresponding keys and titles
SCREENS = [
(ProcessesScreen, "p", "Processes"),
(DriveScreen, "d", "Drive Usage"),
(MemoryScreen, "m", "Memory"),
(CPU_Screen, "c", "CPU Usage"),
(NetworkScreen, "n", "Network"),
(GPU_Screen, "v", "GPU Info"),
(MainScreen, "v", ""),
]

async with self.monitor_app.run_test() as pilot:

# Make sure we are on the main screen to begin
self.assertIs(type(self.monitor_app.screen), MainScreen)

# Starting from the Main Screen, test going to each Screen and back
await pilot.press("p")
self.assertIs(type(self.monitor_app.screen), ProcessesScreen)
await pilot.press("d")
self.assertIs(type(self.monitor_app.screen), DriveScreen)
await pilot.press("m")
self.assertIs(type(self.monitor_app.screen), MemoryScreen)
await pilot.press("c")
self.assertIs(type(self.monitor_app.screen), CPU_Screen)
await pilot.press("n")
self.assertIs(type(self.monitor_app.screen), NetworkScreen)
await pilot.press("v")
self.assertIs(type(self.monitor_app.screen), GPU_Screen)
await pilot.press("v")

# Make sure we made it back to the Main Screen
self.assertIs(type(self.monitor_app.screen), MainScreen)
# Go through each screen in the SCREENS list
for screen_class, key, title in SCREENS:

# Press the key and assert that we are on the correct screen
await pilot.press(key)
self.assertIs(type(self.monitor_app.screen), screen_class)
self.assertEqual(self.monitor_app.screen.BORDER_TITLE, title)

@pytest.mark.asyncio
async def test_keys_relative_reverse(self):
Expand All @@ -137,24 +92,25 @@ async def test_keys_relative_reverse(self):
:return: None
"""

# Define the screens and their corresponding keys
SCREENS = [
(GPU_Screen, "v"),
(NetworkScreen, "n"),
(CPU_Screen, "c"),
(MemoryScreen, "m"),
(DriveScreen, "d"),
(ProcessesScreen, "p"),
(MainScreen, "p"),
]

async with self.monitor_app.run_test() as pilot:

# Make sure we are on the main screen to begin
self.assertIs(type(self.monitor_app.screen), MainScreen)

await pilot.press("v")
self.assertIs(type(self.monitor_app.screen), GPU_Screen)
await pilot.press("n")
self.assertIs(type(self.monitor_app.screen), NetworkScreen)
await pilot.press("c")
self.assertIs(type(self.monitor_app.screen), CPU_Screen)
await pilot.press("m")
self.assertIs(type(self.monitor_app.screen), MemoryScreen)
await pilot.press("d")
self.assertIs(type(self.monitor_app.screen), DriveScreen)
await pilot.press("p")
self.assertIs(type(self.monitor_app.screen), ProcessesScreen)
await pilot.press("p")

# Make sure we made it back to the Main Screen
self.assertIs(type(self.monitor_app.screen), MainScreen)
# Iterate through the screens and their corresponding keys
for screen_class, key in SCREENS:

# Press the key and assert that we are on the correct screen
await pilot.press(key)
self.assertIs(type(self.monitor_app.screen), screen_class)

0 comments on commit bd8408d

Please sign in to comment.