Skip to content

Commit

Permalink
Introduce a new test for Python-BeautifulSoup4
Browse files Browse the repository at this point in the history
provide also python_version_utils.pm for shared common python functions
  • Loading branch information
ilmanzo committed Nov 3, 2023
1 parent fc16de8 commit fdab647
Show file tree
Hide file tree
Showing 5 changed files with 450 additions and 0 deletions.
6 changes: 6 additions & 0 deletions data/python/bs4/python3-beautifulsoup4-test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import bs4 as bs
with open ("testpage.html") as file:
source = file.read()

soup=bs.BeautifulSoup(source,'lxml')
assert soup.title.string=='Python Programming Tutorials'
301 changes: 301 additions & 0 deletions data/python/bs4/testpage.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,301 @@
<html>

<head>

<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Python Programming Tutorials</title>

<meta name="description"
content="Python Programming tutorials from beginner to advanced on a massive variety of topics. All video and text tutorials are free.">

<link rel="shortcut icon" href="/static/favicon.ico">
<link rel="stylesheet" href="/static/css/materialize.min.css">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<meta name="google-site-verification" content="3fLok05gk5gGtWd_VSXbSSSH27F2kr1QqcxYz9vYq2k" />
<link rel="stylesheet" type="text/css" href="/static/css/bootstrap.css">

<style>
@media (min-width:992px) {
#aside {
width: 250px;
}

pre {
tab-size: 4;
}

.btn {
background-color: #FFD166;
color: #000;
height: auto;
font-color: #000;
}

.btn:hover {
background-color: #FFD166;
}
</style>


</head>

<body>

<div class="navbar-fixed">
<nav style="background-color:#003F72">
<div class="nav-wrapper container">
<a href="/" class="brand-logo"><img class="img-responsive"
style="width:50px; height;50px; margin-top:5px" src="/static/images/mainlogowhitethick.jpg"></a>
<a href="#" data-activates="navsidebar" class="button-collapse"><i class="mdi-navigation-menu"></i></a>
<ul class="right hide-on-med-and-down">
<li><i class="material-icons">search</i></li>
<li>
<form method='get' id='searchform' style='height:50px; padding-top:10px' action='/search/?l=hi'>
<input name='q' id="search" type="search" placeholder="search" style='font-size:16px'>
</form>
</li>

<li><a href="/">Home</a></li>
<li><a class="tooltipped" data-position="bottom" data-delay="50" data-tooltip="sudo apt-get upgrade"
href="/+=1/">+=1</a></li>
<!--<li><a href="/store/python-hoodie/">Store</a></li>-->
<li><a href="/support/">Support the Content</a></li>

<li><a href="https://goo.gl/7zgAVQ"
target='blank'><!--<i class="material-icons">question_answer</i>-->Community</a></li>
<li><a href="/login/">Log in</a></li>
<li><a href="/register/">Sign up</a></li>


</ul>
<ul class="side-nav" id="navsidebar">
<li>
<form method='get' id='searchform' style='height:50px; padding-top:10px' action='/search/?l=hi'>
<input name='q' id="search" type="search" placeholder="search" style='font-size:16px'>
</form>
</li>

<li><a href="/">Home</a></li>
<li><a class="tooltipped" data-position="bottom" data-delay="50" data-tooltip="sudo apt-get upgrade"
href="/+=1/">+=1</a></li>
<!--<li><a href="/store/python-hoodie/">Store</a></li>-->
<li><a href="/support/">Support the Content</a></li>

<li><a href="https://goo.gl/7zgAVQ"
target='blank'><!--<i class="material-icons">question_answer</i>-->Community</a></li>
<li><a href="/login/">Log in</a></li>
<li><a href="/register/">Sign up</a></li>


</ul>
</div>
</nav>
</div>



<!-- main content -->
<div class="container" style="max-width:1500px; min-height:100%">
<!--Notification:-->
<!--<p style="font-size:80%">TensorFlow.js Livestream: <a href="https://www.youtube.com/watch?v=NjSlj95lliM" target="blank"><strong>Deep Learning in the browser</strong></a></p>-->
<!--End Notification:-->


<div class="body">

<p class='introduction'>Oh, hello! This is a <span style='font-size:115%'>wonderful</span> page meant to let
you practice web scraping. This page was originally created to help people work with the <a
href="https://www.crummy.com/software/BeautifulSoup/bs4/doc/" target="blank"><strong>Beautiful Soup
4</strong></a> library.</p>

<p>The following table gives some general information for the following <code>programming languages</code>:
</p>

<ul>
<li>Python</li>
<li>Pascal</li>
<li>Lisp</li>
<li>D#</li>
<li>Cobol</li>
<li>Fortran</li>
<li>Haskell</li>
</ul>


<table style="width:100%">

<tr>
<th>Program Name</th>
<th>Internet Points</th>
<th>Kittens?</th>
</tr>

<tr>
<td>Python</td>
<td>932914021</td>
<td>Definitely</td>
</tr>

<tr>
<td>Pascal</td>
<td>532</td>
<td>Unlikely</td>
</tr>


<tr>
<td>Lisp</td>
<td>1522</td>
<td>Uncertain</td>
</tr>


<tr>
<td>D#</td>
<td>12</td>
<td>Possibly</td>
</tr>


<tr>
<td>Cobol</td>
<td>3</td>
<td>No.</td>
</tr>

<tr>
<td>Fortran</td>
<td>52124</td>
<td>Yes.</td>
</tr>

<tr>
<td>Haskell</td>
<td>24</td>
<td>lol.</td>
</tr>

</table>

<p>I think it's clear that, on a scale of 1-10, python is:</p>

<div class='card hoverable'>
<div class='card-content'>
<div class='card-title'></div>
<img class="responsive-img"
src="https://s-media-cache-ak0.pinimg.com/originals/e8/2a/ff/e82aff2876b080675449d0cef7685321.jpg"
alt="omg batman" />
</div>
</div>

<p>Javascript (dynamic data) test:</p>
<p class='jstest' id='yesnojs'>y u bad tho?</p>
<script>
document.getElementById('yesnojs').innerHTML = 'Look at you shinin!';
</script>

<br><br>

<pre>Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!</pre>

<p>Whᶐt hαppéns now¿</p>

<p><a href="/sitemap.xml" target="blank"><strong>sitemap</strong></a></p>

</body>


</div>
</div>

<!--login modal-->


<!--Register modal-->



<script>
$(document).ready(function () {
$(".button-collapse").sideNav();
$('.modal-trigger').leanModal();
$('.collapsible').collapsible({
accordion: false // A setting that changes the collapsible behavior to expandable instead of the default accordion style
});
$('#aside').pushpin({ top: 110, bottom: 500 });
});
</script>
<script>
$(document).ready(function () {
$('.collapsible').collapsible({
accordion: false // A setting that changes the collapsible behavior to expandable instead of the default accordion style
});
$('select').material_select();
});
</script>
<script>
function goBack() {
window.history.back()
}
</script>
<script type="text/javascript" src="/static/js/run_prettify.js"></script>

</body>

<footer class="page-footer">
<div class="container">
<div class="row">
<div class="col l6 s12">
<h5 class="white-text">You've reached the end!</h5>

<p class="grey-text text-lighten-4">Contact: Harrison@pythonprogramming.net.</p>
<ul>
<li><a class="grey-text text-lighten-3" href="/support-donate/">Support this Website!</a></li>
<li><a class="grey-text text-lighten-3" href="/consulting/">Consulting and Contracting</a></li>
<li><a class="grey-text text-lighten-3"
href="https://www.facebook.com/pythonprogramming.net/">Facebook</a></li>
<li><a class="grey-text text-lighten-3" href="https://twitter.com/sentdex">Twitter</a></li>
<li><a class="grey-text text-lighten-3" href="https://instagram.com/sentdex">Instagram</a></li>
</ul>
</div>
<div class="col l4 offset-l2 s12">
<h6 class="white-text">Legal stuff:</h6>
<ul>
<li><a class="grey-text text-lighten-3" href="/about/tos/">Terms and Conditions</a></li>
<li><a class="grey-text text-lighten-3" href="/about/privacy-policy/">Privacy Policy</a></li>

</ul>
</div>
</div>
</div>
<a href="https://xkcd.com/353/" target='blank'>
<p class="grey-text right" style='padding-right:10px'>Programming is a superpower.</p>
</a>
<div class="footer-copyright">
<div class="container">
© OVER 9000! PythonProgramming.net

</div>

</div>
</footer>

</html>
79 changes: 79 additions & 0 deletions lib/python_version_utils.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# Copyright 2015-2022 SUSE LLC
# SPDX-License-Identifier: GPL-2.0-or-later

package python_version_utils;

use base Exporter;
use Exporter;
use testapi;
use utils 'zypper_call';
use strict;
use warnings;
use v5.20;
use feature qw(signatures);
no warnings qw(experimental::signatures);


our @EXPORT = qw(
get_system_python_version
get_available_python_versions
get_python3_binary
remove_installed_pythons
);

=head2 get_system_python_version
returns a string with the system's current default python version, for example 'python311'
=cut

sub get_system_python_version() {
my @system_python_version = script_output(qq[zypper se --installed-only --provides '/usr/bin/python3' | awk -F '|' '/python3[0-9]*/ {gsub(" ", ""); print \$2}' | awk -F '-' '{print \$1}' | uniq]);
die "There are many python3 versions installed " if (scalar(@system_python_version) > 1);
return $system_python_version[0];
}

=head2 get_available_python_versions
returns an array of strings with all the available python versions in the repository
=cut

sub get_available_python_versions() {
my @python3_versions = split(/\n/, script_output(qq[zypper se 'python3[0-9]*' | awk -F '|' '/python3[0-9]/ {gsub(" ", ""); print \$2}' | awk -F '-' '{print \$1}' | uniq]));
record_info("Available versions", "All available new python3 versions are: @python3_versions");
return @python3_versions;
}

=head2 get_python3_binary
given a python package version, e.g. python311, returns the executable name python3.11
when the package is 'python3', return the system default one (eg python3.6 for SLE15.4)
=cut

sub get_python3_binary ($python3_package) {
if ($python3_package eq "python3") {
my $current_version = script_output("rpm -q python3 --queryformat '%{version}'");
$current_version =~ s/\.\d+$//;
return "python$current_version";
}
my $sub_version = substr($python3_package, 7);
return "python3.$sub_version";
}

=head2 remove_installed_pythons
remove all the installed available python versions
=cut

sub remove_installed_pythons() {
my $default_python = script_output("python3 --version | awk -F ' ' '{print \$2}\'");
my @python3_versions = split(/\n/, script_output(qq[zypper se -i 'python3[0-9]*' | awk -F '|' '/python3[0-9]/ {gsub(" ", ""); print \$2}' | awk -F '-' '{print \$1}' | uniq]));
record_info("Installed versions", "All Installed new python3 versions are: @python3_versions");
foreach my $python3_spec_release (@python3_versions) {
my $python_versions = script_output("rpm -q $python3_spec_release | awk -F \'-\' \'{print \$2}\'");
record_info("Python version", "$python_versions:$default_python");
next if ($python_versions eq $default_python);
zypper_call("remove $python3_spec_release-base");
}
}

1;

0 comments on commit fdab647

Please sign in to comment.