|
| 1 | +from os import remove, mkdir |
| 2 | +from os.path import join, exists |
| 3 | + |
| 4 | +from unittest import TestCase, main |
| 5 | +import americangut.notebook_environment as agenv |
| 6 | +from americangut.util import get_new_path |
| 7 | +from americangut.per_category import cat_taxa_summaries |
| 8 | + |
| 9 | + |
| 10 | +class PerCategoryTests(TestCase): |
| 11 | + def setUp(self): |
| 12 | + self.taxa_base = agenv.paths['populated-templates']['result-taxa'] |
| 13 | + |
| 14 | + try: |
| 15 | + get_new_path( |
| 16 | + agenv.paths['populated-templates']['result-taxa']) |
| 17 | + except IOError: |
| 18 | + pass |
| 19 | + |
| 20 | + self.taxa_files = [ |
| 21 | + 'ag-stool-average.txt', |
| 22 | + 'ag-stool-sex-male.txt', |
| 23 | + 'ag-stool-sex-other.txt', |
| 24 | + 'ag-stool-sex-female.txt', |
| 25 | + 'ag-oral-diet-Omnivore.txt', |
| 26 | + 'ag-oral-diet-Vegetarian.txt', |
| 27 | + 'ag-oral-diet-Vegan.txt', |
| 28 | + 'ag-oral-diet-Omnivore_but_do_not_eat_red_meat.txt', |
| 29 | + 'ag-oral-diet-Vegetarian_but_eat_seafood.txt', |
| 30 | + 'ag-skin-sex-male.txt', |
| 31 | + 'ag-skin-sex-female.txt', |
| 32 | + 'ag-stool-diet-Omnivore.txt', |
| 33 | + 'ag-stool-diet-Vegetarian.txt', |
| 34 | + 'ag-stool-diet-Vegan.txt', |
| 35 | + 'ag-stool-diet-Omnivore_but_do_not_eat_red_meat.txt', |
| 36 | + 'ag-stool-diet-Vegetarian_but_eat_seafood.txt', |
| 37 | + 'ag-skin-hand-I_am_left_handed.txt', |
| 38 | + 'ag-skin-hand-I_am_ambidextrous.txt', |
| 39 | + 'ag-skin-hand-I_am_right_handed.txt', |
| 40 | + 'ag-oral-sex-male.txt', |
| 41 | + 'ag-oral-sex-female.txt', |
| 42 | + 'ag-stool-bmi-Overweight.txt', |
| 43 | + 'ag-stool-bmi-Obese.txt', |
| 44 | + 'ag-stool-bmi-Underweight.txt', |
| 45 | + 'ag-stool-bmi-Normal.txt', |
| 46 | + 'ag-oral-flossing-Never.txt', |
| 47 | + 'ag-oral-flossing-Rarely.txt', |
| 48 | + 'ag-oral-flossing-Daily.txt', |
| 49 | + 'ag-oral-flossing-Occasionally.txt', |
| 50 | + 'ag-oral-flossing-Regularly.txt', |
| 51 | + 'ag-stool-age-teen.txt', |
| 52 | + 'ag-stool-age-20s.txt', |
| 53 | + 'ag-stool-age-60s.txt', |
| 54 | + 'ag-stool-age-30s.txt', |
| 55 | + 'ag-stool-age-child.txt', |
| 56 | + 'ag-stool-age-40s.txt', |
| 57 | + 'ag-stool-age-70+.txt', |
| 58 | + 'ag-stool-age-baby.txt', |
| 59 | + 'ag-stool-age-50s.txt', |
| 60 | + 'ag-oral-average.txt', |
| 61 | + 'ag-skin-cosmetics-Never.txt', |
| 62 | + 'ag-skin-cosmetics-Rarely.txt', |
| 63 | + 'ag-skin-cosmetics-Daily.txt', |
| 64 | + 'ag-skin-cosmetics-Occasionally.txt', |
| 65 | + 'ag-skin-cosmetics-Regularly.txt', |
| 66 | + 'ag-skin-age-teen.txt', |
| 67 | + 'ag-skin-age-20s.txt', |
| 68 | + 'ag-skin-age-60s.txt', |
| 69 | + 'ag-skin-age-30s.txt', |
| 70 | + 'ag-skin-age-70+.txt', |
| 71 | + 'ag-skin-age-40s.txt', |
| 72 | + 'ag-skin-age-child.txt', |
| 73 | + 'ag-skin-age-baby.txt', |
| 74 | + 'ag-skin-age-50s.txt', |
| 75 | + 'ag-skin-average.txt', |
| 76 | + 'ag-oral-age-teen.txt', |
| 77 | + 'ag-oral-age-20s.txt', |
| 78 | + 'ag-oral-age-60s.txt', |
| 79 | + 'ag-oral-age-30s.txt', |
| 80 | + 'ag-oral-age-child.txt', |
| 81 | + 'ag-oral-age-40s.txt', |
| 82 | + 'ag-oral-age-70+.txt', |
| 83 | + 'ag-oral-age-50s.txt'] |
| 84 | + |
| 85 | + def tearDown(self): |
| 86 | + for f in self.taxa_files: |
| 87 | + path = join(self.taxa_base, f) |
| 88 | + if exists(path): |
| 89 | + remove(path) |
| 90 | + |
| 91 | + def test_cat_taxa_summaries(self): |
| 92 | + cat_taxa_summaries() |
| 93 | + # Make sure all files created |
| 94 | + for f in self.taxa_files: |
| 95 | + path = join(self.taxa_base, f) |
| 96 | + if not exists(path): |
| 97 | + raise AssertionError('File %s not generated!' % f) |
| 98 | + |
| 99 | + # Test file for correct format |
| 100 | + self.maxDiff = None |
| 101 | + with open(join(self.taxa_base, 'ag-skin-age-teen.txt')) as f: |
| 102 | + obs = f.read() |
| 103 | + |
| 104 | + exp = '' |
| 105 | + self.assertEqual(obs, exp) |
| 106 | + |
| 107 | + |
| 108 | +if __name__ == '__main__': |
| 109 | + main() |
0 commit comments