File: test_table_normalizer.py

package info (click to toggle)
python-biom-format 2.1.17-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 52,044 kB
  • sloc: python: 13,624; makefile: 149; sh: 105; javascript: 45
file content (48 lines) | stat: -rwxr-xr-x 1,517 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env python

# -----------------------------------------------------------------------------
# Copyright (c) 2011-2017, The BIOM Format Development Team.
#
# Distributed under the terms of the Modified BSD License.
#
# The full license is in the file COPYING.txt, distributed with this software.
# -----------------------------------------------------------------------------

from unittest import TestCase, main

import os

import biom
from biom.cli.table_normalizer import _normalize_table
from biom.exception import UnknownAxisError


class TableNormalizerTests(TestCase):

    def setUp(self):
        """initialize objects for use in tests"""
        self.cmd = _normalize_table

        cwd = os.getcwd()
        if os.path.sep in __file__:
            os.chdir(os.path.dirname(__file__))
        self.table = biom.load_table(os.path.join('test_data', 'test.json'))
        os.chdir(cwd)

    def test_bad_inputs(self):
        # relative_abund and pa
        with self.assertRaises(ValueError):
            self.cmd(self.table, relative_abund=True,
                     presence_absence=True, axis="sample")
        # no normalization type
        with self.assertRaises(ValueError):
            self.cmd(self.table, relative_abund=False,
                     presence_absence=False, axis="sample")
        # bad axis
        with self.assertRaises(UnknownAxisError):
            self.cmd(self.table, relative_abund=True,
                     axis="nonsense")


if __name__ == "__main__":
    main()