From patchwork Wed Jan 25 09:01:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tobias Schaffner X-Patchwork-Id: 2533 Return-Path: Received: from shymkent.ilbers.de ([unix socket]) by shymkent (Cyrus 2.5.10-Debian-2.5.10-3+deb9u2) with LMTPA; Wed, 25 Jan 2023 10:02:36 +0100 X-Sieve: CMU Sieve 2.4 Received: from mail-ed1-f57.google.com (mail-ed1-f57.google.com [209.85.208.57]) by shymkent.ilbers.de (8.15.2/8.15.2/Debian-8+deb9u1) with ESMTPS id 30P92as5026065 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 25 Jan 2023 10:02:36 +0100 Received: by mail-ed1-f57.google.com with SMTP id z18-20020a05640235d200b0049d84165065sf12543419edc.18; Wed, 25 Jan 2023 01:02:36 -0800 (PST) ARC-Seal: i=3; a=rsa-sha256; t=1674637350; cv=pass; d=google.com; s=arc-20160816; b=pGPs/O0iUfJIkHpcVZMYZPmiEN8+cgZ+WX31tzwCC7P9QeqxfdT+bTrViUdjGcGlU0 vnJabITubg9g7OhQgf83eBzzmXTL2U37A5N3sab47NqxuSsYnPQyg+TYltxH9S09Ppy+ HakpkEMbWk0OKb5WiiI3huvtlvy9V8YhT0Jt2Gao3T0U1ZQbWxG4IFtfOLv9RkNvNg6q yldkjhum7z/F1eUaMlygClGlAquPo9nzikHtxYL7jCGU/SSTJ1ouVV2wWTjcVkiqOHqm nHd5Ui7Z257XdkJoAD7F5ZebpNXLMK/Wo6CaB3omWZMjFyLZ/YpXyizl68UkEVXCVUTU nSvg== ARC-Message-Signature: i=3; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:dkim-signature; bh=WGUVXVJqnJg78fi/tTReP8XvnR04GE7e/9eUnCef4GY=; b=Gc31q2EU3BQUy2hKJX7wjaVVCv4TbL4f4O7dBjQGKgwvFFTcg4orSEobG6TkJtkSP9 7eGeFFVO2NtGFS2LHt1WixHMNUVhgR9+nS8pvu16hsMDP5PySIfB3pzzlZdrLwWHo6Xf rSFeOClkEf2sAHmwVEwD+fW36+XnfxkwMD4Xiz/5DOOL8b3hi/H1h8eek3fdqj6gkcTP jAQF2oZ86i1dGyx2o5loWF9FTVhgq5SzVPA2YQWzIP8oMO6KIRR4RtLE8kcdBGbqtrJH SNWX2uKUhIUsMH9Rnf1N6OLdqrgbwStQHj7x4Tln3nP8H3cO/laP/apXAnqcgYB5a0s8 oHHQ== ARC-Authentication-Results: i=3; gmr-mx.google.com; dkim=pass header.i=@siemens.com header.s=selector2 header.b=SRGxhRG5; arc=pass (i=1 spf=pass spfdomain=siemens.com dmarc=pass fromdomain=siemens.com); spf=pass (google.com: domain of tobias.schaffner@siemens.com designates 40.107.13.74 as permitted sender) smtp.mailfrom=tobias.schaffner@siemens.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=siemens.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20210112; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:x-original-authentication-results :x-original-sender:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:sender:from:to:cc:subject:date:message-id :reply-to; bh=WGUVXVJqnJg78fi/tTReP8XvnR04GE7e/9eUnCef4GY=; b=NjQ0BpGb6dlLkfTlP3C/wPBHfWSdvXJK2rLEsbQPoBDp00+TNWNdx69dRxx+klhrqL KYqs2dwGrWC8ZV6wTD9FJmvoMiI/WsLoHN0w878TEsmLmIAA/KsRteoO6v9YIX21Kiqg mEC8Uni+Fb1BhnMXAseOsLCnhN/6sf+17kz94zDmBl7UjRiDXxKKTBnu9xPKaI7nyWrm dj4s3BjJGgCZ91ENTM4S7FA0VvUSDqNAmM7mHBaz2IrrU1dV0SedV0GVnm4isNs1BiH4 Bmg+AwOfFqvWLJdz0Xm5jlTRJcyM7pX4WW78xRhGvlvgKkO2XN5NftpZSkfR4j7uxgyi CB3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :x-spam-checked-in-group:list-id:mailing-list:precedence :x-original-authentication-results:x-original-sender:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :x-gm-message-state:sender:from:to:cc:subject:date:message-id :reply-to; bh=WGUVXVJqnJg78fi/tTReP8XvnR04GE7e/9eUnCef4GY=; b=jxeAElf0BBzybaYFEJlKJfdSQ/x72K2hij6Z6gMqljjOm72saEnGnkC/DLapJGesaQ FZ/aBsu9Wf9mfWoB9bm9Zo6JoE/eDZv7VWuz4iUESuKGtRbqlCaZkGnmlMj4en6JN3cN djhPpvUuoxPiXK1J5+rkO6txaQ7xnxZAgehbqhhieI+HrUEbUX3r2bgsFj1EarW/8nyW ZA83T3U/ckqQDmIcMxu/RmGDLJZx0+WvgAKzjIponzBYZ7PHX4m0w4FOI7czlMtKOtRR QrgzvvI8JX3lUOoZF56ovIhiMmg/QTsBislfz2slY9C1uCIyrbFNlpoTOduMCUOGpv7A rrAg== Sender: isar-users@googlegroups.com X-Gm-Message-State: AFqh2kpPRGEk1oVFmF42BVXjCt++JnY4yMsZfKg4HFmtDAF5KaLSFbZc QWBD1QQtxxlbEdNK2RZSyRI= X-Google-Smtp-Source: AMrXdXvszoRt0C/Jl5yx1FY5HgW5MyTqsyX6E3mrELW7vgfrRmpbKRMvYNE5SG50cxUY2ajwRUlzIw== X-Received: by 2002:aa7:dbc1:0:b0:49e:1e:14b1 with SMTP id v1-20020aa7dbc1000000b0049e001e14b1mr3905348edt.6.1674637350769; Wed, 25 Jan 2023 01:02:30 -0800 (PST) X-BeenThere: isar-users@googlegroups.com Received: by 2002:a05:6402:270a:b0:49e:5b8c:71c4 with SMTP id y10-20020a056402270a00b0049e5b8c71c4ls3042010edd.3.-pod-prod-gmail; Wed, 25 Jan 2023 01:02:29 -0800 (PST) X-Received: by 2002:aa7:db4c:0:b0:49f:28ff:124e with SMTP id n12-20020aa7db4c000000b0049f28ff124emr6848304edt.35.1674637349823; Wed, 25 Jan 2023 01:02:29 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1674637349; cv=pass; d=google.com; s=arc-20160816; b=OHg6g8r9szY2eDW5dFHEksFP8wd+qjHA/m0dZE3TNY/z0yGXlRbkoazFlXEdT2MOMk GFEaVwQki+xOQdZMRiDCsVTqxg7+D0wLU8JXEV1KnyG2L5g0CSyX36aa3th7JZc4NpPL +YQd+fHysyYjXxRqcx6A0D+CdqDyL/FBCri+3rTh6nd2bZ+Rg5UOxqnrzOBBhT5ZQJLN CeKVsSAx9QgFB3mrpyYlurv2f6XiTCVWkhlUcGW+fuffMI6s+SKorat//SQWs9qcmkQ3 nqSF1I6cg6WNal0BhEHt9caBOuF0YTGnKB33bCNiGT5RQyN9IU19FKj4Ln6TZ1pyBsaC hn0A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=iB4lqI/m9fzy0bIh2qGVzX6wNMf25pqvc/tjFz+DjPM=; b=F842/Sc/Cz33NwRRP12Vl5DoYG+g+rF2PYUI7DXhXcs0y/4G7oz7TFchU14o77jik+ 4M1BWdzBBULRgoklBqfTdxjmjRm+zQeLZ/rVXfeo4vc9vcWd2EcYb80kqb2K+3p+YvOb ek1ukJyKXyWLeWPDlvhh9XtfHyy3/Yzv1/0I7AFofyXlCrnHr9KI+eRB4Y88A8gSzOyT 4BOOzKSp4cD9r3f40xcMTtHkiTnvlqk1CkXFHshVZjfqCW6C1cZiXfCvleou5lJqAJpY fU8OkXNOaHDko5HoI6lI1wQLKcMgMViMLPwqmLuVPZzLPs2i60GJvotakU612pEvQCsX LZ1A== ARC-Authentication-Results: i=2; gmr-mx.google.com; dkim=pass header.i=@siemens.com header.s=selector2 header.b=SRGxhRG5; arc=pass (i=1 spf=pass spfdomain=siemens.com dmarc=pass fromdomain=siemens.com); spf=pass (google.com: domain of tobias.schaffner@siemens.com designates 40.107.13.74 as permitted sender) smtp.mailfrom=tobias.schaffner@siemens.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=siemens.com Received: from EUR01-HE1-obe.outbound.protection.outlook.com (mail-he1eur01on2074.outbound.protection.outlook.com. [40.107.13.74]) by gmr-mx.google.com with ESMTPS id d28-20020a056402401c00b0049ecd39787fsi229683eda.5.2023.01.25.01.02.29 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 25 Jan 2023 01:02:29 -0800 (PST) Received-SPF: pass (google.com: domain of tobias.schaffner@siemens.com designates 40.107.13.74 as permitted sender) client-ip=40.107.13.74; ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=doB0puJoAfzAJ/hfI9Jkb30FtQVFQ1LoaTmnE6xUQfcR9zw+btMKsWkPcQSkRhgPgskQTAw33nM4MIwmPibUTc+RcumHtC4G14Asx4OY1FuCbxgvNGiUNNXqVdUPf5psLbexT8ae/sX2vUYvTdaUudbH8ooRVVKLzeOyGHEolVdkq0Smxfve+n9VEpRtELoErCiaMfEYfyUpSMEaj0ahvuwPVjGcYrMrDgQz3Zd9gja/bDC+eoV6dRzeF33lRW4C6cCNFQYoLZS5NPdreEyAR1d0IjoaO03uBxGn/9sqBcP2xZSdBUlkCPigkbn9l18QhWcLDCDEmReJpkCO6bI5uw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=iB4lqI/m9fzy0bIh2qGVzX6wNMf25pqvc/tjFz+DjPM=; b=TEbiKPdMxyIW8LKcq46gj4oOfZS4JSDKjHo23B0fbupTyToH20+PoOzJ2PmkrDud4cA1DNQcEMJq95BbgNSqSannp5L9cY6HH0kZax8aSh8LZsAgw4Hwrhpu0pdxsoqwCDbbIkByg9qxkT/ke39Fu7aTF31uDRhKx9uPX01ILyY0qQKbVa9Kqfzjxaka2QWGAWhJNW5ykqo+wArZ3Sa7atyjAGTyTjWktderSzyRXqSIHgg5522NFckZOANC9A9M0k/hY2I+x37eSmtiC+w+Ntz5U95eCjI31Fh4X2weHqIHpbRZH9X+hr7iGKRNvzDHLM5f13YDKSmW4oQwNrexYQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 194.138.21.75) smtp.rcpttodomain=googlegroups.com smtp.mailfrom=siemens.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=siemens.com; dkim=none (message not signed); arc=none Received: from ZR2P278CA0050.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:53::10) by PA4PR10MB5587.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:102:261::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6002.33; Wed, 25 Jan 2023 09:02:28 +0000 Received: from VE1EUR01FT015.eop-EUR01.prod.protection.outlook.com (2603:10a6:910:53:cafe::6a) by ZR2P278CA0050.outlook.office365.com (2603:10a6:910:53::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6002.33 via Frontend Transport; Wed, 25 Jan 2023 09:02:27 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 194.138.21.75) smtp.mailfrom=siemens.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=siemens.com; Received-SPF: Pass (protection.outlook.com: domain of siemens.com designates 194.138.21.75 as permitted sender) receiver=protection.outlook.com; client-ip=194.138.21.75; helo=hybrid.siemens.com; pr=C Received: from hybrid.siemens.com (194.138.21.75) by VE1EUR01FT015.mail.protection.outlook.com (10.152.2.237) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6043.17 via Frontend Transport; Wed, 25 Jan 2023 09:02:27 +0000 Received: from DEMCHDC8WAA.ad011.siemens.net (139.25.226.104) by DEMCHDC8VRA.ad011.siemens.net (194.138.21.75) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.20; Wed, 25 Jan 2023 10:02:25 +0100 Received: from L15-Gen2.fritz.box (139.21.146.184) by DEMCHDC8WAA.ad011.siemens.net (139.25.226.104) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.20; Wed, 25 Jan 2023 10:02:25 +0100 From: "T. Schaffner" To: CC: , , "Tobias Schaffner" Subject: [PATCH 3/5] create a minimal python unittest infrastructure Date: Wed, 25 Jan 2023 10:01:54 +0100 Message-ID: <20230125090156.284309-4-tobias.schaffner@siemens.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230125090156.284309-1-tobias.schaffner@siemens.com> References: <20230125090156.284309-1-tobias.schaffner@siemens.com> MIME-Version: 1.0 X-Originating-IP: [139.21.146.184] X-ClientProxiedBy: DEMCHDC8WBA.ad011.siemens.net (139.25.226.105) To DEMCHDC8WAA.ad011.siemens.net (139.25.226.104) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: VE1EUR01FT015:EE_|PA4PR10MB5587:EE_ X-MS-Office365-Filtering-Correlation-Id: f9362258-e865-4e5f-d355-08dafeb2e1e6 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: jZ8WVhXwa69cmTLlh8B5TVfDyjNBs9uish5Y2bdPixthCUaBc1QSJ4BsMuQJMARQ7wUaQ/61JvU9nnIfc0rdfiFNGKe59FHVgfMy9dmqOfOBfSZgkpN3iIa3EnA3u6GSL8TIem0w2tjpOoFaKfHObQiAa2/i5rj5eloMEJ5E38h066fpZecmAc/vJ4GgS/F+JQ1itAzYoJQVoRNKb4skEG4MYl5uJKg5Mf8MLkjBfA7d1mwPr0fAOjPV18zGTZ6mqBs6SPxLbfB3BroBbaIcaa/ErOR/FtRvSeXIuhRFldh1QzTVr6+X8caF8dFrFq7nlWDyg5+cZNowIFUakmyw3zHfg5nXMlUXmLt9VfGCTC1Pu0puZZzw2UWfFCsushMKBV3/5Xij4wQ7uvP15Z68mjaYW2/GacUHBvJzi87DXw2p+XEkJSIzct/ppjAm6I7TWod+Pe9j68/Z8XZhf11KoWR17qiGs9z/XyUtcl+30lWNdzYc1ME8vygm/j0Q2oZj8eeIbnyVVbuCRBN0PB5xxBsX1eQpza8FWMhvuDAU08czMRQG5QQ09JGO8NMMex2lBaNpFIM5J0vE+NWBDTzKy9wOueZhXQBFnQ76h6N7XmJxd4FX/cwy1Idxpx+DWdP04a1yacg/BNW5bqJYzNorLivg9+zkUU+bwU2tdiK4PLVkflsbzYs5EUyFeE9bmQtOQDXJQZ3a9aJS5B823vrd0yT5TeGbdOyPEirj/TNQ+kyoruxrZmw2hkjs2rU46GenpAzAKC4dm0zIU1WQBf93qKDnfqn0mlCbfkhHBiqyQ9z+PkiPQ0kh8NGvbF9qlWvG X-Forefront-Antispam-Report: CIP:194.138.21.75;CTRY:DE;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:hybrid.siemens.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230025)(4636009)(39860400002)(346002)(396003)(136003)(376002)(451199018)(36840700001)(46966006)(40470700004)(1076003)(82310400005)(316002)(40460700003)(336012)(40480700001)(86362001)(36756003)(54906003)(81166007)(8936002)(70206006)(82740400003)(82960400001)(36860700001)(5660300002)(41300700001)(47076005)(2906002)(70586007)(478600001)(107886003)(16526019)(26005)(356005)(8676002)(4326008)(6666004)(2616005)(186003)(956004)(6916009)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: siemens.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Jan 2023 09:02:27.1950 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f9362258-e865-4e5f-d355-08dafeb2e1e6 X-MS-Exchange-CrossTenant-Id: 38ae3bcd-9579-4fd4-adda-b42e1495d55a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=38ae3bcd-9579-4fd4-adda-b42e1495d55a;Ip=[194.138.21.75];Helo=[hybrid.siemens.com] X-MS-Exchange-CrossTenant-AuthSource: VE1EUR01FT015.eop-EUR01.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA4PR10MB5587 X-Original-Sender: tobias.schaffner@siemens.com X-Original-Authentication-Results: gmr-mx.google.com; dkim=pass header.i=@siemens.com header.s=selector2 header.b=SRGxhRG5; arc=pass (i=1 spf=pass spfdomain=siemens.com dmarc=pass fromdomain=siemens.com); spf=pass (google.com: domain of tobias.schaffner@siemens.com designates 40.107.13.74 as permitted sender) smtp.mailfrom=tobias.schaffner@siemens.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=siemens.com Precedence: list Mailing-list: list isar-users@googlegroups.com; contact isar-users+owners@googlegroups.com List-ID: X-Spam-Checked-In-Group: isar-users@googlegroups.com X-Google-Group-Id: 914930254986 List-Post: , List-Help: , List-Archive: , List-Unsubscribe: , X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H2,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on shymkent.ilbers.de X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= From: Tobias Schaffner Add some some infrastructure for python unittesting. The unittest_isar module exposes a function that uses the bb.parse module to import python functions that are defined in bitbake files. Signed-off-by: Tobias Schaffner --- testsuite/unittests/README.md | 28 +++++++++++++++++++++ testsuite/unittests/bitbake.py | 37 ++++++++++++++++++++++++++++ testsuite/unittests/rootfs.py | 45 ++++++++++++++++++++++++++++++++++ 3 files changed, 110 insertions(+) create mode 100644 testsuite/unittests/README.md create mode 100644 testsuite/unittests/bitbake.py create mode 100644 testsuite/unittests/rootfs.py diff --git a/testsuite/unittests/README.md b/testsuite/unittests/README.md new file mode 100644 index 0000000..75a3bb0 --- /dev/null +++ b/testsuite/unittests/README.md @@ -0,0 +1,28 @@ +# Isar Unittests + +The unittest python module adds some simple infrastructure that allows to +unittest python functions defined in bitbake files. + +## Running the tests + +You can run the tests using avocado with `avocado --show=app,test run testsuite/unittests/` +or by using the buildin module with `python3 -m unittest discover testsuite/unittests/` + +## Creating new tests + +See the [unittest documentation](https://docs.python.org/3/library/unittest.html) +on how to create a test module and name it test_*bitbake_module_name*.py + +Use the function `load_function(file_name: str, function_name: str) -> Callable` +in the bitbake module to load the function. + +Example: +```python +from bitbake import load_function + +my_function = load_function("meta/classes/my_module.bbclass", "my_function") +my_function(arg1, arg2) +``` + +Use the [unittest.mock](https://docs.python.org/3/library/unittest.mock.html) +library to mock the bb modules as needed. diff --git a/testsuite/unittests/bitbake.py b/testsuite/unittests/bitbake.py new file mode 100644 index 0000000..1e2f685 --- /dev/null +++ b/testsuite/unittests/bitbake.py @@ -0,0 +1,37 @@ +# This software is a part of ISAR. +# Copyright (C) Siemens AG, 2023 +# +# SPDX-License-Identifier: MIT + +import sys +import pathlib +from typing import Callable + +location = pathlib.Path(__file__).parent.resolve() +sys.path.insert(0, "{}/../../bitbake/lib".format(location)) + +from bb.parse import handle +from bb.data import init + +# Modules added for reimport from testfiles +from bb.data_smart import DataSmart + + +def load_function(file_name: str, function_name: str) -> Callable: + """Load a python function defined in a bitbake file. + + Args: + file_name (str): The path to the file e.g. `meta/classes/my_special.bbclass`. + function_name (str): The name of the python function without braces e.g. `my_special_function` + + Returns: + Callable: The loaded function. + """ + d = init() + parse = handle("{}/../../{}".format(location, file_name), d) + if function_name not in parse: + raise KeyError("Function {} does not exist in {}".format( + function_name, file_name)) + namespace = {} + exec(parse[function_name], namespace) + return namespace[function_name] diff --git a/testsuite/unittests/rootfs.py b/testsuite/unittests/rootfs.py new file mode 100644 index 0000000..6c51149 --- /dev/null +++ b/testsuite/unittests/rootfs.py @@ -0,0 +1,45 @@ +# This software is a part of ISAR. +# Copyright (C) Siemens AG, 2023 +# +# SPDX-License-Identifier: MIT + +import tempfile +import pathlib +import shutil +import atexit + +temp_dirs = [] + + +class TemporaryRootfs: + """ A temporary rootfs folder that will be removed after the testrun. """ + + def __init__(self): + self._rootfs_path = tempfile.mkdtemp() + temp_dirs.append(self._rootfs_path) + + def path(self) -> str: + return self._rootfs_path + + def create_file(self, path: str, content: str) -> None: + """ Create a file with the given content. + + Args: + path (str): The path to the file e.g. `/etc/hostname`. + content (str): The content of the file e.g. `my_special_host` + + Returns: + None + """ + pathlib.Path(self._rootfs_path + + path).parent.mkdir(parents=True, exist_ok=True) + with open(self._rootfs_path + path, 'w') as file: + file.write(content) + + +def cleanup(): + for temp_dir in temp_dirs: + shutil.rmtree(temp_dir) + + +atexit.register(cleanup)