Skip to content
Snippets Groups Projects
Select Git revision
  • c81621ec0b964740c5c41460098e563324a64b15
  • master default protected
  • fgh-updated-cw
  • cuda-solver-fix
  • fix-rocky-dockerfile
  • fgh-ba-mielchen
  • fgh-updated-base
  • i-nergy-ASM
  • emt-syngen-trstab
  • mnasolver-plugins
  • vs-signal-gen-follow-up-rebase6
  • fgh_cw_csv_sourcereader
  • sg-controllers
  • slew-scenarios-all-updated-villas
  • 4OrderSG-iter
  • SynGenModels
  • syngen-vbr-nicslu
  • slew-scenarios-all
  • slew-scenario-2
  • gh-actions
  • villas-interface
  • v1.0.0
  • v0.1.6
  • v0.1.5
  • v0.1.3
  • v0.1.1
  • v0.1.0
27 results

test_attribute.py

Blame
  • Steffen Vogel's avatar
    Steffen Vogel authored
    Former-commit-id: f7d82e7b
    c81621ec
    History
    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