Skip to content

Commit

Permalink
[refactor-prompt] restore theming support (CityOfZion#788)
Browse files Browse the repository at this point in the history
* re-store theming support

* fix comment
  • Loading branch information
ixje authored and jseagrave21 committed Jan 7, 2019
1 parent ff8fcc3 commit eec122c
Show file tree
Hide file tree
Showing 26 changed files with 180 additions and 19 deletions.
1 change: 1 addition & 0 deletions neo/Prompt/CommandBase.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from abc import ABC, abstractmethod
from neo.Prompt.Utils import get_arg
from typing import List
from neo.Prompt.PromptPrinter import prompt_print as print


class ParameterDesc():
Expand Down
2 changes: 1 addition & 1 deletion neo/Prompt/Commands/BuildNRun.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from neocore.BigInteger import BigInteger
from neo.Settings import settings
from neo.logging import log_manager
from neo.Prompt.PromptPrinter import prompt_print as print

logger = log_manager.getLogger()

Expand Down Expand Up @@ -77,7 +78,6 @@ def BuildAndRun(arguments, wallet, verbose=True, min_fee=DEFAULT_MIN_FEE, invoca
def DoRun(contract_script, arguments, wallet, path, verbose=True,
from_addr=None, min_fee=DEFAULT_MIN_FEE, invocation_test_mode=True,
debug_map=None, invoke_attrs=None, owners=None):

if not wallet:
print("Please open a wallet to test build contract")
return None, None, None, None
Expand Down
1 change: 1 addition & 0 deletions neo/Prompt/Commands/Config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from neo.Prompt.Utils import get_arg
from neo.Settings import settings
from neo.Network.NodeLeader import NodeLeader
from neo.Prompt.PromptPrinter import prompt_print as print
from distutils import util
import logging

Expand Down
1 change: 1 addition & 0 deletions neo/Prompt/Commands/Invoke.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
from prompt_toolkit import prompt
from copy import deepcopy
from neo.logging import log_manager
from neo.Prompt.PromptPrinter import prompt_print as print

logger = log_manager.getLogger()

Expand Down
1 change: 1 addition & 0 deletions neo/Prompt/Commands/LoadSmartContract.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from neo.Core.Blockchain import Blockchain
from neo.SmartContract.Contract import Contract
from neocore.BigInteger import BigInteger
from neo.Prompt.PromptPrinter import prompt_print as print


def ImportContractAddr(wallet, contract_hash, pubkey_script_hash):
Expand Down
2 changes: 1 addition & 1 deletion neo/Prompt/Commands/SC.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from neo.Implementations.Blockchains.LevelDB.DebugStorage import DebugStorage
from distutils import util
from neo.Settings import settings

from neo.Prompt.PromptPrinter import prompt_print as print
from neo.logging import log_manager

logger = log_manager.getLogger()
Expand Down
1 change: 1 addition & 0 deletions neo/Prompt/Commands/Search.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from neo.Prompt.Utils import get_arg
from neo.Core.Blockchain import Blockchain
from neo.logging import log_manager
from neo.Prompt.PromptPrinter import prompt_print as print
import json

logger = log_manager.getLogger()
Expand Down
1 change: 1 addition & 0 deletions neo/Prompt/Commands/Send.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from neo.Prompt.PromptData import PromptData
from neo.Prompt.CommandBase import CommandBase, CommandDesc, ParameterDesc
from logzero import logger
from neo.Prompt.PromptPrinter import prompt_print as print


class CommandWalletSend(CommandBase):
Expand Down
1 change: 1 addition & 0 deletions neo/Prompt/Commands/Show.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from neo.Network.NodeLeader import NodeLeader
from neo.Implementations.Notifications.LevelDB.NotificationDB import NotificationDB
from neo.logging import log_manager
from neo.Prompt.PromptPrinter import prompt_print as print
import json

logger = log_manager.getLogger()
Expand Down
2 changes: 1 addition & 1 deletion neo/Prompt/Commands/Tokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from neocore.Utils import isValidPublicAddress
import peewee
import traceback

from neo.Prompt.PromptPrinter import prompt_print as print
from neo.logging import log_manager

logger = log_manager.getLogger()
Expand Down
1 change: 1 addition & 0 deletions neo/Prompt/Commands/Wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from neo.Prompt.Commands.WalletExport import CommandWalletExport
from neo.logging import log_manager
from neocore.Utils import isValidPublicAddress
from neo.Prompt.PromptPrinter import prompt_print as print

logger = log_manager.getLogger()

Expand Down
1 change: 1 addition & 0 deletions neo/Prompt/Commands/WalletAddress.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from neo.Core.Blockchain import Blockchain
from neo.Core.TX.Transaction import ContractTransaction
from neo.Core.TX.Transaction import TransactionOutput
from neo.Prompt.PromptPrinter import prompt_print as print


class CommandWalletAddress(CommandBase):
Expand Down
1 change: 1 addition & 0 deletions neo/Prompt/Commands/WalletExport.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from neo.Prompt import Utils as PromptUtils
from neo.Prompt.PromptData import PromptData
from prompt_toolkit import prompt
from neo.Prompt.PromptPrinter import prompt_print as print


class CommandWalletExport(CommandBase):
Expand Down
1 change: 1 addition & 0 deletions neo/Prompt/Commands/WalletImport.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from neo.SmartContract.Contract import Contract
from neo.Core.Blockchain import Blockchain
from neo.Wallets import NEP5Token
from neo.Prompt.PromptPrinter import prompt_print as print


class CommandWalletImport(CommandBase):
Expand Down
12 changes: 12 additions & 0 deletions neo/Prompt/Commands/tests/test_claim_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from neo.Prompt.Commands.Wallet import ClaimGas
from neocore.Fixed8 import Fixed8
from neo.Core.TX.ClaimTransaction import ClaimTransaction
from neo.Prompt.PromptPrinter import pp
import shutil


Expand All @@ -28,6 +29,17 @@ class UserWalletTestCase(WalletFixtureTestCase):

_wallet3 = None

@classmethod
def setUpClass(cls):
super().setUpClass()
# replace the prompt_toolkit formatted print function with the default such that we can test easily
pp.printer = print

@classmethod
def tearDownClass(cls):
super().tearDownClass()
pp.reset_printer()

@property
def GAS(self):
return Blockchain.Default().SystemCoin().Hash
Expand Down
14 changes: 14 additions & 0 deletions neo/Prompt/Commands/tests/test_config_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,20 @@
from neo.Network.NodeLeader import NodeLeader
from mock import patch
from io import StringIO
from neo.Prompt.PromptPrinter import pp


class CommandConfigTestCase(BlockchainFixtureTestCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
# replace the prompt_toolkit formatted print function with the default such that we can test easily
pp.printer = print

@classmethod
def tearDownClass(cls):
super().tearDownClass()
pp.reset_printer()

@classmethod
def leveldb_testpath(self):
Expand All @@ -25,6 +36,9 @@ def test_config(self):
self.assertFalse(res)

def test_config_output(self):
# importing because it sets up `peewee` logging, which is checked at the test below
from neo.Implementations.Wallets.peewee.UserWallet import UserWallet

args = ['output']
with patch('neo.Prompt.Commands.Config.prompt', side_effect=[1, 1, 1, "\n", "\n"]): # tests changing the level and keeping the current level
res = CommandConfig().execute(args)
Expand Down
11 changes: 11 additions & 0 deletions neo/Prompt/Commands/tests/test_output_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,22 @@
from neo.Prompt.Commands.Config import start_output_config
from mock import patch
from neo.Utils.NeoTestCase import NeoTestCase
from neo.Prompt.PromptPrinter import pp
import logging
import io


class TestOutputConfig(NeoTestCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
# replace the prompt_toolkit formatted print function with the default such that we can test easily by patching sys.stdout
pp.printer = print

@classmethod
def tearDownClass(cls):
super().tearDownClass()
pp.reset_printer()

@patch('sys.stdout', new_callable=io.StringIO)
@patch('neo.Prompt.Commands.Config.log_manager.config_stdio')
Expand Down
12 changes: 12 additions & 0 deletions neo/Prompt/Commands/tests/test_sc_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from io import StringIO
from boa.compiler import Compiler
from neo.Settings import settings
from neo.Prompt.PromptPrinter import pp


class CommandSCTestCase(WalletFixtureTestCase):
Expand All @@ -23,6 +24,17 @@ class CommandSCTestCase(WalletFixtureTestCase):
_wallet1 = None
_wallet3 = None

@classmethod
def setUpClass(cls):
super().setUpClass()
# replace the prompt_toolkit formatted print function with the default such that we can test easily
pp.printer = print

@classmethod
def tearDownClass(cls):
super().tearDownClass()
pp.reset_printer()

@classmethod
def GetWallet1(cls, recreate=False):
if cls._wallet1 is None or recreate:
Expand Down
12 changes: 12 additions & 0 deletions neo/Prompt/Commands/tests/test_search_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,22 @@
from neo.Prompt.Commands.Search import CommandSearch
from mock import patch
from io import StringIO
from neo.Prompt.PromptPrinter import pp


class CommandShowTestCase(BlockchainFixtureTestCase):

@classmethod
def setUpClass(cls):
super().setUpClass()
# replace the prompt_toolkit formatted print function with the default such that we can test easily
pp.printer = print

@classmethod
def tearDownClass(cls):
super().tearDownClass()
pp.reset_printer()

@classmethod
def leveldb_testpath(self):
return os.path.join(settings.DATA_DIR_PATH, 'fixtures/test_chain')
Expand Down
12 changes: 12 additions & 0 deletions neo/Prompt/Commands/tests/test_send_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from mock import patch
import json
from io import StringIO
from neo.Prompt.PromptPrinter import pp


class UserWalletTestCase(WalletFixtureTestCase):
Expand Down Expand Up @@ -42,6 +43,17 @@ def GetWallet1(cls, recreate=False):
def tearDown(cls):
PromptData.Wallet = None

@classmethod
def setUpClass(cls):
super().setUpClass()
# replace the prompt_toolkit formatted print function with the default such that we can test easily
pp.printer = print

@classmethod
def tearDownClass(cls):
super().tearDownClass()
pp.reset_printer()

def test_send_neo(self):
with patch('neo.Prompt.Commands.Send.prompt', side_effect=[UserWalletTestCase.wallet_1_pass()]):
PromptData.Wallet = self.GetWallet1(recreate=True)
Expand Down
11 changes: 11 additions & 0 deletions neo/Prompt/Commands/tests/test_show_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from neo.Prompt.Commands.Show import CommandShow
from neo.Prompt.Commands.Wallet import CommandWallet
from neo.Prompt.PromptData import PromptData
from neo.Prompt.PromptPrinter import pp
from neo.bin.prompt import PromptInterface
from copy import deepcopy
from neo.Network.NodeLeader import NodeLeader, NeoNode
Expand All @@ -13,6 +14,16 @@


class CommandShowTestCase(BlockchainFixtureTestCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
# replace the prompt_toolkit formatted print function with the default such that we can test easily
pp.printer = print

@classmethod
def tearDownClass(cls):
super().tearDownClass()
pp.reset_printer()

@classmethod
def leveldb_testpath(self):
Expand Down
23 changes: 23 additions & 0 deletions neo/Prompt/Commands/tests/test_token_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from contextlib import contextmanager
from io import StringIO
from neo.VM.InteropService import StackItem
from neo.Prompt.PromptPrinter import pp


class UserWalletTestCase(WalletFixtureTestCase):
Expand All @@ -34,6 +35,17 @@ class UserWalletTestCase(WalletFixtureTestCase):

token_hash_str = '31730cc9a1844891a3bafd1aa929a4142860d8d3'

@classmethod
def setUpClass(cls):
super().setUpClass()
# replace the prompt_toolkit formatted print function with the default such that we can test easily
pp.printer = print

@classmethod
def tearDownClass(cls):
super().tearDownClass()
pp.reset_printer()

@property
def GAS(self):
return Blockchain.Default().SystemCoin().Hash
Expand Down Expand Up @@ -780,6 +792,17 @@ class TokenSendFromTestCase(WalletFixtureTestCase):
watch_addr_str = 'AGYaEi3W6ndHPUmW7T12FFfsbQ6DWymkEm'
wallet_1_addr = 'AJQ6FoaSXDFzA6wLnyZ1nFN7SGSN2oNTc3'

@classmethod
def setUpClass(cls):
super().setUpClass()
# replace the prompt_toolkit formatted print function with the default such that we can test easily
pp.printer = print

@classmethod
def tearDownClass(cls):
super().tearDownClass()
pp.reset_printer()

@contextmanager
def OpenWallet1(self):
PromptData.Wallet = UserWalletTestCase.GetWallet1(recreate=True)
Expand Down
13 changes: 12 additions & 1 deletion neo/Prompt/Commands/tests/test_wallet_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from neo.Prompt.Commands.Wallet import CommandWallet
from neo.Prompt.Commands.Wallet import ShowUnspentCoins
from neo.Prompt.PromptData import PromptData
from neo.Prompt.PromptPrinter import pp
import os
import shutil
from mock import patch
Expand Down Expand Up @@ -61,9 +62,19 @@ def OpenWallet2(cls):
def tearDown(cls):
PromptData.Wallet = None

@classmethod
def setUpClass(cls):
super().setUpClass()
# replace the prompt_toolkit formatted print function with the default such that we can test easily
pp.printer = print

class UserWalletTestCase(UserWalletTestCaseBase):
@classmethod
def tearDownClass(cls):
super().tearDownClass()
pp.reset_printer()


class UserWalletTestCase(UserWalletTestCaseBase):
# Beginning with refactored tests
def test_wallet(self):
# without wallet opened
Expand Down
Loading

0 comments on commit eec122c

Please sign in to comment.