Best Python code snippet using molecule_python
proof.py
Source:proof.py
...104 >>> MyRenamedAttr().target105 'target'106 """107 __metaclass__ = RenamingType108 class __rich__(Custom): pass109 @classmethod110 def test(klass, arg):111 return 'CLASSMETHOD %s ' % arg112class MyRenAttr(MyRenamedAttr):113 """114 >>> MyRenAttr().a115 'MyRenAttr'116 >>> MyRenAttr().target117 'target'118 >>> MyRenAttr.rich().a119 'MyRenAttr'120 >>> MyRenAttr.rich().target121 'custom'122 """123class MyRenAttrII(MyRenamedAttr):124 """125 >>> MyRenAttrII().a126 'MyRenAttrII'127 >>> MyRenAttrII().target128 'target'129 >>> MyRenAttrII.rich().a130 'MyRenAttrII'131 >>> MyRenAttrII.rich().target132 'SUCCESS'133 >>> MyRenAttrII().rich().a134 'MyRenAttrII'135 >>> MyRenAttrII().rich().target136 'SUCCESS'137 >>> MyRenAttrII().rich.a138 'MyRenAttrII'139 >>> MyRenAttrII().rich.target140 'SUCCESS'141 >>> MyRenAttrII.rich.a142 'MyRenAttrII'143 >>> MyRenAttrII.rich.target144 'SUCCESS'145 """146 class __rich__(Simple):147 target = "SUCCESS"148 @classmethod149 def test(klass, arg):150 return 'SPECIAL CLASSMETHOD %s ' % arg151class NullMeta(type):152 def __new__(meta, name, bases, dct):153 newdict = dct.copy()154 t = type.__new__(meta, name, bases, newdict)155 return t156 def __init__(clss, name, bases, dct):157 newdict = dct.copy()158 super(AttrMeta, clss).__init__(name, bases, newdict)159if __name__ == '__main__':160 import doctest...
gui.py
Source:gui.py
...28class Header:29 """30 Display header with clock.31 """32 def __rich__(self) -> Panel:33 """34 Setup of rich renderables.35 :return: Panel with the proper content to draw.36 """37 grid = Table.grid(expand=True)38 grid.add_column(justify="center", ratio=1)39 grid.add_column(justify="right")40 grid.add_row(41 "[b]Cart Manager[/b]",42 datetime.now().ctime().replace(":", "[blink]:[/]"),43 )44 grid.add_row(45 "[b]1:[/b] Create cart "46 "[b]2:[/b] Select cart "47 "[b]3:[/b] Add product "48 "[b]4:[/b] Delete cart "49 "[b]5:[/b] Exit"50 )51 return Panel(grid, title="Status", style="white on blue")52class Status:53 """54 Display status messages in footer.55 """56 def __init__(self, text: Text = Text("")):57 """58 Class initializer.59 :param text: Text to display.60 """61 self.text = text62 def __rich__(self) -> Panel:63 """64 Setup of rich renderables.65 :return: Panel with the proper content to draw.66 """67 grid = Table.grid(expand=True)68 grid.add_column(justify="left")69 grid.add_row(self.text)70 return Panel(grid, style="white on black")71class CartList:72 """73 Display the list of carts.74 """75 def __init__(self, carts: Optional[List[str]] = None, select: int = 0):76 """77 Class initializer.78 :param carts: List of carts.79 :param select: Cart to be selected.80 """81 self.select = select82 if carts:83 self.carts = carts84 else:85 self.carts = []86 def __rich__(self) -> Panel:87 """88 Setup of rich renderables.89 :return: Panel with the proper content to draw.90 """91 grid = Table.grid(expand=True)92 grid.add_column(justify="left")93 grid.add_column(justify="left", max_width=36)94 grid.add_row()95 if not self.carts:96 grid.add_row("", "[grey69]-- empty --[/grey69]")97 for index, cart_id in enumerate(self.carts):98 if index == self.select:99 # Highlights the selected cart100 text_cart_id = f"[white on grey69]{cart_id}[/white on grey69]"101 else:102 text_cart_id = f"{cart_id}"103 grid.add_row(f"{index + 1}", text_cart_id)104 return Panel(grid, title="Carts List", style="white on black")105class CartDetail:106 """107 Displays the products of a cart.108 """109 def __init__(self, products: List[str], total: str = "0.00"):110 """111 Class initializer.112 :param products: List of products.113 :param total: Total value of the cart.114 """115 self.products = products116 self.total = total117 def __rich__(self) -> Panel:118 """119 Setup of rich renderables.120 :return: Panel with the proper content to draw..121 """122 grid = Table.grid(expand=True)123 grid.add_column(justify="left", max_width=8)124 grid.add_column(justify="left")125 grid.add_row("Quantity", "Product", style="grey69")126 grid.add_row("--------", "-----------")127 for product, count in Counter(self.products).items():128 grid.add_row(f"{count:>8}", f"{product}")129 grid.add_row("", "")130 grid.add_row("--------", "-----------")131 grid.add_row("Total", f"{self.total}")...
cui.py
Source:cui.py
...18 for i in range(0, rows):19 self.field.append([])20 for j in range(0, cols):21 self.field[i].append(MockUnit())22 def __rich__(self) -> str:23 res = ""24 for x in range(0, self.rows):25 for y in range(0, self.cols):26 if x == self.cursor[0] and y == self.cursor[1]:27 res += "[on black]" + str(self.field[x][y]) + "[/on black]"28 else:29 res += self.field[x][y].__rich__()30 res += "\n"31 return res[:-1]32 def run(self) -> None:33 cmd = ""34 while True:35 os.system("cls")36 print(Panel.fit(self.__rich__()), end="")37 cmd = input("> ")38 if cmd == "q":39 break40 self.cursor_visible = True41 while True:42 if keyboard.is_pressed("a"):43 self.cursor[1] = max(0, self.cursor[1] - 1)44 os.system("cls")45 print(Panel.fit(self.__rich__()), end="")46 elif keyboard.is_pressed("d"):47 self.cursor[1] = min(self.rows - 1, self.cursor[1] + 1)48 os.system("cls")49 print(Panel.fit(self.__rich__()), end="")50 elif keyboard.is_pressed("w"):51 self.cursor[0] = max(0, self.cursor[0] - 1)52 os.system("cls")53 print(Panel.fit(self.__rich__()), end="")54 elif keyboard.is_pressed("s"):55 self.cursor[0] = min(self.cols - 1, self.cursor[0] + 1)56 os.system("cls")57 print(Panel.fit(self.__rich__()), end="")58 elif keyboard.is_pressed("f"):59 keyboard.press_and_release("enter")60 input()61 break62 time.sleep(0.1)63 self.cursor_visible = False64 return65class MockUnit:66 def __init__(self) -> None:67 self.char: str = " "68 self.color: str | None = None69 self.oncolor: str | None = None70 if random.randrange(1, 100) < 10:71 self.char = random.choice("ABCDEFGHIJKLMNOPQRSTUVWXYZ")72 self.color = random.choice(73 ["white", "black"],74 )75 self.oncolor = random.choice(["green", "grey37", "dark_blue"])76 else:77 (self.char, self.color, self.oncolor) = random.choice(78 [79 (" ", "blue", "green"),80 (" ", "grey69", "grey37"),81 (" ", "blue", "dark_blue"),82 ]83 )84 def __rich__(self) -> str:85 if self.color is not None:86 if self.oncolor is not None:87 return f"[{self.color} on {self.oncolor}]{self.char}[/]"88 else:89 return f"[{self.color}]{self.char}[/]"90 else:91 return self.char92 def __str__(self) -> str:...
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!!