Skip to content
Snippets Groups Projects
Select Git revision
  • 1af6e3eeafa725a55ebe77c2a07772a1c1c5d85b
  • main default protected
  • gitkeep
  • dev
  • ipynb
  • 81-add-id-to-figure-file-metadata
  • v0.3.2
  • v0.3.1
  • v0.3.0
  • v0.2.3
  • test_tag
  • v0.2.2
  • v.0.2.1
  • v0.2.1
  • v0.1.2
  • v0.1.1
  • v0.1.0
17 results

installation.rst

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    test_attribute.py 1.22 KiB
    import dpsim
    import pytest
    
    def test_read():
        gnd = dpsim.dp.Node.GND()
        c = dpsim.dp.ph1.Capacitor('c1', [gnd, gnd], C=1.234);
    
        assert c.C == 1.234
        assert c.name == 'c1'
    
    def test_write():
        gnd = dpsim.dp.Node.GND()
        c = dpsim.dp.ph1.Capacitor('c1', [gnd, gnd], C=1.234);
    
        c.C = 5
    
        assert c.C == 5
    
    def test_invalid():
        with pytest.raises(AttributeError) as e_info:
            gnd = dpsim.dp.Node.GND()
            c = dpsim.dp.ph1.Capacitor('c1', [gnd, gnd], C=1.234);
    
            # dp.Capacitor does not have an attribute named 'doesnotexist'
            # Accessing it should throw a AttributeError exception!
            x = c.doesnotexist
    
    def test_access():
        with pytest.raises(AttributeError) as e_info:
            gnd = dpsim.dp.Node.GND()
            c = dpsim.dp.ph1.Capacitor('c1', [gnd, gnd], C=1.234);
    
            # Current is a read-only property.
            # This should throw a AttributeError exception!
            c.current = 5
    
    def test_type():
        with pytest.raises(TypeError) as e_info:
            gnd = dpsim.dp.Node.GND()
            c = dpsim.dp.ph1.Capacitor('c1', [gnd, gnd], C=1.234);
    
            # Capacitance is a real valued property.
            # Assigning a complex number should throw a TypeError exception!
            c.C = 1j