Skip to main content
  • Home
  • Development
  • Documentation
  • Donate
  • Operational login
  • Browse the archive

swh logo
SoftwareHeritage
Software
Heritage
Archive
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

  • 62a6b5a
  • /
  • scripts
  • /
  • test_general.py
Raw File Download
Permalinks

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • content
  • directory
content badge Iframe embedding
swh:1:cnt:954328f8e36454fd6c49312988525b7dac430c8c
directory badge Iframe embedding
swh:1:dir:d53121163106162dc5e14cd0697d5f66a6662f36
Citations

This interface enables to generate software citations, provided that the root directory of browsed objects contains a citation.cff or codemeta.json file.
Select below a type of object currently browsed in order to generate citations for them.

  • content
  • directory
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
test_general.py
import pytest
import os
import shutil
import glob
import subprocess
'''
scripts for unit testing
'''


def get_data(dset):
    dpaths = glob.glob('./datasets/{}*'.format(dset))
    [shutil.rmtree(d) for d in dpaths]
    cmd = './scripts/{}/get_data.sh > /dev/null 2>&1'.format(dset)
    os.system(cmd)

def add_args(file, temp_file, new_args):
    with open(file) as f:
        tokens = f.readlines()
    # now make the config so it only trains for one iteration
    tokens[-1] = tokens[-1] + '\n'
    for arg in new_args:
        tokens.append(arg)
    with open(temp_file, 'w') as f:
        f.writelines(tokens)

def run_train(dset):
    train_file = './scripts/{}/train.sh'.format(dset)
    temp_train_file = './scripts/{}/train_temp.sh'.format(dset)
    p = subprocess.run(['cp', '-p', '--preserve', train_file, temp_train_file])
    add_args(train_file, temp_train_file, ['--niter_decay 0 \\\n', '--niter 1 \\\n', '--max_dataset_size 2 \\\n', '--gpu_ids -1 \\'])
    cmd = "bash -c 'source ~/anaconda3/bin/activate ~/anaconda3/envs/meshcnn && {} > /dev/null 2>&1'".format(temp_train_file)
    os.system(cmd)
    os.remove(temp_train_file)

def get_pretrained(dset):
    cmd = './scripts/{}/get_pretrained.sh > /dev/null 2>&1'.format(dset)
    os.system(cmd)

def run_test(dset):
    test_file = './scripts/{}/test.sh'.format(dset)
    temp_test_file = './scripts/{}/test_temp.sh'.format(dset)
    p = subprocess.run(['cp', '-p', '--preserve', test_file, temp_test_file])
    add_args(test_file, temp_test_file, ['--gpu_ids -1 \\'])
    # now run inference
    cmd = "bash -c 'source ~/anaconda3/bin/activate ~/anaconda3/envs/meshcnn && {}'".format(temp_test_file)
    proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True)
    (_out, err) = proc.communicate()
    out = str(_out)
    idf0 = 'TEST ACC: ['
    token = out[out.find(idf0) + len(idf0):]
    idf1 = '%]'
    accs = token[:token.find(idf1)]
    acc = float(accs)
    if dset == 'shrec':
        assert acc == 99.167, "shrec accuracy was {} and not 99.167".format(acc)
    if dset == 'human_seg':
        assert acc == 92.554, "human_seg accuracy was {} and not 92.554".format(acc)
    os.remove(temp_test_file)

def run_dataset(dset):
    get_data(dset)
    run_train(dset)
    get_pretrained(dset)
    run_test(dset)

def test_shrec():
    run_dataset('shrec')

def test_human_seg():
    run_dataset('human_seg')

Software Heritage — Copyright (C) 2015–2025, The Software Heritage developers. License: GNU AGPLv3+.
The source code of Software Heritage itself is available on our development forge.
The source code files archived by Software Heritage are available under their own copyright and licenses.
Terms of use: Archive access, API— Contact— JavaScript license information— Web API

back to top