From ad9ce91864e1bdafc83eea5f37f704fa5c475c84 Mon Sep 17 00:00:00 2001 From: ibraheem-opentensor Date: Wed, 7 Aug 2024 11:44:30 -0700 Subject: [PATCH] Fixes tests depending on explicit line numbers --- .../test_root_register_add_member_senate.py | 43 ++++++----------- .../root/test_root_view_proposal.py | 32 ++----------- .../subcommands/stake/test_stake_show.py | 46 ++++++------------- .../subcommands/subnet/test_metagraph.py | 9 ++-- 4 files changed, 37 insertions(+), 93 deletions(-) diff --git a/tests/e2e_tests/subcommands/root/test_root_register_add_member_senate.py b/tests/e2e_tests/subcommands/root/test_root_register_add_member_senate.py index 26e227c4e0..5fdcb5e66a 100644 --- a/tests/e2e_tests/subcommands/root/test_root_register_add_member_senate.py +++ b/tests/e2e_tests/subcommands/root/test_root_register_add_member_senate.py @@ -42,6 +42,7 @@ def test_root_register_add_member_senate(local_chain, capsys): exec_command(SetTakeCommand, ["r", "set_take", "--take", "0.8"]) + captured = capsys.readouterr() # Verify subnet 1 created successfully assert local_chain.query("SubtensorModule", "NetworksAdded", [1]).serialize() # Query local chain for senate members @@ -62,21 +63,14 @@ def test_root_register_add_member_senate(local_chain, capsys): ) captured = capsys.readouterr() - lines = captured.out.splitlines() # assert output is graph Titling "Senate" with names and addresses - assert "Senate" in lines[17].strip().split() - assert "NAME" in lines[18].strip().split() - assert "ADDRESS" in lines[18].strip().split() - assert ( - "5CiPPseXPECbkjWCa6MnjNokrgYjMqmKndv2rSnekmSK2DjL" in lines[19].strip().split() - ) - assert ( - "5DAAnrj7VHTznn2AWBemMuyBwZWs6FNFjdyVXUeYum3PTXFy" in lines[20].strip().split() - ) - assert ( - "5HGjWAeFDfFCWPsjFQdVV2Msvz2XtMktvgocEZcCj68kUMaw" in lines[21].strip().split() - ) + assert "Senate" in captured.out + assert "NAME" in captured.out + assert "ADDRESS" in captured.out + assert "5CiPPseXPECbkjWCa6MnjNokrgYjMqmKndv2rSnekmSK2DjL" in captured.out + assert "5DAAnrj7VHTznn2AWBemMuyBwZWs6FNFjdyVXUeYum3PTXFy" in captured.out + assert "5HGjWAeFDfFCWPsjFQdVV2Msvz2XtMktvgocEZcCj68kUMaw" in captured.out exec_command( RootRegisterCommand, @@ -111,21 +105,12 @@ def test_root_register_add_member_senate(local_chain, capsys): ) captured = capsys.readouterr() - lines = captured.out.splitlines() # assert output is graph Titling "Senate" with names and addresses - assert "Senate" in lines[2].strip().split() - assert "NAME" in lines[3].strip().split() - assert "ADDRESS" in lines[3].strip().split() - assert ( - "5CiPPseXPECbkjWCa6MnjNokrgYjMqmKndv2rSnekmSK2DjL" in lines[4].strip().split() - ) - assert ( - "5DAAnrj7VHTznn2AWBemMuyBwZWs6FNFjdyVXUeYum3PTXFy" in lines[5].strip().split() - ) - assert ( - "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY" in lines[6].strip().split() - ) - assert ( - "5HGjWAeFDfFCWPsjFQdVV2Msvz2XtMktvgocEZcCj68kUMaw" in lines[7].strip().split() - ) + assert "Senate" in captured.out + assert "NAME" in captured.out + assert "ADDRESS" in captured.out + assert "5CiPPseXPECbkjWCa6MnjNokrgYjMqmKndv2rSnekmSK2DjL" in captured.out + assert "5DAAnrj7VHTznn2AWBemMuyBwZWs6FNFjdyVXUeYum3PTXFy" in captured.out + assert "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY" in captured.out + assert "5HGjWAeFDfFCWPsjFQdVV2Msvz2XtMktvgocEZcCj68kUMaw" in captured.out diff --git a/tests/e2e_tests/subcommands/root/test_root_view_proposal.py b/tests/e2e_tests/subcommands/root/test_root_view_proposal.py index 05bfe8fa3a..c5da8f32f3 100644 --- a/tests/e2e_tests/subcommands/root/test_root_view_proposal.py +++ b/tests/e2e_tests/subcommands/root/test_root_view_proposal.py @@ -4,7 +4,6 @@ setup_wallet, call_add_proposal, ) -import bittensor def test_root_view_proposal(local_chain, capsys): @@ -35,30 +34,9 @@ def test_root_view_proposal(local_chain, capsys): ] captured = capsys.readouterr() - lines = captured.out.splitlines() - for line in lines: - bittensor.logging.info(line) + output = captured.out - # Assert that the length of the lines is as expected - assert len(lines) == 6 - - # Check each line for expected content - assert ( - lines[0] == "📡 Syncing with chain: local ..." - ), f"Expected '📡 Syncing with chain: local ...', got {lines[0]}" - assert ( - lines[1].strip() - == "Proposals Active Proposals: 1 Senate Size: 3" - ), f"Expected 'Proposals Active Proposals: 1 Senate Size: 3', got {lines[1].strip()}" - assert ( - lines[2].strip().startswith("HASH") - ), f"Expected line starting with 'HASH', got {lines[2].strip()}" - assert ( - lines[3] - .strip() - .startswith( - "0x78b8a348690f565efe3730cd8189f7388c0a896b6fd090276639c9130c0eba47" - ) - ), f"Expected line starting with '0x78b8a348690f565efe3730cd8189f7388c0a896b6fd090276639c9130c0eba47', got {lines[3].strip()}" - assert lines[4].strip() == "\x00)", f"Expected '\x00)', got {lines[4].strip()}" - assert lines[5].strip() == "", f"Expected empty line, got {lines[5].strip()}" + for expected_line in simulated_output: + assert ( + expected_line in output + ), f"Expected '{expected_line}' to be in the output" diff --git a/tests/e2e_tests/subcommands/stake/test_stake_show.py b/tests/e2e_tests/subcommands/stake/test_stake_show.py index b3c434e7b3..8200f72e81 100644 --- a/tests/e2e_tests/subcommands/stake/test_stake_show.py +++ b/tests/e2e_tests/subcommands/stake/test_stake_show.py @@ -8,42 +8,26 @@ def test_stake_show(local_chain, capsys): # Execute the command exec_command(StakeShow, ["stake", "show"]) captured = capsys.readouterr() - lines = captured.out.split("\n") - - # Ensure there are enough lines - assert len(lines) >= 5, "Output has fewer than 5 lines." + output = captured.out # Check the header line - header = lines[0] - assert "Coldkey" in header, "Header missing 'Coldkey'." - assert "Balance" in header, "Header missing 'Balance'." - assert "Account" in header, "Header missing 'Account'." - assert "Stake" in header, "Header missing 'Stake'." - assert "Rate" in header, "Header missing 'Rate'." + assert "Coldkey" in output, "Output missing 'Coldkey'." + assert "Balance" in output, "Output missing 'Balance'." + assert "Account" in output, "Output missing 'Account'." + assert "Stake" in output, "Output missing 'Stake'." + assert "Rate" in output, "Output missing 'Rate'." # Check the first line of data - values1 = lines[1].strip().split() - assert values1[0] == "default", f"Expected 'default', got {values1[0]}." - assert ( - values1[1].replace("τ", "") == "1000000.000000" - ), f"Expected '1000000.000000', got {values1[1]}." + assert "default" in output, "Output missing 'default'." + assert "1000000.000000" in output.replace( + "τ", "" + ), "Output missing '1000000.000000'." # Check the second line of data - values2 = lines[2].strip().split() - assert values2[0] == "default", f"Expected 'default', got {values2[0]}." - assert ( - values2[1].replace("τ", "") == "0.000000" - ), f"Expected '0.000000', got {values2[1]}." - assert values2[2] == "0/d", f"Expected '0/d', got {values2[2]}." + assert "0.000000" in output.replace("τ", ""), "Output missing '0.000000'." + assert "0/d" in output, "Output missing '0/d'." # Check the third line of data - values3 = lines[3].strip().split() - assert ( - values3[0].replace("τ", "") == "1000000.00000" - ), f"Expected '1000000.00000', got {values3[0]}." - assert ( - values3[1].replace("τ", "") == "0.00000" - ), f"Expected '0.00000', got {values3[1]}." - assert ( - values3[2].replace("τ", "") == "0.00000/d" - ), f"Expected '0.00000/d', got {values3[2]}." + assert "1000000.00000" in output.replace("τ", ""), "Output missing '1000000.00000'." + assert "0.00000" in output.replace("τ", ""), "Output missing '0.00000'." + assert "0.00000/d" in output.replace("τ", ""), "Output missing '0.00000/d'." diff --git a/tests/e2e_tests/subcommands/subnet/test_metagraph.py b/tests/e2e_tests/subcommands/subnet/test_metagraph.py index c9334f8abf..f8ad463757 100644 --- a/tests/e2e_tests/subcommands/subnet/test_metagraph.py +++ b/tests/e2e_tests/subcommands/subnet/test_metagraph.py @@ -37,10 +37,9 @@ def test_metagraph_command(local_chain, capsys): exec_command(MetagraphCommand, ["subnet", "metagraph", "--netuid", "1"]) captured = capsys.readouterr() - lines = captured.out.splitlines() # Assert metagraph is printed for netuid 1 - assert "Metagraph: net: local:1" in lines[2] + assert "Metagraph: net: local:1" in captured.out # Register Bob as neuron to the subnet bob_keypair, bob_exec_command, bob_wallet = setup_wallet("//Bob") @@ -55,10 +54,9 @@ def test_metagraph_command(local_chain, capsys): ) captured = capsys.readouterr() - lines = captured.out.splitlines() # Assert neuron was registered - assert "✅ Registered" in lines[3] + assert "✅ Registered" in captured.out # Refresh the metagraph metagraph = subtensor.metagraph(netuid=1) @@ -87,10 +85,9 @@ def test_metagraph_command(local_chain, capsys): ) captured = capsys.readouterr() - lines = captured.out.splitlines() # Assert neuron was registered - assert "✅ Registered" in lines[3] + assert "✅ Registered" in captured.out # Refresh the metagraph metagraph = subtensor.metagraph(netuid=1)