From c8fcd888b62d15c05a28b03854b6bd7a8e6d608c Mon Sep 17 00:00:00 2001 From: cjdsellers Date: Tue, 9 Mar 2021 21:21:09 +1100 Subject: [PATCH 1/2] Convert tests to pytest --- .../unit_tests/core/test_core_correctness.py | 32 +- tests/unit_tests/model/test_model_bar.py | 207 ++++--- tests/unit_tests/model/test_model_currency.py | 50 +- tests/unit_tests/model/test_model_enums.py | 552 +++++++++--------- tests/unit_tests/model/test_model_events.py | 98 ++-- .../model/test_model_identifiers.py | 140 +++-- 6 files changed, 542 insertions(+), 537 deletions(-) diff --git a/tests/unit_tests/core/test_core_correctness.py b/tests/unit_tests/core/test_core_correctness.py index 4947126cfb5b..174ac653a789 100644 --- a/tests/unit_tests/core/test_core_correctness.py +++ b/tests/unit_tests/core/test_core_correctness.py @@ -130,24 +130,27 @@ def test_callable_or_none_when_arg_not_callable_raises_type_error(self): with pytest.raises(TypeError): PyCondition.callable_or_none("not_callable", "param") - def test_callable_or_none_when_arg_is_callable_or_none_does_nothing(self): + @pytest.mark.parametrize( + "value", + [[].append, None], + ) + def test_callable_or_none_when_arg_is_callable_or_none_does_nothing(self, value): # Arrange - collection = [] - # Act # Assert: ValueError not raised - PyCondition.callable_or_none(collection.append, "param") - PyCondition.callable_or_none(None, "param") + PyCondition.callable_or_none(value, "param") - def test_equal_when_args_not_equal_raises_value_error(self): + @pytest.mark.parametrize( + "id1, id2", + [["O-123456", "O-123"], + ["O-123456", "P-123456"]], + ) + def test_equal_when_args_not_equal_raises_value_error(self, id1, id2): # Arrange # Act # Assert with pytest.raises(ValueError): - PyCondition.equal("O-123456", "O-123", "order_id1", "order_id2") - - with pytest.raises(ValueError): - PyCondition.equal("O-123456", "P-123456", "order_id", "position_id") + PyCondition.equal(id1, id2, "id1", "id2") def test_equal_when_args_are_equal_does_nothing(self): # Arrange @@ -197,12 +200,15 @@ def test_dict_types_when_contains_incorrect_types_raises_type_error(self, value) with pytest.raises(TypeError): PyCondition.dict_types(value, str, str, "param") - def test_dict_types_when_contains_correct_types_or_none_does_nothing(self): + @pytest.mark.parametrize( + "value", + [{"key": 1}, {}], + ) + def test_dict_types_when_contains_correct_types_or_none_does_nothing(self, value): # Arrange # Act # Assert: ValueError not raised - PyCondition.dict_types({"key": 1}, str, int, "param_name") - PyCondition.dict_types({}, str, str, "param_name") + PyCondition.dict_types(value, str, int, "param_name") def test_is_in_when_item_not_in_list_raises_type_error(self): # Arrange diff --git a/tests/unit_tests/model/test_model_bar.py b/tests/unit_tests/model/test_model_bar.py index 97a46276b88b..78e29b9e7f54 100644 --- a/tests/unit_tests/model/test_model_bar.py +++ b/tests/unit_tests/model/test_model_bar.py @@ -13,9 +13,7 @@ # limitations under the License. # ------------------------------------------------------------------------------------------------- -import unittest - -from parameterized import parameterized +import pytest from nautilus_trader.model.bar import Bar from nautilus_trader.model.bar import BarData @@ -36,7 +34,7 @@ GBPUSD_SIM = TestStubs.security_gbpusd() -class BarSpecificationTests(unittest.TestCase): +class TestBarSpecification: def test_bar_spec_equality(self): # Arrange @@ -46,9 +44,9 @@ def test_bar_spec_equality(self): # Act # Assert - self.assertTrue(bar_spec1 == bar_spec1) - self.assertTrue(bar_spec1 == bar_spec2) - self.assertTrue(bar_spec1 != bar_spec3) + assert bar_spec1 == bar_spec1 + assert bar_spec1 == bar_spec2 + assert bar_spec1 != bar_spec3 def test_bar_spec_hash_str_and_repr(self): # Arrange @@ -56,43 +54,43 @@ def test_bar_spec_hash_str_and_repr(self): # Act # Assert - self.assertEqual(int, type(hash(bar_spec))) - self.assertEqual("1-MINUTE-BID", str(bar_spec)) - self.assertEqual("BarSpecification(1-MINUTE-BID)", repr(bar_spec)) - - @parameterized.expand([ - [""], - ["1"], - ["-1-TICK-MID"], - ["1-TICK_MID"], - ]) + assert isinstance(hash(bar_spec), int) + assert "1-MINUTE-BID" == str(bar_spec) + assert "BarSpecification(1-MINUTE-BID)" == repr(bar_spec) + + @pytest.mark.parametrize( + "value", + ["", "1", "-1-TICK-MID", "1-TICK_MID"], + ) def test_from_str_given_various_invalid_strings_raises_value_error(self, value): # Arrange # Act # Assert - self.assertRaises(ValueError, BarSpecification.from_str, value) - - @parameterized.expand([ - ["1-MINUTE-BID", BarSpecification(1, BarAggregation.MINUTE, PriceType.BID)], - ["15-MINUTE-MID", BarSpecification(15, BarAggregation.MINUTE, PriceType.MID)], - ["100-TICK-LAST", BarSpecification(100, BarAggregation.TICK, PriceType.LAST)], - ["10000-VALUE_IMBALANCE-MID", BarSpecification(10000, BarAggregation.VALUE_IMBALANCE, PriceType.MID)], - - ]) + with pytest.raises(ValueError): + BarSpecification.from_str(value) + + @pytest.mark.parametrize( + "value, expected", + [["1-MINUTE-BID", BarSpecification(1, BarAggregation.MINUTE, PriceType.BID)], + ["15-MINUTE-MID", BarSpecification(15, BarAggregation.MINUTE, PriceType.MID)], + ["100-TICK-LAST", BarSpecification(100, BarAggregation.TICK, PriceType.LAST)], + ["10000-VALUE_IMBALANCE-MID", BarSpecification(10000, BarAggregation.VALUE_IMBALANCE, PriceType.MID)]], + ) def test_from_str_given_various_valid_string_returns_expected_specification(self, value, expected): # Arrange # Act spec = BarSpecification.from_str(value) # Assert - self.assertEqual(spec, expected) - - @parameterized.expand([ - [BarSpecification(1, BarAggregation.SECOND, PriceType.BID), True, False, False], - [BarSpecification(1, BarAggregation.MINUTE, PriceType.BID), True, False, False], - [BarSpecification(1000, BarAggregation.TICK, PriceType.MID), False, True, False], - [BarSpecification(10000, BarAggregation.VALUE_RUNS, PriceType.MID), False, False, True], - ]) + assert spec == expected + + @pytest.mark.parametrize( + "bar_spec, is_time_aggregated, is_threshold_aggregated, is_information_aggregated", + [[BarSpecification(1, BarAggregation.SECOND, PriceType.BID), True, False, False], + [BarSpecification(1, BarAggregation.MINUTE, PriceType.BID), True, False, False], + [BarSpecification(1000, BarAggregation.TICK, PriceType.MID), False, True, False], + [BarSpecification(10000, BarAggregation.VALUE_RUNS, PriceType.MID), False, False, True]], + ) def test_aggregation_queries( self, bar_spec, @@ -103,12 +101,12 @@ def test_aggregation_queries( # Arrange # Act # Assert - self.assertEqual(is_time_aggregated, bar_spec.is_time_aggregated()) - self.assertEqual(is_threshold_aggregated, bar_spec.is_threshold_aggregated()) - self.assertEqual(is_information_aggregated, bar_spec.is_information_aggregated()) + assert is_time_aggregated == bar_spec.is_time_aggregated() + assert is_threshold_aggregated == bar_spec.is_threshold_aggregated() + assert is_information_aggregated == bar_spec.is_information_aggregated() -class BarTypeTests(unittest.TestCase): +class TestBarType: def test_bar_type_equality(self): # Arrange @@ -121,9 +119,9 @@ def test_bar_type_equality(self): # Act # Assert - self.assertTrue(bar_type1 == bar_type1) - self.assertTrue(bar_type1 == bar_type2) - self.assertTrue(bar_type1 != bar_type3) + assert bar_type1 == bar_type1 + assert bar_type1 == bar_type2 + assert bar_type1 != bar_type3 def test_bar_type_to_serializable_string(self): # Arrange @@ -135,7 +133,7 @@ def test_bar_type_to_serializable_string(self): result = bar_type.to_serializable_str() # Assert - self.assertEqual("AUD/USD.IDEALPRO,FX,SPOT-1-MINUTE-BID", result) + assert "AUD/USD.IDEALPRO,FX,SPOT-1-MINUTE-BID" == result def test_bar_type_hash_str_and_repr(self): # Arrange @@ -145,85 +143,83 @@ def test_bar_type_hash_str_and_repr(self): # Act # Assert - self.assertEqual(int, type(hash(bar_type))) - self.assertEqual("AUD/USD.SIM-1-MINUTE-BID", str(bar_type)) - self.assertEqual("BarType(AUD/USD.SIM-1-MINUTE-BID, internal_aggregation=True)", repr(bar_type)) - - @parameterized.expand([ - [""], - ["AUD/USD"], - ["AUD/USD.IDEALPRO-1-MILLISECOND-BID"], - ]) + assert isinstance(hash(bar_type), int) + assert "AUD/USD.SIM-1-MINUTE-BID" == str(bar_type) + assert "BarType(AUD/USD.SIM-1-MINUTE-BID, internal_aggregation=True)" == repr(bar_type) + + @pytest.mark.parametrize( + "value", + ["", "AUD/USD", "AUD/USD.IDEALPRO-1-MILLISECOND-BID"], + ) def test_from_str_given_various_invalid_strings_raises_value_error(self, value): # Arrange # Act # Assert - self.assertRaises(ValueError, BarType.from_serializable_str, value) - - @parameterized.expand([ - ["AUD/USD.IDEALPRO,FX,SPOT-1-MINUTE-BID", BarType(Security("AUD/USD", Venue("IDEALPRO"), AssetClass.FX, AssetType.SPOT), BarSpecification(1, BarAggregation.MINUTE, PriceType.BID))], # noqa - ["GBP/USD.SIM,FX,SPOT-1000-TICK-MID", BarType(Security("GBP/USD", Venue("SIM"), AssetClass.FX, AssetType.SPOT), BarSpecification(1000, BarAggregation.TICK, PriceType.MID))], # noqa - ["AAPL.NYSE,STOCK,SPOT-1-HOUR-MID", BarType(Security("AAPL", Venue("NYSE"), AssetClass.STOCK, AssetType.SPOT), BarSpecification(1, BarAggregation.HOUR, PriceType.MID))], # noqa - ["BTC/USDT.BINANCE,CRYPTO,SPOT-100-TICK-LAST", BarType(Security("BTC/USDT", Venue("BINANCE"), AssetClass.CRYPTO, AssetType.SPOT), BarSpecification(100, BarAggregation.TICK, PriceType.LAST))], # noqa - ]) + with pytest.raises(ValueError): + BarType.from_serializable_str(value) + + @pytest.mark.parametrize( + "value, expected", + [["AUD/USD.IDEALPRO,FX,SPOT-1-MINUTE-BID", BarType(Security("AUD/USD", Venue("IDEALPRO"), AssetClass.FX, AssetType.SPOT), BarSpecification(1, BarAggregation.MINUTE, PriceType.BID))], # noqa + ["GBP/USD.SIM,FX,SPOT-1000-TICK-MID", BarType(Security("GBP/USD", Venue("SIM"), AssetClass.FX, AssetType.SPOT), BarSpecification(1000, BarAggregation.TICK, PriceType.MID))], # noqa + ["AAPL.NYSE,STOCK,SPOT-1-HOUR-MID", BarType(Security("AAPL", Venue("NYSE"), AssetClass.STOCK, AssetType.SPOT), BarSpecification(1, BarAggregation.HOUR, PriceType.MID))], # noqa + ["BTC/USDT.BINANCE,CRYPTO,SPOT-100-TICK-LAST", BarType(Security("BTC/USDT", Venue("BINANCE"), AssetClass.CRYPTO, AssetType.SPOT), BarSpecification(100, BarAggregation.TICK, PriceType.LAST))]], # noqa + ) def test_from_str_given_various_valid_string_returns_expected_specification(self, value, expected): # Arrange # Act bar_type = BarType.from_serializable_str(value, internal_aggregation=True) # Assert - self.assertEqual(bar_type, expected) + assert bar_type == expected -class BarTests(unittest.TestCase): +class TestBar: def test_check_when_high_below_low_raises_value_error(self): # Arrange # Act # Assert - self.assertRaises( - ValueError, - Bar, - Price("1.00001"), - Price("1.00000"), # High below low - Price("1.00002"), - Price("1.00003"), - Quantity(100000), - UNIX_EPOCH, - True, - ) + with pytest.raises(ValueError): + Bar( + Price("1.00001"), + Price("1.00000"), # High below low + Price("1.00002"), + Price("1.00003"), + Quantity(100000), + UNIX_EPOCH, + True, + ) def test_check_when_high_below_close_raises_value_error(self): # Arrange # Act # Assert - self.assertRaises( - ValueError, - Bar, - Price("1.00000"), - Price("1.00000"), # High below close - Price("1.00000"), - Price("1.00005"), - Quantity(100000), - UNIX_EPOCH, - True, - ) + with pytest.raises(ValueError): + Bar( + Price("1.00000"), + Price("1.00000"), # High below close + Price("1.00000"), + Price("1.00005"), + Quantity(100000), + UNIX_EPOCH, + True, + ) def test_check_when_low_above_close_raises_value_error(self): # Arrange # Act # Assert - self.assertRaises( - ValueError, - Bar, - Price("1.00000"), - Price("1.00005"), - Price("1.00000"), - Price("0.99999"), # Close below low - Quantity(100000), - UNIX_EPOCH, - True, - ) + with pytest.raises(ValueError): + Bar( + Price("1.00000"), + Price("1.00005"), + Price("1.00000"), + Price("0.99999"), # Close below low + Quantity(100000), + UNIX_EPOCH, + True, + ) def test_equality(self): # Arrange @@ -247,8 +243,8 @@ def test_equality(self): # Act # Assert - self.assertEqual(bar1, bar1) - self.assertNotEqual(bar1, bar2) + assert bar1 == bar1 + assert bar1 != bar2 def test_hash_str_repr(self): # Arrange @@ -263,9 +259,9 @@ def test_hash_str_repr(self): # Act # Assert - self.assertEqual(int, type(hash(bar))) - self.assertEqual("1.00001,1.00004,1.00002,1.00003,100000,1970-01-01T00:00:00.000Z", str(bar)) - self.assertEqual("Bar(1.00001,1.00004,1.00002,1.00003,100000,1970-01-01T00:00:00.000Z)", repr(bar)) + assert isinstance(hash(bar), int) + assert "1.00001,1.00004,1.00002,1.00003,100000,1970-01-01T00:00:00.000Z" == str(bar) + assert "Bar(1.00001,1.00004,1.00002,1.00003,100000,1970-01-01T00:00:00.000Z)" == repr(bar) def test_to_serializable_string(self): # Arrange @@ -282,7 +278,7 @@ def test_to_serializable_string(self): serializable = bar.to_serializable_str() # Assert - self.assertEqual("1.00001,1.00004,1.00002,1.00003,100000,0", serializable) + assert "1.00001,1.00004,1.00002,1.00003,100000,0" == serializable def test_from_serializable_string_given_malformed_string_raises_value_error(self): # Arrange @@ -297,7 +293,8 @@ def test_from_serializable_string_given_malformed_string_raises_value_error(self # Act # Assert - self.assertRaises(ValueError, bar.from_serializable_str, "NOT_A_BAR") + with pytest.raises(ValueError): + bar.from_serializable_str("NOT_A_BAR") def test_from_serializable_string_given_valid_string_returns_expected_bar(self): # Arrange @@ -307,10 +304,10 @@ def test_from_serializable_string_given_valid_string_returns_expected_bar(self): result = Bar.from_serializable_str(bar.to_serializable_str()) # Assert - self.assertEqual(bar, result) + assert bar == result -class BarDataTests(unittest.TestCase): +class TestBarData: def test_str_repr(self): # Arrange @@ -330,5 +327,5 @@ def test_str_repr(self): # Act # Assert - self.assertEqual("BarData(bar_type=GBP/USD.SIM-1-MINUTE-BID, bar=1.00001,1.00004,1.00002,1.00003,100000,1970-01-01T00:00:00.000Z)", str(bar_data)) # noqa - self.assertEqual("BarData(bar_type=GBP/USD.SIM-1-MINUTE-BID, bar=1.00001,1.00004,1.00002,1.00003,100000,1970-01-01T00:00:00.000Z)", repr(bar_data)) # noqa + assert "BarData(bar_type=GBP/USD.SIM-1-MINUTE-BID, bar=1.00001,1.00004,1.00002,1.00003,100000,1970-01-01T00:00:00.000Z)" == str(bar_data) # noqa + assert "BarData(bar_type=GBP/USD.SIM-1-MINUTE-BID, bar=1.00001,1.00004,1.00002,1.00003,100000,1970-01-01T00:00:00.000Z)" == repr(bar_data) # noqa diff --git a/tests/unit_tests/model/test_model_currency.py b/tests/unit_tests/model/test_model_currency.py index 1b58a451977a..7c18b05b23cb 100644 --- a/tests/unit_tests/model/test_model_currency.py +++ b/tests/unit_tests/model/test_model_currency.py @@ -13,9 +13,7 @@ # limitations under the License. # ------------------------------------------------------------------------------------------------- -import unittest - -from parameterized import parameterized +import pytest from nautilus_trader.model.currencies import AUD from nautilus_trader.model.currencies import BTC @@ -29,7 +27,7 @@ GBPUSD_SIM = TestStubs.security_gbpusd() -class CurrencyTests(unittest.TestCase): +class TestCurrency: def test_currency_equality(self): # Arrange @@ -39,9 +37,9 @@ def test_currency_equality(self): # Act # Assert - self.assertTrue(currency1 == currency1) - self.assertTrue(currency1 == currency2) - self.assertTrue(currency1 != currency3) + assert currency1 == currency1 + assert currency1 == currency2 + assert currency1 != currency3 def test_currency_hash(self): # Arrange @@ -49,8 +47,8 @@ def test_currency_hash(self): # Act # Assert - self.assertEqual(int, type(hash(currency))) - self.assertEqual(hash(currency), hash(currency)) + assert isinstance(hash(currency), int) + assert hash(currency) == hash(currency) def test_str_repr(self): # Arrange @@ -58,8 +56,8 @@ def test_str_repr(self): # Act # Assert - self.assertEqual("AUD", str(currency)) - self.assertEqual("Currency(code=AUD, precision=2, type=FIAT)", repr(currency)) + assert "AUD" == str(currency) + assert "Currency(code=AUD, precision=2, type=FIAT)" == repr(currency) def test_from_str_given_unknown_code_returns_none(self): # Arrange @@ -67,30 +65,32 @@ def test_from_str_given_unknown_code_returns_none(self): result = Currency.from_str("SOME_CURRENCY") # Assert - self.assertIsNone(result) - - @parameterized.expand([ - ["AUD", AUD], - ["GBP", GBP], - ["BTC", BTC], - ["ETH", ETH], - ]) + assert result is None + + @pytest.mark.parametrize( + "string, expected", + [["AUD", AUD], + ["GBP", GBP], + ["BTC", BTC], + ["ETH", ETH]], + ) def test_from_str(self, string, expected): # Arrange # Act result = Currency.from_str(string) # Assert - self.assertEqual(expected, result) + assert expected == result - @parameterized.expand([ - ["AUD", True], - ["ZZZ", False], - ]) + @pytest.mark.parametrize( + "string, expected", + [["AUD", True], + ["ZZZ", False]], + ) def test_is_fiat(self, string, expected): # Arrange # Act result = Currency.is_fiat(string) # Assert - self.assertEqual(expected, result) + assert expected == result diff --git a/tests/unit_tests/model/test_model_enums.py b/tests/unit_tests/model/test_model_enums.py index 6a9362bb4b82..8d480e76860d 100644 --- a/tests/unit_tests/model/test_model_enums.py +++ b/tests/unit_tests/model/test_model_enums.py @@ -13,9 +13,7 @@ # limitations under the License. # ------------------------------------------------------------------------------------------------- -import unittest - -from parameterized import parameterized +import pytest from nautilus_trader.model.c_enums.asset_class import AssetClass from nautilus_trader.model.c_enums.asset_class import AssetClassParser @@ -43,434 +41,458 @@ from nautilus_trader.model.c_enums.time_in_force import TimeInForceParser -class AssetClassTests(unittest.TestCase): +class TestAssetClass: - @parameterized.expand([ - [AssetClass.UNDEFINED, "UNDEFINED"], - [AssetClass.FX, "FX"], - [AssetClass.STOCK, "STOCK"], - [AssetClass.COMMODITY, "COMMODITY"], - [AssetClass.BOND, "BOND"], - [AssetClass.INDEX, "INDEX"], - [AssetClass.CRYPTO, "CRYPTO"], - ]) + @pytest.mark.parametrize( + "enum, expected", + [[AssetClass.UNDEFINED, "UNDEFINED"], + [AssetClass.FX, "FX"], + [AssetClass.STOCK, "STOCK"], + [AssetClass.COMMODITY, "COMMODITY"], + [AssetClass.BOND, "BOND"], + [AssetClass.INDEX, "INDEX"], + [AssetClass.CRYPTO, "CRYPTO"]], + ) def test_asset_class_to_str(self, enum, expected): # Arrange # Act result = AssetClassParser.to_str_py(enum) # Assert - self.assertEqual(expected, result) - - @parameterized.expand([ - ["", AssetClass.UNDEFINED], - ["UNDEFINED", AssetClass.UNDEFINED], - ["FX", AssetClass.FX], - ["STOCK", AssetClass.STOCK], - ["COMMODITY", AssetClass.COMMODITY], - ["BOND", AssetClass.BOND], - ["INDEX", AssetClass.INDEX], - ["CRYPTO", AssetClass.CRYPTO], - ]) + assert expected == result + + @pytest.mark.parametrize( + "string, expected", + [["", AssetClass.UNDEFINED], + ["UNDEFINED", AssetClass.UNDEFINED], + ["FX", AssetClass.FX], + ["STOCK", AssetClass.STOCK], + ["COMMODITY", AssetClass.COMMODITY], + ["BOND", AssetClass.BOND], + ["INDEX", AssetClass.INDEX], + ["CRYPTO", AssetClass.CRYPTO]], + ) def test_asset_class_from_str(self, string, expected): # Arrange # Act result = AssetClassParser.from_str_py(string) # Assert - self.assertEqual(expected, result) - - -class AssetTypeTests(unittest.TestCase): - - @parameterized.expand([ - [AssetType.UNDEFINED, "UNDEFINED"], - [AssetType.SPOT, "SPOT"], - [AssetType.SWAP, "SWAP"], - [AssetType.FUTURE, "FUTURE"], - [AssetType.FORWARD, "FORWARD"], - [AssetType.CFD, "CFD"], - [AssetType.OPTION, "OPTION"], - [AssetType.WARRANT, "WARRANT"], - ]) + assert expected == result + + +class TestAssetType: + + @pytest.mark.parametrize( + "enum, expected", + [[AssetType.UNDEFINED, "UNDEFINED"], + [AssetType.SPOT, "SPOT"], + [AssetType.SWAP, "SWAP"], + [AssetType.FUTURE, "FUTURE"], + [AssetType.FORWARD, "FORWARD"], + [AssetType.CFD, "CFD"], + [AssetType.OPTION, "OPTION"], + [AssetType.WARRANT, "WARRANT"]], + ) def test_asset_type_to_str(self, enum, expected): # Arrange # Act result = AssetTypeParser.to_str_py(enum) # Assert - self.assertEqual(expected, result) - - @parameterized.expand([ - ["", AssetType.UNDEFINED], - ["UNDEFINED", AssetType.UNDEFINED], - ["SPOT", AssetType.SPOT], - ["SWAP", AssetType.SWAP], - ["FUTURE", AssetType.FUTURE], - ["FORWARD", AssetType.FORWARD], - ["CFD", AssetType.CFD], - ["OPTION", AssetType.OPTION], - ["WARRANT", AssetType.WARRANT], - ]) + assert expected == result + + @pytest.mark.parametrize( + "string, expected", + [["", AssetType.UNDEFINED], + ["UNDEFINED", AssetType.UNDEFINED], + ["SPOT", AssetType.SPOT], + ["SWAP", AssetType.SWAP], + ["FUTURE", AssetType.FUTURE], + ["FORWARD", AssetType.FORWARD], + ["CFD", AssetType.CFD], + ["OPTION", AssetType.OPTION], + ["WARRANT", AssetType.WARRANT]], + ) def test_asset_type_from_str(self, string, expected): # Arrange # Act result = AssetTypeParser.from_str_py(string) # Assert - self.assertEqual(expected, result) - - -class BarAggregationTests(unittest.TestCase): - - @parameterized.expand([ - [BarAggregation.UNDEFINED, "UNDEFINED"], - [BarAggregation.TICK, "TICK"], - [BarAggregation.TICK_IMBALANCE, "TICK_IMBALANCE"], - [BarAggregation.TICK_RUNS, "TICK_RUNS"], - [BarAggregation.VOLUME, "VOLUME"], - [BarAggregation.VOLUME_IMBALANCE, "VOLUME_IMBALANCE"], - [BarAggregation.VOLUME_RUNS, "VOLUME_RUNS"], - [BarAggregation.VALUE, "VALUE"], - [BarAggregation.VALUE_IMBALANCE, "VALUE_IMBALANCE"], - [BarAggregation.VALUE_RUNS, "VALUE_RUNS"], - [BarAggregation.SECOND, "SECOND"], - [BarAggregation.MINUTE, "MINUTE"], - [BarAggregation.HOUR, "HOUR"], - [BarAggregation.DAY, "DAY"], - ]) + assert expected == result + + +class TestBarAggregation: + + @pytest.mark.parametrize( + "enum, expected", + [[BarAggregation.UNDEFINED, "UNDEFINED"], + [BarAggregation.TICK, "TICK"], + [BarAggregation.TICK_IMBALANCE, "TICK_IMBALANCE"], + [BarAggregation.TICK_RUNS, "TICK_RUNS"], + [BarAggregation.VOLUME, "VOLUME"], + [BarAggregation.VOLUME_IMBALANCE, "VOLUME_IMBALANCE"], + [BarAggregation.VOLUME_RUNS, "VOLUME_RUNS"], + [BarAggregation.VALUE, "VALUE"], + [BarAggregation.VALUE_IMBALANCE, "VALUE_IMBALANCE"], + [BarAggregation.VALUE_RUNS, "VALUE_RUNS"], + [BarAggregation.SECOND, "SECOND"], + [BarAggregation.MINUTE, "MINUTE"], + [BarAggregation.HOUR, "HOUR"], + [BarAggregation.DAY, "DAY"]], + ) def test_bar_aggregation_to_str(self, enum, expected): # Arrange # Act result = BarAggregationParser.to_str_py(enum) # Assert - self.assertEqual(expected, result) - - @parameterized.expand([ - ["", BarAggregation.UNDEFINED], - ["UNDEFINED", BarAggregation.UNDEFINED], - ["TICK", BarAggregation.TICK], - ["TICK_IMBALANCE", BarAggregation.TICK_IMBALANCE], - ["TICK_RUNS", BarAggregation.TICK_RUNS], - ["VOLUME", BarAggregation.VOLUME], - ["VOLUME_IMBALANCE", BarAggregation.VOLUME_IMBALANCE], - ["VOLUME_RUNS", BarAggregation.VOLUME_RUNS], - ["VALUE", BarAggregation.VALUE], - ["VALUE_IMBALANCE", BarAggregation.VALUE_IMBALANCE], - ["VALUE_RUNS", BarAggregation.VALUE_RUNS], - ["SECOND", BarAggregation.SECOND], - ["MINUTE", BarAggregation.MINUTE], - ["HOUR", BarAggregation.HOUR], - ["DAY", BarAggregation.DAY], - ]) + assert expected == result + + @pytest.mark.parametrize( + "string, expected", + [["", BarAggregation.UNDEFINED], + ["UNDEFINED", BarAggregation.UNDEFINED], + ["TICK", BarAggregation.TICK], + ["TICK_IMBALANCE", BarAggregation.TICK_IMBALANCE], + ["TICK_RUNS", BarAggregation.TICK_RUNS], + ["VOLUME", BarAggregation.VOLUME], + ["VOLUME_IMBALANCE", BarAggregation.VOLUME_IMBALANCE], + ["VOLUME_RUNS", BarAggregation.VOLUME_RUNS], + ["VALUE", BarAggregation.VALUE], + ["VALUE_IMBALANCE", BarAggregation.VALUE_IMBALANCE], + ["VALUE_RUNS", BarAggregation.VALUE_RUNS], + ["SECOND", BarAggregation.SECOND], + ["MINUTE", BarAggregation.MINUTE], + ["HOUR", BarAggregation.HOUR], + ["DAY", BarAggregation.DAY]], + ) def test_bar_aggregation_from_str(self, string, expected): # Arrange # Act result = BarAggregationParser.from_str_py(string) # Assert - self.assertEqual(expected, result) + assert expected == result -class CurrencyTypeTests(unittest.TestCase): +class TestCurrencyType: - @parameterized.expand([ - [CurrencyType.UNDEFINED, "UNDEFINED"], - [CurrencyType.CRYPTO, "CRYPTO"], - [CurrencyType.FIAT, "FIAT"], - ]) + @pytest.mark.parametrize( + "enum, expected", + [[CurrencyType.UNDEFINED, "UNDEFINED"], + [CurrencyType.CRYPTO, "CRYPTO"], + [CurrencyType.FIAT, "FIAT"]], + ) def test_currency_type_to_str(self, enum, expected): # Arrange # Act result = CurrencyTypeParser.to_str_py(enum) # Assert - self.assertEqual(expected, result) - - @parameterized.expand([ - ["", CurrencyType.UNDEFINED], - ["UNDEFINED", CurrencyType.UNDEFINED], - ["CRYPTO", CurrencyType.CRYPTO], - ["FIAT", CurrencyType.FIAT], - ]) + assert expected == result + + @pytest.mark.parametrize( + "string, expected", + [["", CurrencyType.UNDEFINED], + ["UNDEFINED", CurrencyType.UNDEFINED], + ["CRYPTO", CurrencyType.CRYPTO], + ["FIAT", CurrencyType.FIAT]], + ) def test_currency_type_from_str(self, string, expected): # Arrange # Act result = CurrencyTypeParser.from_str_py(string) # Assert - self.assertEqual(expected, result) + assert expected == result -class LiquiditySideTests(unittest.TestCase): +class TestLiquiditySide: - @parameterized.expand([ - [LiquiditySide.NONE, "NONE"], - [LiquiditySide.MAKER, "MAKER"], - [LiquiditySide.TAKER, "TAKER"], - ]) + @pytest.mark.parametrize( + "enum, expected", + [[LiquiditySide.NONE, "NONE"], + [LiquiditySide.MAKER, "MAKER"], + [LiquiditySide.TAKER, "TAKER"]], + ) def test_liquidity_side_to_str(self, enum, expected): # Arrange # Act result = LiquiditySideParser.to_str_py(enum) # Assert - self.assertEqual(expected, result) - - @parameterized.expand([ - ["", LiquiditySide.NONE], - ["NONE", LiquiditySide.NONE], - ["MAKER", LiquiditySide.MAKER], - ["TAKER", LiquiditySide.TAKER], - ]) + assert expected == result + + @pytest.mark.parametrize( + "string, expected", + [["", LiquiditySide.NONE], + ["NONE", LiquiditySide.NONE], + ["MAKER", LiquiditySide.MAKER], + ["TAKER", LiquiditySide.TAKER]], + ) def test_liquidity_side_from_str(self, string, expected): # Arrange # Act result = LiquiditySideParser.from_str_py(string) # Assert - self.assertEqual(expected, result) + assert expected == result -class OMSTypeTests(unittest.TestCase): +class TestOMSType: - @parameterized.expand([ - [OMSType.UNDEFINED, "UNDEFINED"], - [OMSType.NETTING, "NETTING"], - [OMSType.HEDGING, "HEDGING"], - ]) + @pytest.mark.parametrize( + "enum, expected", + [[OMSType.UNDEFINED, "UNDEFINED"], + [OMSType.NETTING, "NETTING"], + [OMSType.HEDGING, "HEDGING"]], + ) def test_oms_type_to_str(self, enum, expected): # Arrange # Act result = OMSTypeParser.to_str_py(enum) # Assert - self.assertEqual(expected, result) - - @parameterized.expand([ - ["", OMSType.UNDEFINED], - ["UNDEFINED", OMSType.UNDEFINED], - ["NETTING", OMSType.NETTING], - ["HEDGING", OMSType.HEDGING], - ]) + assert expected == result + + @pytest.mark.parametrize( + "string, expected", + [["", OMSType.UNDEFINED], + ["UNDEFINED", OMSType.UNDEFINED], + ["NETTING", OMSType.NETTING], + ["HEDGING", OMSType.HEDGING]], + ) def test_oms_type_from_str(self, string, expected): # Arrange # Act result = OMSTypeParser.from_str_py(string) # Assert - self.assertEqual(expected, result) + assert expected == result -class OrderSideTests(unittest.TestCase): +class TestOrderSide: - @parameterized.expand([ - [OrderSide.UNDEFINED, "UNDEFINED"], - [OrderSide.BUY, "BUY"], - [OrderSide.SELL, "SELL"], - ]) + @pytest.mark.parametrize( + "enum, expected", + [[OrderSide.UNDEFINED, "UNDEFINED"], + [OrderSide.BUY, "BUY"], + [OrderSide.SELL, "SELL"]], + ) def test_order_side_to_str(self, enum, expected): # Arrange # Act result = OrderSideParser.to_str_py(enum) # Assert - self.assertEqual(expected, result) - - @parameterized.expand([ - ["", OrderSide.UNDEFINED], - ["UNDEFINED", OrderSide.UNDEFINED], - ["BUY", OrderSide.BUY], - ["SELL", OrderSide.SELL], - ]) + assert expected == result + + @pytest.mark.parametrize( + "string, expected", + [["", OrderSide.UNDEFINED], + ["UNDEFINED", OrderSide.UNDEFINED], + ["BUY", OrderSide.BUY], + ["SELL", OrderSide.SELL]], + ) def test_order_side_from_str(self, string, expected): # Arrange # Act result = OrderSideParser.from_str_py(string) # Assert - self.assertEqual(expected, result) - - -class OrderStateTests(unittest.TestCase): - - @parameterized.expand([ - [OrderState.UNDEFINED, "UNDEFINED"], - [OrderState.INITIALIZED, "INITIALIZED"], - [OrderState.INVALID, "INVALID"], - [OrderState.DENIED, "DENIED"], - [OrderState.SUBMITTED, "SUBMITTED"], - [OrderState.ACCEPTED, "ACCEPTED"], - [OrderState.REJECTED, "REJECTED"], - [OrderState.CANCELLED, "CANCELLED"], - [OrderState.EXPIRED, "EXPIRED"], - [OrderState.TRIGGERED, "TRIGGERED"], - [OrderState.PARTIALLY_FILLED, "PARTIALLY_FILLED"], - [OrderState.FILLED, "FILLED"], - ]) + assert expected == result + + +class TestOrderState: + + @pytest.mark.parametrize( + "enum, expected", + [[OrderState.UNDEFINED, "UNDEFINED"], + [OrderState.INITIALIZED, "INITIALIZED"], + [OrderState.INVALID, "INVALID"], + [OrderState.DENIED, "DENIED"], + [OrderState.SUBMITTED, "SUBMITTED"], + [OrderState.ACCEPTED, "ACCEPTED"], + [OrderState.REJECTED, "REJECTED"], + [OrderState.CANCELLED, "CANCELLED"], + [OrderState.EXPIRED, "EXPIRED"], + [OrderState.TRIGGERED, "TRIGGERED"], + [OrderState.PARTIALLY_FILLED, "PARTIALLY_FILLED"], + [OrderState.FILLED, "FILLED"]], + ) def test_order_state_to_str(self, enum, expected): # Arrange # Act result = OrderStateParser.to_str_py(enum) # Assert - self.assertEqual(expected, result) - - @parameterized.expand([ - ["", OrderState.UNDEFINED], - ["UNDEFINED", OrderState.UNDEFINED], - ["INITIALIZED", OrderState.INITIALIZED], - ["INVALID", OrderState.INVALID], - ["DENIED", OrderState.DENIED], - ["SUBMITTED", OrderState.SUBMITTED], - ["ACCEPTED", OrderState.ACCEPTED], - ["REJECTED", OrderState.REJECTED], - ["CANCELLED", OrderState.CANCELLED], - ["EXPIRED", OrderState.EXPIRED], - ["TRIGGERED", OrderState.TRIGGERED], - ["PARTIALLY_FILLED", OrderState.PARTIALLY_FILLED], - ["FILLED", OrderState.FILLED], - ]) + assert expected == result + + @pytest.mark.parametrize( + "string, expected", + [["", OrderState.UNDEFINED], + ["UNDEFINED", OrderState.UNDEFINED], + ["INITIALIZED", OrderState.INITIALIZED], + ["INVALID", OrderState.INVALID], + ["DENIED", OrderState.DENIED], + ["SUBMITTED", OrderState.SUBMITTED], + ["ACCEPTED", OrderState.ACCEPTED], + ["REJECTED", OrderState.REJECTED], + ["CANCELLED", OrderState.CANCELLED], + ["EXPIRED", OrderState.EXPIRED], + ["TRIGGERED", OrderState.TRIGGERED], + ["PARTIALLY_FILLED", OrderState.PARTIALLY_FILLED], + ["FILLED", OrderState.FILLED]], + ) def test_order_state_from_str(self, string, expected): # Arrange # Act result = OrderStateParser.from_str_py(string) # Assert - self.assertEqual(expected, result) + assert expected == result -class OrderTypeTests(unittest.TestCase): +class TestOrderType: - @parameterized.expand([ - [OrderType.UNDEFINED, "UNDEFINED"], - [OrderType.MARKET, "MARKET"], - [OrderType.LIMIT, "LIMIT"], - [OrderType.STOP_MARKET, "STOP_MARKET"], - [OrderType.STOP_LIMIT, "STOP_LIMIT"], - ]) + @pytest.mark.parametrize( + "enum, expected", + [[OrderType.UNDEFINED, "UNDEFINED"], + [OrderType.MARKET, "MARKET"], + [OrderType.LIMIT, "LIMIT"], + [OrderType.STOP_MARKET, "STOP_MARKET"], + [OrderType.STOP_LIMIT, "STOP_LIMIT"]], + ) def test_order_type_to_str(self, enum, expected): # Arrange # Act result = OrderTypeParser.to_str_py(enum) # Assert - self.assertEqual(expected, result) - - @parameterized.expand([ - ["", OrderType.UNDEFINED], - ["UNDEFINED", OrderType.UNDEFINED], - ["MARKET", OrderType.MARKET], - ["LIMIT", OrderType.LIMIT], - ["STOP_MARKET", OrderType.STOP_MARKET], - ["STOP_LIMIT", OrderType.STOP_LIMIT], - ]) + assert expected == result + + @pytest.mark.parametrize( + "string, expected", + [["", OrderType.UNDEFINED], + ["UNDEFINED", OrderType.UNDEFINED], + ["MARKET", OrderType.MARKET], + ["LIMIT", OrderType.LIMIT], + ["STOP_MARKET", OrderType.STOP_MARKET], + ["STOP_LIMIT", OrderType.STOP_LIMIT]], + ) def test_order_type_from_str(self, string, expected): # Arrange # Act result = OrderTypeParser.from_str_py(string) # Assert - self.assertEqual(expected, result) + assert expected == result -class PositionSideTests(unittest.TestCase): +class TestPositionSide: - @parameterized.expand([ - [PositionSide.UNDEFINED, "UNDEFINED"], - [PositionSide.FLAT, "FLAT"], - [PositionSide.LONG, "LONG"], - [PositionSide.SHORT, "SHORT"], - ]) + @pytest.mark.parametrize( + "enum, expected", + [[PositionSide.UNDEFINED, "UNDEFINED"], + [PositionSide.FLAT, "FLAT"], + [PositionSide.LONG, "LONG"], + [PositionSide.SHORT, "SHORT"]], + ) def test_position_side_to_str(self, enum, expected): # Arrange # Act result = PositionSideParser.to_str_py(enum) # Assert - self.assertEqual(expected, result) - - @parameterized.expand([ - ["", PositionSide.UNDEFINED], - ["UNDEFINED", PositionSide.UNDEFINED], - ["FLAT", PositionSide.FLAT], - ["LONG", PositionSide.LONG], - ["SHORT", PositionSide.SHORT], - ]) + assert expected == result + + @pytest.mark.parametrize( + "string, expected", + [["", PositionSide.UNDEFINED], + ["UNDEFINED", PositionSide.UNDEFINED], + ["FLAT", PositionSide.FLAT], + ["LONG", PositionSide.LONG], + ["SHORT", PositionSide.SHORT]], + ) def test_position_side_from_str(self, string, expected): # Arrange # Act result = PositionSideParser.from_str_py(string) # Assert - self.assertEqual(expected, result) + assert expected == result -class PriceTypeTests(unittest.TestCase): +class TestPriceType: - @parameterized.expand([ - [PriceType.UNDEFINED, "UNDEFINED"], - [PriceType.BID, "BID"], - [PriceType.ASK, "ASK"], - [PriceType.MID, "MID"], - [PriceType.LAST, "LAST"], - ]) + @pytest.mark.parametrize( + "enum, expected", + [[PriceType.UNDEFINED, "UNDEFINED"], + [PriceType.BID, "BID"], + [PriceType.ASK, "ASK"], + [PriceType.MID, "MID"], + [PriceType.LAST, "LAST"]], + ) def test_price_type_to_str(self, enum, expected): # Arrange # Act result = PriceTypeParser.to_str_py(enum) # Assert - self.assertEqual(expected, result) - - @parameterized.expand([ - ["", PriceType.UNDEFINED], - ["UNDEFINED", PriceType.UNDEFINED], - ["ASK", PriceType.ASK], - ["MID", PriceType.MID], - ["LAST", PriceType.LAST], - ]) + assert expected == result + + @pytest.mark.parametrize( + "string, expected", + [["", PriceType.UNDEFINED], + ["UNDEFINED", PriceType.UNDEFINED], + ["ASK", PriceType.ASK], + ["MID", PriceType.MID], + ["LAST", PriceType.LAST]], + ) def test_price_type_from_str(self, string, expected): # Arrange # Act result = PriceTypeParser.from_str_py(string) # Assert - self.assertEqual(expected, result) + assert expected == result -class TimeInForceTests(unittest.TestCase): +class TestTimeInForce: - @parameterized.expand([ - [TimeInForce.UNDEFINED, "UNDEFINED"], - [TimeInForce.DAY, "DAY"], - [TimeInForce.GTC, "GTC"], - [TimeInForce.IOC, "IOC"], - [TimeInForce.FOK, "FOK"], - [TimeInForce.GTD, "GTD"], - ]) + @pytest.mark.parametrize( + "enum, expected", + [[TimeInForce.UNDEFINED, "UNDEFINED"], + [TimeInForce.DAY, "DAY"], + [TimeInForce.GTC, "GTC"], + [TimeInForce.IOC, "IOC"], + [TimeInForce.FOK, "FOK"], + [TimeInForce.GTD, "GTD"]], + ) def test_time_in_force_to_str(self, enum, expected): # Arrange # Act result = TimeInForceParser.to_str_py(enum) # Assert - self.assertEqual(expected, result) - - @parameterized.expand([ - ["", TimeInForce.UNDEFINED], - ["UNDEFINED", TimeInForce.UNDEFINED], - ["DAY", TimeInForce.DAY], - ["GTC", TimeInForce.GTC], - ["IOC", TimeInForce.IOC], - ["FOK", TimeInForce.FOK], - ["GTD", TimeInForce.GTD], - ]) + assert expected == result + + @pytest.mark.parametrize( + "string, expected", + [["", TimeInForce.UNDEFINED], + ["UNDEFINED", TimeInForce.UNDEFINED], + ["DAY", TimeInForce.DAY], + ["GTC", TimeInForce.GTC], + ["IOC", TimeInForce.IOC], + ["FOK", TimeInForce.FOK], + ["GTD", TimeInForce.GTD]], + ) def test_time_in_force_from_str(self, string, expected): # Arrange # Act result = TimeInForceParser.from_str_py(string) # Assert - self.assertEqual(expected, result) + assert expected == result diff --git a/tests/unit_tests/model/test_model_events.py b/tests/unit_tests/model/test_model_events.py index 967d7654568d..08ebcb3dd5da 100644 --- a/tests/unit_tests/model/test_model_events.py +++ b/tests/unit_tests/model/test_model_events.py @@ -13,8 +13,6 @@ # limitations under the License. # ------------------------------------------------------------------------------------------------- -import unittest - from nautilus_trader.core.uuid import uuid4 from nautilus_trader.model.currencies import USD from nautilus_trader.model.currencies import USDT @@ -53,7 +51,7 @@ AUDUSD_SIM = TestInstrumentProvider.default_fx_ccy("AUD/USD") -class EventTests(unittest.TestCase): +class TestEvents: def test_account_state_str_repr(self): # Arrange @@ -70,10 +68,8 @@ def test_account_state_str_repr(self): # Act # Assert - self.assertEqual(f"AccountState(account_id=SIM-000, " - f"free=[1,525,000.00 USD], locked=[0.00 USD], event_id={uuid})", str(event)) - self.assertEqual(f"AccountState(account_id=SIM-000, " - f"free=[1,525,000.00 USD], locked=[0.00 USD], event_id={uuid})", repr(event)) + assert f"AccountState(account_id=SIM-000, free=[1,525,000.00 USD], locked=[0.00 USD], event_id={uuid})" == str(event) + assert f"AccountState(account_id=SIM-000, free=[1,525,000.00 USD], locked=[0.00 USD], event_id={uuid})" == repr(event) def test_order_initialized(self): # Arrange @@ -93,8 +89,8 @@ def test_order_initialized(self): # Act # Assert - self.assertEqual(f"OrderInitialized(cl_ord_id=O-2020872378423, strategy_id=SCALPER-001, event_id={uuid})", str(event)) - self.assertEqual(f"OrderInitialized(cl_ord_id=O-2020872378423, strategy_id=SCALPER-001, event_id={uuid})", repr(event)) + assert f"OrderInitialized(cl_ord_id=O-2020872378423, strategy_id=SCALPER-001, event_id={uuid})" == str(event) + assert f"OrderInitialized(cl_ord_id=O-2020872378423, strategy_id=SCALPER-001, event_id={uuid})" == repr(event) def test_order_invalid(self): # Arrange @@ -108,10 +104,8 @@ def test_order_invalid(self): # Act # Assert - self.assertEqual(f"OrderInvalid(cl_ord_id=O-2020872378423, " - f"reason='DUPLICATE_CL_ORD_ID', event_id={uuid})", str(event)) - self.assertEqual(f"OrderInvalid(cl_ord_id=O-2020872378423, " - f"reason='DUPLICATE_CL_ORD_ID', event_id={uuid})", repr(event)) + assert f"OrderInvalid(cl_ord_id=O-2020872378423, reason='DUPLICATE_CL_ORD_ID', event_id={uuid})" == str(event) + assert f"OrderInvalid(cl_ord_id=O-2020872378423, reason='DUPLICATE_CL_ORD_ID', event_id={uuid})" == repr(event) def test_order_denied(self): # Arrange @@ -124,10 +118,8 @@ def test_order_denied(self): ) # Act - self.assertEqual(f"OrderDenied(cl_ord_id=O-2020872378423, " - f"reason='SINGLE_ORDER_RISK_EXCEEDED', event_id={uuid})", str(event)) - self.assertEqual(f"OrderDenied(cl_ord_id=O-2020872378423, " - f"reason='SINGLE_ORDER_RISK_EXCEEDED', event_id={uuid})", repr(event)) + assert f"OrderDenied(cl_ord_id=O-2020872378423, reason='SINGLE_ORDER_RISK_EXCEEDED', event_id={uuid})", str(event) + assert f"OrderDenied(cl_ord_id=O-2020872378423, reason='SINGLE_ORDER_RISK_EXCEEDED', event_id={uuid})", repr(event) def test_order_submitted(self): # Arrange @@ -141,10 +133,8 @@ def test_order_submitted(self): ) # Act - self.assertEqual(f"OrderSubmitted(account_id=SIM-000, " - f"cl_ord_id=O-2020872378423, event_id={uuid})", str(event)) - self.assertEqual(f"OrderSubmitted(account_id=SIM-000, " - f"cl_ord_id=O-2020872378423, event_id={uuid})", repr(event)) + assert f"OrderSubmitted(account_id=SIM-000, cl_ord_id=O-2020872378423, event_id={uuid})", str(event) + assert f"OrderSubmitted(account_id=SIM-000, cl_ord_id=O-2020872378423, event_id={uuid})", repr(event) def test_order_rejected(self): # Arrange @@ -159,10 +149,8 @@ def test_order_rejected(self): ) # Act - self.assertEqual(f"OrderRejected(account_id=SIM-000, cl_ord_id=O-2020872378423, " - f"reason='INSUFFICIENT_MARGIN', event_id={uuid})", str(event)) # noqa - self.assertEqual(f"OrderRejected(account_id=SIM-000, cl_ord_id=O-2020872378423, " - f"reason='INSUFFICIENT_MARGIN', event_id={uuid})", repr(event)) # noqa + assert f"OrderRejected(account_id=SIM-000, cl_ord_id=O-2020872378423, reason='INSUFFICIENT_MARGIN', event_id={uuid})", str(event) # noqa + assert f"OrderRejected(account_id=SIM-000, cl_ord_id=O-2020872378423, reason='INSUFFICIENT_MARGIN', event_id={uuid})", repr(event) # noqa def test_order_accepted(self, order_id=None): if order_id is None: @@ -180,10 +168,8 @@ def test_order_accepted(self, order_id=None): ) # Act - self.assertEqual(f"OrderAccepted(account_id=SIM-000, cl_ord_id=O-2020872378423, " - f"order_id={123456}, event_id={uuid})", str(event)) # noqa - self.assertEqual(f"OrderAccepted(account_id=SIM-000, cl_ord_id=O-2020872378423, " - f"order_id={123456}, event_id={uuid})", repr(event)) # noqa + assert f"OrderAccepted(account_id=SIM-000, cl_ord_id=O-2020872378423, order_id={123456}, event_id={uuid})", str(event) # noqa + assert f"OrderAccepted(account_id=SIM-000, cl_ord_id=O-2020872378423, order_id={123456}, event_id={uuid})", repr(event) # noqa def test_order_cancel_reject(self): # Arrange @@ -200,12 +186,12 @@ def test_order_cancel_reject(self): ) # Act - self.assertEqual(f"OrderCancelReject(account_id=SIM-000, cl_ord_id=O-2020872378423, " - f"response_to=O-2020872378423, reason='ORDER_DOES_NOT_EXIST', " - f"event_id={uuid})", str(event)) - self.assertEqual(f"OrderCancelReject(account_id=SIM-000, cl_ord_id=O-2020872378423, " - f"response_to=O-2020872378423, reason='ORDER_DOES_NOT_EXIST', " - f"event_id={uuid})", repr(event)) + assert (f"OrderCancelReject(account_id=SIM-000, cl_ord_id=O-2020872378423, " + f"response_to=O-2020872378423, reason='ORDER_DOES_NOT_EXIST', " + f"event_id={uuid})" == str(event)) + assert (f"OrderCancelReject(account_id=SIM-000, cl_ord_id=O-2020872378423, " + f"response_to=O-2020872378423, reason='ORDER_DOES_NOT_EXIST', " + f"event_id={uuid})" == repr(event)) def test_order_cancelled(self): # Arrange @@ -220,10 +206,10 @@ def test_order_cancelled(self): ) # Act - self.assertEqual(f"OrderCancelled(account_id=SIM-000, cl_ord_id=O-2020872378423, " - f"order_id=123456, event_id={uuid})", str(event)) - self.assertEqual(f"OrderCancelled(account_id=SIM-000, cl_ord_id=O-2020872378423, " - f"order_id=123456, event_id={uuid})", repr(event)) + assert (f"OrderCancelled(account_id=SIM-000, cl_ord_id=O-2020872378423, " + f"order_id=123456, event_id={uuid})" == str(event)) + assert (f"OrderCancelled(account_id=SIM-000, cl_ord_id=O-2020872378423, " + f"order_id=123456, event_id={uuid})" == repr(event)) def test_order_amended(self): # Arrange @@ -240,10 +226,10 @@ def test_order_amended(self): ) # Act - self.assertEqual(f"OrderAmended(account_id=SIM-000, cl_order_id=O-2020872378423, " - f"order_id=123456, qty=500,000, price=1.95000, event_id={uuid})", str(event)) - self.assertEqual(f"OrderAmended(account_id=SIM-000, cl_order_id=O-2020872378423, " - f"order_id=123456, qty=500,000, price=1.95000, event_id={uuid})", repr(event)) + assert (f"OrderAmended(account_id=SIM-000, cl_order_id=O-2020872378423, " + f"order_id=123456, qty=500,000, price=1.95000, event_id={uuid})" == str(event)) + assert (f"OrderAmended(account_id=SIM-000, cl_order_id=O-2020872378423, " + f"order_id=123456, qty=500,000, price=1.95000, event_id={uuid})" == repr(event)) def test_order_expired(self): # Arrange @@ -258,10 +244,8 @@ def test_order_expired(self): ) # Act - self.assertEqual(f"OrderExpired(account_id=SIM-000, cl_ord_id=O-2020872378423, " - f"order_id=123456, event_id={uuid})", str(event)) - self.assertEqual(f"OrderExpired(account_id=SIM-000, cl_ord_id=O-2020872378423, " - f"order_id=123456, event_id={uuid})", repr(event)) + assert f"OrderExpired(account_id=SIM-000, cl_ord_id=O-2020872378423, order_id=123456, event_id={uuid})" == str(event) + assert f"OrderExpired(account_id=SIM-000, cl_ord_id=O-2020872378423, order_id=123456, event_id={uuid})" == repr(event) def test_order_filled(self): # Arrange @@ -289,13 +273,13 @@ def test_order_filled(self): ) # Act - self.assertEqual(f"OrderFilled(account_id=SIM-000, cl_ord_id=O-2020872378423, " - f"order_id=123456, position_id=2, strategy_id=SCALPER-001, " - f"security=BTC/USDT.BINANCE, side=BUY-MAKER, fill_qty=0.561000, " - f"fill_price=15600.12445 USDT, cum_qty=0.561000, leaves_qty=0, " - f"commission=12.20000000 USDT, event_id={uuid})", str(event)) # noqa - self.assertEqual(f"OrderFilled(account_id=SIM-000, cl_ord_id=O-2020872378423, " - f"order_id=123456, position_id=2, strategy_id=SCALPER-001, " - f"security=BTC/USDT.BINANCE, side=BUY-MAKER, fill_qty=0.561000, " - f"fill_price=15600.12445 USDT, cum_qty=0.561000, leaves_qty=0, " - f"commission=12.20000000 USDT, event_id={uuid})", repr(event)) # noqa + assert (f"OrderFilled(account_id=SIM-000, cl_ord_id=O-2020872378423, " + f"order_id=123456, position_id=2, strategy_id=SCALPER-001, " + f"security=BTC/USDT.BINANCE, side=BUY-MAKER, fill_qty=0.561000, " + f"fill_price=15600.12445 USDT, cum_qty=0.561000, leaves_qty=0, " + f"commission=12.20000000 USDT, event_id={uuid})" == str(event)) + assert (f"OrderFilled(account_id=SIM-000, cl_ord_id=O-2020872378423, " + f"order_id=123456, position_id=2, strategy_id=SCALPER-001, " + f"security=BTC/USDT.BINANCE, side=BUY-MAKER, fill_qty=0.561000, " + f"fill_price=15600.12445 USDT, cum_qty=0.561000, leaves_qty=0, " + f"commission=12.20000000 USDT, event_id={uuid})" == repr(event)) diff --git a/tests/unit_tests/model/test_model_identifiers.py b/tests/unit_tests/model/test_model_identifiers.py index b9ce541817d8..1ba1aabdd887 100644 --- a/tests/unit_tests/model/test_model_identifiers.py +++ b/tests/unit_tests/model/test_model_identifiers.py @@ -13,9 +13,7 @@ # limitations under the License. # ------------------------------------------------------------------------------------------------- -import unittest - -from parameterized import parameterized +import pytest from nautilus_trader.model.enums import AssetClass from nautilus_trader.model.enums import AssetType @@ -33,20 +31,22 @@ from nautilus_trader.model.identifiers import Venue -class IdentifierTests(unittest.TestCase): +class TestIdentifiers: - @parameterized.expand([ - [None, TypeError], - ["", ValueError], - [" ", ValueError], - [" ", ValueError], - [1234, TypeError], - ]) + @pytest.mark.parametrize( + "value, ex", + [[None, TypeError], + ["", ValueError], + [" ", ValueError], + [" ", ValueError], + [1234, TypeError]], + ) def test_instantiate_given_various_invalid_values_raises_exception(self, value, ex): # Arrange # Act # Assert - self.assertRaises(ex, Identifier, value) + with pytest.raises(ex): + Identifier(value) def test_equality(self): # Arrange @@ -56,10 +56,10 @@ def test_equality(self): # Act # Assert - self.assertTrue("abc123", id1.value) - self.assertTrue(id1 == id1) - self.assertTrue(id1 == id2) - self.assertTrue(id1 != id3) + assert "abc123" == id1.value + assert id1 == id1 + assert id1 == id2 + assert id1 != id3 def test_equality_of_subclass(self): # Arrange @@ -70,13 +70,13 @@ def test_equality_of_subclass(self): # Act # Assert - self.assertTrue(id1 == id1) - self.assertTrue(id2 == id2) - self.assertTrue(id1 == id2) - self.assertTrue(id2 == id1) - self.assertTrue(id1 != id3) - self.assertTrue(id2 != id3) - self.assertTrue(id2 != id4) + assert id1 == id1 + assert id2 == id2 + assert id1 == id2 + assert id2 == id1 + assert id1 != id3 + assert id2 != id3 + assert id2 != id4 def test_comparison(self): # Arrange @@ -87,13 +87,13 @@ def test_comparison(self): # Act # Assert - self.assertTrue(string1 <= string1) - self.assertTrue(string1 <= string2) - self.assertTrue(string1 < string2) - self.assertTrue(string2 > string1) - self.assertTrue(string2 >= string1) - self.assertTrue(string2 >= string2) - self.assertTrue(string3 <= string4) + assert string1 <= string1 + assert string1 <= string2 + assert string1 < string2 + assert string2 > string1 + assert string2 >= string1 + assert string2 >= string2 + assert string3 <= string4 def test_hash(self): # Arrange @@ -102,8 +102,8 @@ def test_hash(self): # Act # Assert - self.assertEqual(int, type(hash(identifier1))) - self.assertEqual(hash(identifier1), hash(identifier2)) + assert isinstance(hash(identifier1), int) + assert hash(identifier1) == hash(identifier2) def test_identifier_equality(self): # Arrange @@ -111,16 +111,9 @@ def test_identifier_equality(self): id2 = Identifier("some-id-2") # Act - result1 = id1 == id1 - result2 = id1 != id1 - result3 = id1 == id2 - result4 = id1 != id2 - # Assert - self.assertTrue(result1) - self.assertFalse(result2) - self.assertFalse(result3) - self.assertTrue(result4) + assert id1 == id1 + assert id1 != id2 def test_identifier_to_str(self): # Arrange @@ -130,7 +123,7 @@ def test_identifier_to_str(self): result = str(identifier) # Assert - self.assertEqual("some-id", result) + assert "some-id" == result def test_identifier_repr(self): # Arrange @@ -140,7 +133,7 @@ def test_identifier_repr(self): result = repr(identifier) # Assert - self.assertEqual("Identifier('some-id')", result) + assert "Identifier('some-id')" == result def test_mixed_identifier_equality(self): # Arrange @@ -149,26 +142,29 @@ def test_mixed_identifier_equality(self): # Act # Assert - self.assertTrue(id1 == id1) - self.assertFalse(id1 == id2) + assert id1 == id1 + assert id1 != id2 def test_account_id_given_malformed_string_raises_value_error(self): # Arrange # Act # Assert - self.assertRaises(ValueError, AccountId.from_str, "BAD_STRING") + with pytest.raises(ValueError): + AccountId.from_str("BAD_STRING") def test_strategy_id_given_malformed_string_raises_value_error(self): # Arrange # Act # Assert - self.assertRaises(ValueError, StrategyId.from_str, "BAD_STRING") + with pytest.raises(ValueError): + StrategyId.from_str("BAD_STRING") def test_trader_id_given_malformed_string_raises_value_error(self): # Arrange # Act # Assert - self.assertRaises(ValueError, TraderId.from_str, "BAD_STRING") + with pytest.raises(ValueError): + TraderId.from_str("BAD_STRING") def test_trader_identifier(self): # Arrange @@ -177,11 +173,11 @@ def test_trader_identifier(self): trader_id2 = TraderId("TESTER", "001") # Assert - self.assertEqual(trader_id1, trader_id1) - self.assertNotEqual(trader_id1, trader_id2) - self.assertEqual("TESTER-000", trader_id1.value) - self.assertEqual("TESTER", trader_id1.name) - self.assertEqual(trader_id1, TraderId.from_str("TESTER-000")) + assert trader_id1 == trader_id1 + assert trader_id1 != trader_id2 + assert "TESTER-000" == trader_id1.value + assert "TESTER" == trader_id1.name + assert trader_id1 == TraderId.from_str("TESTER-000") def test_strategy_identifier(self): # Arrange @@ -190,11 +186,11 @@ def test_strategy_identifier(self): strategy_id2 = StrategyId("SCALPER", "01") # Assert - self.assertEqual("NULL-NULL", strategy_id1.value) - self.assertEqual(strategy_id1, strategy_id1) - self.assertNotEqual(strategy_id1, strategy_id2) - self.assertEqual("NULL", strategy_id1.name) - self.assertEqual(strategy_id2, StrategyId.from_str('SCALPER-01')) + assert "NULL-NULL" == strategy_id1.value + assert strategy_id1 == strategy_id1 + assert strategy_id1 != strategy_id2 + assert "NULL" == strategy_id1.name + assert strategy_id2 == StrategyId.from_str('SCALPER-01') def test_account_identifier(self): # Arrange @@ -203,11 +199,11 @@ def test_account_identifier(self): account_id2 = AccountId("SIM", "09999999") # Assert - self.assertEqual(account_id1, account_id1) - self.assertNotEqual(account_id1, account_id2) - self.assertEqual("SIM-02851908", account_id1.value) - self.assertEqual(Issuer("SIM"), account_id1.issuer) - self.assertEqual(account_id1, AccountId("SIM", "02851908")) + assert account_id1 == account_id1 + assert account_id1 != account_id2 + assert "SIM-02851908", account_id1.value + assert Issuer("SIM") == account_id1.issuer + assert account_id1 == AccountId("SIM", "02851908") def test_position_identifier(self): # Arrange @@ -215,7 +211,7 @@ def test_position_identifier(self): position_id0 = PositionId.null() # Assert - self.assertEqual("NULL", position_id0.value) + assert "NULL" == position_id0.value def test_order_identifier(self): # Arrange @@ -223,10 +219,10 @@ def test_order_identifier(self): order_id = OrderId.null() # Assert - self.assertEqual("NULL", order_id.value) + assert "NULL" == order_id.value -class SecurityIdentifierTests(unittest.TestCase): +class TestSecurityIdentifier: def test_security_equality(self): # Arrange @@ -236,9 +232,9 @@ def test_security_equality(self): # Act # Assert - self.assertTrue(security1 == security1) - self.assertTrue(security1 != security2) - self.assertTrue(security1 != security3) + assert security1 == security1 + assert security1 != security2 + assert security1 != security3 def test_security_str(self): # Arrange @@ -246,7 +242,7 @@ def test_security_str(self): # Act # Assert - self.assertEqual("AUD/USD.SIM", str(security)) + assert "AUD/USD.SIM" == str(security) def test_security_repr(self): # Arrange @@ -254,7 +250,7 @@ def test_security_repr(self): # Act # Assert - self.assertEqual("Security('AUD/USD.SIM,FX,SPOT')", repr(security)) + assert "Security('AUD/USD.SIM,FX,SPOT')" == repr(security) def test_parse_security_from_str(self): # Arrange @@ -264,7 +260,7 @@ def test_parse_security_from_str(self): result = Security.from_serializable_str(security.to_serializable_str()) # Assert - self.assertEqual(security, result) + assert security == result # class SecurityIdentifierTests(unittest.TestCase): From 6df31f6b9af93d74716f94b75d77d8771a94bcc1 Mon Sep 17 00:00:00 2001 From: cjdsellers Date: Tue, 9 Mar 2021 21:49:01 +1100 Subject: [PATCH 2/2] Fix release --- .github/workflows/test-tag-publish.yml | 7 ++++++- RELEASES.md | 2 +- poetry.lock | 20 ++++++++++---------- pyproject.toml | 6 +++--- 4 files changed, 20 insertions(+), 15 deletions(-) diff --git a/.github/workflows/test-tag-publish.yml b/.github/workflows/test-tag-publish.yml index 7c5ea822138f..760bf967d88c 100644 --- a/.github/workflows/test-tag-publish.yml +++ b/.github/workflows/test-tag-publish.yml @@ -114,9 +114,14 @@ jobs: - name: Set output id: vars run: | + release = sed -n '/^#/,${p;/^---/q}' RELEASES.md + release="${release//'%'/'%25'}" + release="${release//$'\n'/'%0A'}" + release="${release//$'\r'/'%0D'}" + echo $release echo "::set-output name=tag_name::v$(poetry version --short)" echo "::set-output name=release_name::NautilusTrader $(poetry version --short) Beta" - echo "::set-output name=body::$(sed -n '/^#/,${p;/^---/q}' RELEASES.md)" + echo "::set-output name=body::$release" # Create GitHub release - name: Create release diff --git a/RELEASES.md b/RELEASES.md index f2e244f258a8..c084849421dc 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -1,4 +1,4 @@ -# NautilusTrader 1.108.0 Beta - Release Notes +# NautilusTrader 1.108.1 Beta - Release Notes This release executes a major refactoring of `Symbol` and how securities are generally identified within the platform. This will allow a smoother integration diff --git a/poetry.lock b/poetry.lock index d4dfacb9a585..3daf5431df00 100644 --- a/poetry.lock +++ b/poetry.lock @@ -109,7 +109,7 @@ pytz = ">=2015.7" [[package]] name = "ccxt" -version = "1.42.66" +version = "1.42.67" description = "A JavaScript / Python / PHP cryptocurrency trading library with support for 130+ exchanges" category = "main" optional = false @@ -310,7 +310,7 @@ nest-asyncio = "*" [[package]] name = "identify" -version = "2.1.0" +version = "2.1.1" description = "File identification library for Python" category = "dev" optional = false @@ -563,7 +563,7 @@ dev = ["pre-commit", "tox"] [[package]] name = "pre-commit" -version = "2.11.0" +version = "2.10.0" description = "A framework for managing and maintaining multi-language pre-commit hooks." category = "dev" optional = false @@ -1014,7 +1014,7 @@ docs = ["numpydoc"] [metadata] lock-version = "1.1" python-versions = "^3.7.9" -content-hash = "5e0aa35d5a64fca5aa08dd6f2807e188659ccf69a8c1a5761294b4cab7cedb9a" +content-hash = "49efff1b74d6228f11ab6df14b1c0179e1d3902b0ec6fb465d920e039f89496f" [metadata.files] aiodns = [ @@ -1093,8 +1093,8 @@ babel = [ {file = "Babel-2.9.0.tar.gz", hash = "sha256:da031ab54472314f210b0adcff1588ee5d1d1d0ba4dbd07b94dba82bde791e05"}, ] ccxt = [ - {file = "ccxt-1.42.66-py2.py3-none-any.whl", hash = "sha256:d0be50d4a1dee962de957b32751da4e95b9771a02d885aad45c94d5fd69ccfd5"}, - {file = "ccxt-1.42.66.tar.gz", hash = "sha256:e22bc25c990bde7f3cc077520e4f2ac6d92289e1e6e026b4c04d3f2feace8759"}, + {file = "ccxt-1.42.67-py2.py3-none-any.whl", hash = "sha256:01e69541fd92f314eda5c9f2f76ad1f9e12e1284721aca9155044370c507dab1"}, + {file = "ccxt-1.42.67.tar.gz", hash = "sha256:4790a52bf236b0a64c70602464f486518d937729da2cf66b017b445d52a829f4"}, ] certifi = [ {file = "certifi-2020.12.5-py2.py3-none-any.whl", hash = "sha256:719a74fb9e33b9bd44cc7f3a8d94bc35e4049deebe19ba7d8e108280cfd59830"}, @@ -1276,8 +1276,8 @@ ib-insync = [ {file = "ib_insync-0.9.65.tar.gz", hash = "sha256:7fe0bb294bb7a86414ebc0935a5f759ebb3b3abe903907b73ce0ba938a0c0510"}, ] identify = [ - {file = "identify-2.1.0-py2.py3-none-any.whl", hash = "sha256:2a5fdf2f5319cc357eda2550bea713a404392495961022cf2462624ce62f0f46"}, - {file = "identify-2.1.0.tar.gz", hash = "sha256:2179e7359471ab55729f201b3fdf7dc2778e221f868410fedcb0987b791ba552"}, + {file = "identify-2.1.1-py2.py3-none-any.whl", hash = "sha256:220169a38a0c977c8fef377dc808d6a3330641b5211ec7356c7bbe73cda487c7"}, + {file = "identify-2.1.1.tar.gz", hash = "sha256:da3d757c94596c50865aae63db6ba4e2e5e3f666c3ea6a6da0cd09a8b2d34abc"}, ] idna = [ {file = "idna-2.10-py2.py3-none-any.whl", hash = "sha256:b97d804b1e9b523befed77c48dacec60e6dcb0b5391d57af6a65a312a90648c0"}, @@ -1530,8 +1530,8 @@ pluggy = [ {file = "pluggy-0.13.1.tar.gz", hash = "sha256:15b2acde666561e1298d71b523007ed7364de07029219b604cf808bfa1c765b0"}, ] pre-commit = [ - {file = "pre_commit-2.11.0-py2.py3-none-any.whl", hash = "sha256:c4853e29c24b27d81359357fae891e00bc83e6a0575c93d815e0e8077bd53b3b"}, - {file = "pre_commit-2.11.0.tar.gz", hash = "sha256:06f8cb95e29e56788fb5dc98d7ca7a714969dc96633e1ba654ccd5953b64c195"}, + {file = "pre_commit-2.10.0-py2.py3-none-any.whl", hash = "sha256:391ed331fdd0a21d0be48c1b9919921e9d372dfd60f6dc77b8f01dd6b13161c1"}, + {file = "pre_commit-2.10.0.tar.gz", hash = "sha256:f413348d3a8464b77987e36ef6e02c3372dadb823edf0dfe6fb0c3dc2f378ef9"}, ] psutil = [ {file = "psutil-5.8.0-cp27-cp27m-macosx_10_9_x86_64.whl", hash = "sha256:0066a82f7b1b37d334e68697faba68e5ad5e858279fd6351c8ca6024e8d6ba64"}, diff --git a/pyproject.toml b/pyproject.toml index 367c18ef938f..c9c396412ea4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api" [tool.poetry] name = "nautilus_trader" -version = "1.108.0" +version = "1.108.1" description = "A high-performance algorithmic trading platform and event-driven backtester" authors = ["Nautech Systems "] license = "LGPL-3.0-or-later" @@ -33,7 +33,7 @@ generate-setup-file = false [tool.poetry.dependencies] python = "^3.7.9" -ccxt = "^1.42.66" +ccxt = "^1.42.67" cython = "^3.0a6" empyrical = "^0.5.5" ib_insync = "^0.9.65" @@ -61,7 +61,7 @@ flake8 = "^3.8.4" isort = "^5.7.0" nox = "^2020.12.31" parameterized = "^0.8.1" -pre-commit = "^2.11.0" +pre-commit = "2.10.0" pytest = "^6.2.2" pytest-cov = "^2.10.1" pytest-xdist = { version = "^2.2.0", extras = ["psutil"] }