コード例 #1
0
    def test_get_given_none_raises_value_error(self, value, ex):
        # Arrange
        cache = ObjectCache(InstrumentId, InstrumentId.from_str)

        # Act
        # Assert
        with pytest.raises(ex):
            cache.get(value)
コード例 #2
0
    def test_keys_when_cache_empty_returns_empty_list(self):
        # Arrange
        cache = ObjectCache(InstrumentId, InstrumentId.from_str)

        # Act
        result = cache.keys()

        # Assert
        assert [] == result
コード例 #3
0
    def test_cache_initialization(self):
        # Arrange
        cache = ObjectCache(Symbol, Symbol.from_str)

        # Act
        # Assert
        self.assertEqual(str, cache.type_key)
        self.assertEqual(Symbol, cache.type_value)
        self.assertEqual([], cache.keys())
コード例 #4
0
    def test_cache_initialization(self):
        # Arrange
        cache = ObjectCache(InstrumentId, InstrumentId.from_str)

        # Act
        # Assert
        assert str == cache.type_key
        assert InstrumentId == cache.type_value
        assert [] == cache.keys()
コード例 #5
0
    def test_keys_when_cache_empty_returns_empty_list(self):
        # Arrange
        cache = ObjectCache(Symbol, Symbol.from_str)

        # Act
        result = cache.keys()

        # Assert
        self.assertEqual([], result)
コード例 #6
0
    def test_cache_initialization(self):
        # Arrange
        cache = ObjectCache(InstrumentId, InstrumentId.from_str)

        # Act
        # Assert
        assert cache.type_key == str
        assert cache.type_value == InstrumentId
        assert cache.keys() == []
コード例 #7
0
    def test_get_from_empty_cache(self):
        # Arrange
        cache = ObjectCache(InstrumentId, InstrumentId.from_str)
        instrument_id = "AUD/USD.SIM,FX,SPOT"

        # Act
        result = cache.get(instrument_id)

        # Assert
        assert instrument_id == str(result)
        assert ["AUD/USD.SIM,FX,SPOT"] == cache.keys()
コード例 #8
0
    def test_get_from_empty_cache(self):
        # Arrange
        cache = ObjectCache(Symbol, Symbol.from_str)
        symbol = "AUD/USD.SIM"

        # Act
        result = cache.get(symbol)

        # Assert
        self.assertEqual(symbol, str(result))
        self.assertEqual(["AUD/USD.SIM"], cache.keys())
コード例 #9
0
    def test_can_get_from_empty_cache(self):
        # Arrange
        cache = ObjectCache(Symbol, Symbol.py_from_string)
        symbol = 'AUDUSD.FXCM'

        # Act
        result = cache.get(symbol)

        # Assert
        self.assertEqual(symbol, str(result))
        self.assertEqual(['AUDUSD.FXCM'], cache.keys())
コード例 #10
0
    def test_get_given_none_raises_value_error(self, value, ex):
        # Arrange
        cache = ObjectCache(Symbol, Symbol.from_str)

        # Act
        # Assert
        self.assertRaises(ex, cache.get, value)
コード例 #11
0
    def test_clear_cache(self):
        # Arrange
        cache = ObjectCache(InstrumentId, InstrumentId.from_str)
        instrument_id = "AUD/USD.SIM,FX,SPOT"
        cache.get(instrument_id)

        # Act
        cache.clear()

        # Assert
        assert [] == cache.keys()
コード例 #12
0
    def test_clear_cache(self):
        # Arrange
        cache = ObjectCache(Symbol, Symbol.from_str)
        symbol = "AUD/USD.SIM"
        cache.get(symbol)

        # Act
        cache.clear()

        # Assert
        self.assertEqual([], cache.keys())
コード例 #13
0
    def test_can_clear_cache(self):
        # Arrange
        cache = ObjectCache(Symbol, Symbol.py_from_string)
        symbol = 'AUDUSD.FXCM'
        cache.get(symbol)

        # Act
        cache.clear()

        # Assert
        self.assertEqual([], cache.keys())
コード例 #14
0
    def test_get_from_cache(self):
        # Arrange
        cache = ObjectCache(InstrumentId, InstrumentId.from_str)
        instrument_id = "AUD/USD.SIM,FX,SPOT"
        cache.get(instrument_id)

        # Act
        cache.get(instrument_id)
        result1 = cache.get(instrument_id)
        result2 = cache.get(instrument_id)

        # Assert
        assert instrument_id == str(result1)
        assert id(result1) == id(result2)
        assert ["AUD/USD.SIM,FX,SPOT"] == cache.keys()
コード例 #15
0
    def test_get_from_cache(self):
        # Arrange
        cache = ObjectCache(Symbol, Symbol.from_str)
        symbol = "AUD/USD.SIM"
        cache.get(symbol)

        # Act
        cache.get(symbol)
        result1 = cache.get(symbol)
        result2 = cache.get(symbol)

        # Assert
        self.assertEqual(symbol, str(result1))
        self.assertEqual(id(result1), id(result2))
        self.assertEqual(["AUD/USD.SIM"], cache.keys())
コード例 #16
0
    def test_can_get_from_cache(self):
        # Arrange
        cache = ObjectCache(Symbol, Symbol.py_from_string)
        symbol = 'AUDUSD.FXCM'
        cache.get(symbol)

        # Act
        cache.get(symbol)
        result1 = cache.get(symbol)
        result2 = cache.get(symbol)

        # Assert
        self.assertEqual(symbol, str(result1))
        self.assertEqual(id(result1), id(result2))
        self.assertEqual(['AUDUSD.FXCM'], cache.keys())