Best Python code snippet using avocado_python
tmux_status.py
Source:tmux_status.py  
...39except:40  pass41## battery information42## TODO: maybe use the /sys/ filesystem to dig out this information?43if fs_exists("/sys/devices/LNXSYSTM:00/LNXSYBUS:00/PNP0C0A:00/power_supply/BAT0"):44  try:45    dmax = float(open("/sys/devices/LNXSYSTM:00/LNXSYBUS:00/PNP0C0A:00/power_supply/BAT0/charge_full_design").read().strip())46    cmax = float(open("/sys/devices/LNXSYSTM:00/LNXSYBUS:00/PNP0C0A:00/power_supply/BAT0/charge_full").read().strip())47    cur = float(open("/sys/devices/LNXSYSTM:00/LNXSYBUS:00/PNP0C0A:00/power_supply/BAT0/charge_now").read().strip())48    bstat = open("/sys/devices/LNXSYSTM:00/LNXSYBUS:00/PNP0C0A:00/power_supply/BAT0/status").read().strip()49  except:50    dmax = 1.051    cmax = 1.052    cur = 1.053    bstat = "-"54  if bstat == "Discharging":55    #h = cur/rate56    txt+="-"+str(round((cur/cmax)*100,2))+"%"57  elif bstat == "Charging":58    #h = (cmax-cur)/rate59    txt+="+"+str(round((cur/cmax)*100,2))+"%"   #str(int(h))+"."+str(int(60*(h-int(h))))60  elif bstat == "Full":61    txt+="="+str(round((cur/dmax)*100,2))+"%"62## data usage63if fs_exists("/var/local/datausage.dat"):64  try:65    txt += str(int(float(open("/var/local/datausage.dat","r").readline().split()[7])/1024/500*100))+"%"66  except:67    txt += "?%"68  ts = time.localtime()69  txt += "/%s%%" % (int((ts.tm_mday/31.0)*100))...test_path.py
Source:test_path.py  
1import unittest2from unittest.mock import MagicMock3from dxpy.filesystem import Path4from ruamel.yaml import YAML5yaml = YAML()6class TestPath(unittest.TestCase):7    def test_str_root(self):8        p = Path('/')9        self.assertEqual(p.abs, '/')10    def test_str_basic(self):11        p = Path('/tmp')12        self.assertEqual(p.abs, '/tmp')13    def test_url(self):14        p = Path('%2Ftmp')15        self.assertEqual(p.abs, '/tmp')16    def test_parts(self):17        p = Path('/tmp/base')18        self.assertEqual(p.parts, ('/', 'tmp', 'base'))19    def test_parent(self):20        p = Path('/tmp/base')21        self.assertEqual(p.father, '/tmp')22    def test_name(self):23        p = Path('/tmp/base')24        self.assertEqual(p.name, 'base')25    def test_name_dir(self):26        p = Path('/tmp/base/')27        self.assertEqual(p.name, 'base')28    @unittest.skip29    def test_brief(self):30        p = Path('/tmp/test')31        self.assertEqual(p.brief, {32            'name': 'test',33            'path': '/tmp/test'34        })35    @unittest.skip36    def test_detail(self):37        p = Path('/tmp/test')38        self.assertEqual(p.detail, {39            'name': 'test',40            'path': '/tmp/test',41            'parent': '/tmp',42            'url': '%2Ftmp%2Ftest',43            'suffix': '',44            'parts': ('/', 'tmp', 'test')45        })46    def test_exists(self):47        def postive():48            fs = MagicMock()49            fs_exists = MagicMock(return_value=True)50            fs.exists = fs_exists51            p = Path('/tmp/temp.txt')52            assert p.check_exists(fs) == True53        def negtive():54            fs = MagicMock()55            fs_exists = MagicMock(return_value=False)56            fs.exists = fs_exists57            p = Path('/tmp/temp.txt')58            assert p.check_exists(fs) == False59        postive()60        negtive()61    def test_copy_init(self):62        p = Path('/tmp/file')63        p2 = Path(p)64        assert p.abs == p2.abs65    def test_div(self):66        p = Path('/tmp')67        p = p / 'sub'68        assert p.abs == '/tmp/sub'69    @unittest.skip70    def test_yaml_dump(self):71        p = Path('/tmp/test')72        assert yaml.dump(p) == "!path '/tmp/test'\n"73    @unittest.skip74    def test_yaml_load(self):75        p = yaml.load("!path '/tmp/test'\n")...extfs_ext.py
Source:extfs_ext.py  
...26    # win_file takes care of windows27    if salt.utils.is_windows():28        return False29    return 'extfs'30def fs_exists(device):31    """32    Check to see if there is already a filesystem on the device33    CLI Example::34        salt '*' extfs.fs_exists /dev/sdj35        salt '*' extfs.fs_exists /dev/xvdj36    """37    cmd = 'dumpe2fs {0}'.format(device)38    out = __salt__['cmd.run'](cmd, python_shell=False)...Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
