
import unittest
import os

from pyrpl import RedPitaya


class RedPitayaTestCases(unittest.TestCase):

    def setUp(self):
        self.hostname = os.environ.get('REDPITAYA')

    def tearDown(self):
        pass

    def test_hostname(self):
        self.assertIsNotNone(
            self.hostname,
            msg="Set REDPITAYA=localhost or the ip of your board to proceed!")
        
    def test_connect(self):
        if self.hostname != "localhost":
            r = RedPitaya(hostname=self.hostname)
            self.assertEqual(r.hk.led, 0)
    

import unittest
import os

from pyrpl import RedPitaya


class RedPitayaTestCases(unittest.TestCase):

    def setUp(self):
        self.hostname = os.environ.get('REDPITAYA')
        self.password = os.environ.get('RP_PASSWORD') or 'root'

    def tearDown(self):
        pass

    def test_hostname(self):
        self.assertIsNotNone(
            self.hostname,
            msg="Set REDPITAYA=localhost or the ip of your board to proceed!")

    def test_password(self):
        self.assertIsNotNone(
            self.password,
            msg="Set RP_PASSWORD=<your redpitaya password> to proceed!")
        
    def test_connect(self):
        if self.hostname != "localhost":
            r = RedPitaya(hostname=self.hostname, password=self.password)
            self.assertEqual(r.hk.led, 0)
    
Update test_connect to read password from env. variable
Update test_connect to read password from env. variable

  
  import unittest
  import os
  
  from pyrpl import RedPitaya
  
  
  class RedPitayaTestCases(unittest.TestCase):
  
      def setUp(self):
          self.hostname = os.environ.get('REDPITAYA')
+         self.password = os.environ.get('RP_PASSWORD') or 'root'
  
      def tearDown(self):
          pass
  
      def test_hostname(self):
          self.assertIsNotNone(
              self.hostname,
              msg="Set REDPITAYA=localhost or the ip of your board to proceed!")
+ 
+     def test_password(self):
+         self.assertIsNotNone(
+             self.password,
+             msg="Set RP_PASSWORD=<your redpitaya password> to proceed!")
          
      def test_connect(self):
          if self.hostname != "localhost":
-             r = RedPitaya(hostname=self.hostname)
+             r = RedPitaya(hostname=self.hostname, password=self.password)
              self.assertEqual(r.hk.led, 0)
      
Update test_connect to read password from env. variable
## Code Before:

import unittest
import os

from pyrpl import RedPitaya


class RedPitayaTestCases(unittest.TestCase):

    def setUp(self):
        self.hostname = os.environ.get('REDPITAYA')

    def tearDown(self):
        pass

    def test_hostname(self):
        self.assertIsNotNone(
            self.hostname,
            msg="Set REDPITAYA=localhost or the ip of your board to proceed!")
        
    def test_connect(self):
        if self.hostname != "localhost":
            r = RedPitaya(hostname=self.hostname)
            self.assertEqual(r.hk.led, 0)
    
## Instruction:
Update test_connect to read password from env. variable
## Code After:

import unittest
import os

from pyrpl import RedPitaya


class RedPitayaTestCases(unittest.TestCase):

    def setUp(self):
        self.hostname = os.environ.get('REDPITAYA')
        self.password = os.environ.get('RP_PASSWORD') or 'root'

    def tearDown(self):
        pass

    def test_hostname(self):
        self.assertIsNotNone(
            self.hostname,
            msg="Set REDPITAYA=localhost or the ip of your board to proceed!")

    def test_password(self):
        self.assertIsNotNone(
            self.password,
            msg="Set RP_PASSWORD=<your redpitaya password> to proceed!")
        
    def test_connect(self):
        if self.hostname != "localhost":
            r = RedPitaya(hostname=self.hostname, password=self.password)
            self.assertEqual(r.hk.led, 0)
    